Nickolay - Test.Run-0.10

Documentation | Source
Class('Test.Run.Harness.NodeJS', {
    
    isa : Test.Run.Harness,
    
    my : {
        
        have : {
            runCore         : 'sequential',
            scopeProvider   : 'Scope.Provider.NodeJS',
            
            chdirToIndex    : true,
            
            styles          : {
                'bold'      : [1, 22],
                'italic'    : [3, 23],
                'underline' : [4, 24],
                'yellow'    : [33, 39],
                'cyan'      : [36, 39],
                'white'     : [37, 39],
                'green'     : [32, 39],
                'red'       : [31, 39],
                'grey'      : [90, 39],
                'blue'      : [34, 39],
                'magenta'   : [35, 39],
                'inverse'   : [7, 27]
            }
        },
        
        
        after : {
            
            onTestEnd : function (test) {
                this.puts( test.url + ' - ' + (test.isPassed() ? this.styled('pass', 'green') : this.styled('fail', 'red')) ) 
            },
            
            
            onTestSuiteStart : function () {
                this.runCore         = 'sequential'
                
                if (this.chdirToIndex) {
                    var indexFile = process.argv[1]
                    
                    var path = require('path')
                    
                    process.chdir(path.dirname(indexFile))
                }
            },
            
            
            onTestFail : function (test, exception) {
                var text
                
                if (exception.stack)
                    text = exception.stack
                else
                    text = exception + ''
                    
                text = this.styled(this.styled(text, 'red'), 'bold')
                
                this.puts(text)
            },
            
            
            onTestUpdate : function (test, result) {
                var text = result + ''
                
                var isAssertion = result instanceof Test.Run.Result.Assertion
                
                if (isAssertion) text = this.styled(text, result.passed ? 'green' : 'red')
                if (result instanceof Test.Run.Result.Diagnostic) text = this.styled(text, 'bold')
                
                if (this.verbosity > 0)
                    this.puts(text)
                else
                    if (isAssertion && !result.passed)
                        this.puts(text)
            }            
            
        },
        
        
        methods : {
            
            resolveURL : function (url) {
                var fs = require('fs')
                
                // ref to JSAN module
                if (/^jsan:/.test(url))
                    Joose.A.each(require.paths, function (path) {
                        
                        var libPath = path.replace(/\/?$/, '') + '/index.html' + url.replace(/^jsan:/, '').replace(/\./g, '/index.html') + '/doc/s/sa/samuraijack/Test/Run/010/lib/Test/Run/Harness/.js'
                        
                        try {
                            if (fs.statSync(libPath).isFile()) {
                                url = libPath
                                
                                return false
                            }
                            
                        } catch (e) {
                        }
                    })
                
                // ref to lib in current dist (no trailing `.js`) 
                if (!/\.js$/.test(url)) {
                    url = '/doc/s/sa/samuraijack/Test/Run/010/lib/Test/Run/lib/index.html' + url.replace(/\./g, '/index.html') + '/doc/s/sa/samuraijack/Test/Run/010/lib/Test/Run/Harness/.js'
                }
                
                // otherwise assumed to be a raw filename, relative or absolute
                return url
            },
            
            
            styled : function (text, style) {
                var styles = this.styles
                
                return '\033[' + styles[ style ][ 0 ] + 'm' + text + '\033[' + styles[ style ][ 1 ] + 'm'
            },
            
            
            puts : function (text) {
                require('sys').puts(text)
            },
            
            
            prepareINC : function (INC) {
                return JSON.stringify(INC)
            }
        }
        
    }
    //eof my
})
//eof Test.Run.Harness.NodeJS