jasmine-node
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
var jasmine = require('jasmine-node'); | ||
var jasmine = require('./index'); | ||
var sys = require('sys'), | ||
@@ -14,4 +14,9 @@ Path= require('path'); | ||
var extentions = "js"; | ||
var match = '.' | ||
process.argv.slice(2).forEach(function(arg){ | ||
var args = process.argv.slice(2); | ||
while(args.length) { | ||
var arg = args.shift(); | ||
switch(arg) | ||
@@ -32,2 +37,15 @@ { | ||
break; | ||
case '-m': | ||
case '--match': | ||
match = args.shift(); | ||
break; | ||
case '-i': | ||
case '--include': | ||
var dir = args.shift(); | ||
if(!Path.existsSync(dir)) | ||
throw new Error("Include path '" + dir + "' doesn't exist!"); | ||
require.paths.unshift(dir); | ||
break; | ||
default: | ||
@@ -38,3 +56,3 @@ if (arg.match(/^--/)) help(); | ||
} | ||
}); | ||
} | ||
@@ -45,2 +63,11 @@ if (!specFolder) { | ||
var exitCode = 0; | ||
process.on("exit", onExit); | ||
function onExit() { | ||
process.removeListener("exit", onExit); | ||
process.exit(exitCode); | ||
} | ||
jasmine.loadHelpersInFolder(specFolder, new RegExp("[-_]helper\\.(" + extentions + ")$")); | ||
@@ -50,18 +77,23 @@ jasmine.executeSpecsInFolder(specFolder, function(runner, log){ | ||
if (runner.results().failedCount == 0) { | ||
process.exit(0); | ||
exitCode = 0; | ||
} else { | ||
process.exit(1); | ||
exitCode = 1; | ||
} | ||
}, isVerbose, showColors, new RegExp(".spec\\.(" + extentions + ")$", 'i')); | ||
}, isVerbose, showColors, new RegExp(match + "spec\\.(" + extentions + ")$", 'i')); | ||
function help(){ | ||
sys.print('USAGE: jasmine-node [--color|--noColor] [--verbose] [--coffee] directory\n'); | ||
sys.print('\n'); | ||
sys.print('Options:\n'); | ||
sys.print(' --color - use color coding for output\n'); | ||
sys.print(' --noColor - do not use color coding for output\n'); | ||
sys.print(' --verbose - print extra information per each test run\n'); | ||
sys.print(' --coffee - load coffee-script which allows execution .coffee files\n'); | ||
sys.print([ | ||
'USAGE: jasmine-node [--color|--noColor] [--verbose] [--coffee] directory' | ||
, '' | ||
, 'Options:' | ||
, ' --color - use color coding for output' | ||
, ' --noColor - do not use color coding for output' | ||
, ' -m, --match REGEXP - load only specs containing "REGEXPspec"' | ||
, ' -i, --include DIR - add given directory to node include paths' | ||
, ' --verbose - print extra information per each test run' | ||
, ' --coffee - load coffee-script which allows execution .coffee files' | ||
, '' | ||
].join("\n")); | ||
process.exit(1); | ||
} |
@@ -0,1 +1,2 @@ | ||
var fs = require('fs'); | ||
@@ -27,8 +28,15 @@ var sys = require('sys'); | ||
function noop(){} | ||
jasmine.TerminalReporter = require('./reporter').TerminalReporter; | ||
jasmine.loadHelpersInFolder=function(folder, matcher) | ||
{ | ||
var helpers = jasmine.getAllSpecFiles(folder, matcher); | ||
var helpers = []; | ||
if(fs.statSync(folder).isDirectory()) { | ||
helpers = jasmine.getAllSpecFiles(folder, matcher); | ||
} else { | ||
folder = path.dirname(folder); | ||
helpers = jasmine.getAllSpecFiles(folder, matcher); | ||
} | ||
for (var i = 0, len = helpers.length; i < len; ++i) | ||
@@ -41,20 +49,14 @@ { | ||
} | ||
} | ||
}; | ||
jasmine.executeSpecsInFolder = function(folder, done, isVerbose, showColors, matcher){ | ||
var log = []; | ||
var columnCounter = 0; | ||
var start = 0; | ||
var elapsed = 0; | ||
var verbose = isVerbose || false; | ||
jasmine.executeSpecsInFolder = function(folder, done, isVerbose, showColors, matcher) { | ||
var fileMatcher = matcher || new RegExp(".(js)$", "i"); | ||
var colors = showColors || false; | ||
var specs = jasmine.getAllSpecFiles(folder, fileMatcher); | ||
var specs = []; | ||
var ansi = { | ||
green: '\033[32m', | ||
red: '\033[31m', | ||
yellow: '\033[33m', | ||
none: '\033[0m' | ||
}; | ||
if (fs.statSync(folder).isDirectory()) { | ||
specs = jasmine.getAllSpecFiles(folder, fileMatcher); | ||
} else { | ||
specs.push(folder); | ||
} | ||
@@ -67,77 +69,6 @@ for (var i = 0, len = specs.length; i < len; ++i){ | ||
var jasmineEnv = jasmine.getEnv(); | ||
jasmineEnv.reporter = { | ||
log: function(str){ | ||
}, | ||
reportSpecStarting: function(runner) { | ||
}, | ||
reportRunnerStarting: function(runner) { | ||
sys.puts('Started'); | ||
start = Number(new Date); | ||
}, | ||
reportSuiteResults: function(suite) { | ||
var specResults = suite.results(); | ||
var path = []; | ||
while(suite) { | ||
path.unshift(suite.description); | ||
suite = suite.parentSuite; | ||
} | ||
var description = path.join(' '); | ||
if (verbose) | ||
log.push('Spec ' + description); | ||
specResults.items_.forEach(function(spec){ | ||
if (spec.failedCount > 0 && spec.description) { | ||
if (!verbose) | ||
log.push(description); | ||
log.push(' it ' + spec.description); | ||
spec.items_.forEach(function(result){ | ||
log.push(' ' + result.trace.stack + '\n'); | ||
}); | ||
} | ||
}); | ||
}, | ||
reportSpecResults: function(spec) { | ||
var result = spec.results(); | ||
var msg = ''; | ||
if (result.passed()) | ||
{ | ||
msg = (colors) ? (ansi.green + '.' + ansi.none) : '.'; | ||
// } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec? | ||
// msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*'; | ||
} else { | ||
msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F'; | ||
} | ||
sys.print(msg); | ||
if (columnCounter++ < 50) return; | ||
columnCounter = 0; | ||
sys.print('\n'); | ||
}, | ||
reportRunnerResults: function(runner) { | ||
elapsed = (Number(new Date) - start) / 1000; | ||
sys.puts('\n'); | ||
log.forEach(function(log){ | ||
sys.puts(log); | ||
}); | ||
sys.puts('Finished in ' + elapsed + ' seconds'); | ||
var summary = jasmine.printRunnerResults(runner); | ||
if(colors) | ||
{ | ||
if(runner.results().failedCount === 0 ) | ||
sys.puts(ansi.green + summary + ansi.none); | ||
else | ||
sys.puts(ansi.red + summary + ansi.none); | ||
} else { | ||
sys.puts(summary); | ||
} | ||
(done||noop)(runner, log); | ||
} | ||
}; | ||
jasmineEnv.reporter = new jasmine.TerminalReporter({print: sys.print, | ||
verbose: isVerbose, | ||
color: showColors, | ||
onComplete: done}); | ||
jasmineEnv.execute(); | ||
@@ -148,3 +79,2 @@ }; | ||
var specs = []; | ||
if (fs.statSync(dir).isFile() && dir.match(matcher)) { | ||
@@ -156,26 +86,39 @@ specs.push(dir); | ||
var filename = dir + '/' + files[i]; | ||
if (fs.statSync(filename).isFile() && filename.match(matcher)){ | ||
specs.push(filename); | ||
}else if (fs.statSync(filename).isDirectory()){ | ||
var subfiles = this.getAllSpecFiles(filename, matcher); | ||
subfiles.forEach(function(result){ | ||
specs.push(result); | ||
}); | ||
} | ||
// fs.fstatSync will pass ENOENT from stat(2) up | ||
// the stack. That's not particularly useful right now, | ||
// so try and continue... | ||
try{ | ||
isFile = fs.statSync(filename).isFile(); | ||
}catch (err){ | ||
if(err.code === 'ENOENT'){ | ||
isFile = false; | ||
}else{ | ||
throw err; | ||
} | ||
} | ||
if (filename.match(matcher) && isFile){ | ||
specs.push(filename); | ||
}else{ | ||
try{ | ||
isDir = fs.statSync(filename).isDirectory(); | ||
} catch (err) { | ||
if(err.code === 'ENOENT'){ | ||
isDir = false; | ||
}else{ | ||
throw err; | ||
} | ||
} | ||
if (isDir){ | ||
var subfiles = this.getAllSpecFiles(filename, matcher); | ||
subfiles.forEach(function(result){ | ||
specs.push(result); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return specs; | ||
}; | ||
jasmine.printRunnerResults = function(runner){ | ||
var results = runner.results(); | ||
var suites = runner.suites(); | ||
var msg = ''; | ||
msg += suites.length + ' test' + ((suites.length === 1) ? '' : 's') + ', '; | ||
msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', '; | ||
msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n'; | ||
return msg; | ||
}; | ||
function now(){ | ||
@@ -182,0 +125,0 @@ return new Date().getTime(); |
{ | ||
"name" : "jasmine-node" | ||
, "version" : "1.0.6" | ||
, "version" : "1.0.7" | ||
, "description" : "DOM-less simple JavaScript BDD testing framework for Node" | ||
@@ -5,0 +5,0 @@ , "homepage" : [ "http://pivotal.github.com/jasmine" |
@@ -11,5 +11,6 @@ jasmine-node | ||
Write the specifications for your code in *.js and *.coffee files in | ||
the spec/ directory. You can use sub-directories to better organise | ||
your specs. | ||
Write the specifications for your code in *.js and *.coffee files in the | ||
spec/ directory (note: your specification files must end with either | ||
.spec.js or .spec.coffee; otherwise jasmine-node won't find them!). You | ||
can use sub-directories to better organise your specs. | ||
@@ -28,2 +29,3 @@ If you have installed the npm package, you can run it with: | ||
* <code>--coffee</code>, allow execution of .coffee specs | ||
* <code>--color</code>, indicates spec output should uses color to | ||
@@ -30,0 +32,0 @@ indicates passing (green) or failing (red) specs |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
81362
6.02%21
23.53%2489
4.19%35
6.06%