jasmine-node
Advanced tools
Comparing version 1.0.12 to 1.0.13
var jasmine = require('./index'); | ||
var sys = require('sys'), | ||
var util, | ||
Path= require('path'); | ||
try { | ||
util = require('util') | ||
} catch(e) { | ||
util = require('sys') | ||
} | ||
var specFolder = null; | ||
@@ -13,2 +19,3 @@ | ||
var teamcity = process.env.TEAMCITY_PROJECT_NAME || false; | ||
var useRequireJs = false; | ||
var extentions = "js"; | ||
@@ -49,11 +56,2 @@ var match = '.' | ||
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; | ||
case '--junitreport': | ||
@@ -65,2 +63,15 @@ junitreport.report = true; | ||
break; | ||
case '--runWithRequireJs': | ||
useRequireJs = true; | ||
break; | ||
case '--test-dir': | ||
var dir = args.shift(); | ||
if(!Path.existsSync(dir)) | ||
throw new Error("Test root path '" + dir + "' doesn't exist!"); | ||
specFolder = dir; // NOTE: Does not look from current working directory. | ||
break; | ||
case '-h': | ||
help(); | ||
default: | ||
@@ -86,5 +97,4 @@ if (arg.match(/^--/)) help(); | ||
jasmine.loadHelpersInFolder(specFolder, new RegExp("[-_]helper\\.(" + extentions + ")$")); | ||
jasmine.executeSpecsInFolder(specFolder, function(runner, log){ | ||
sys.print('\n'); | ||
var onComplete = function(runner, log) { | ||
util.print('\n'); | ||
if (runner.results().failedCount == 0) { | ||
@@ -95,6 +105,17 @@ exitCode = 0; | ||
} | ||
}, isVerbose, showColors, teamcity, new RegExp(match + "spec\\.(" + extentions + ")$", 'i'), junitreport); | ||
}; | ||
jasmine.loadHelpersInFolder(specFolder, | ||
new RegExp("[-_]helper\\.(" + extentions + ")$")); | ||
jasmine.executeSpecsInFolder(specFolder, | ||
onComplete, | ||
isVerbose, | ||
showColors, | ||
teamcity, | ||
useRequireJs, | ||
new RegExp(match + "spec\\.(" + extentions + ")$", 'i'), | ||
junitreport); | ||
function help(){ | ||
sys.print([ | ||
util.print([ | ||
'USAGE: jasmine-node [--color|--noColor] [--verbose] [--coffee] directory' | ||
@@ -111,2 +132,5 @@ , '' | ||
, ' --teamcity - converts all console output to teamcity custom test runner commands. (Normally auto detected.)' | ||
, ' --runWithRequireJs - loads all specs using requirejs instead of node\'s native require method' | ||
, ' --test-dir - the absolute root directory path where tests are located' | ||
, ' -h, --help - display this help and exit' | ||
, '' | ||
@@ -113,0 +137,0 @@ ].join("\n")); |
var fs = require('fs'); | ||
var sys = require('sys'); | ||
var util; | ||
try { | ||
util = require('util') | ||
} catch(e) { | ||
util = require('sys') | ||
} | ||
var path = require('path'); | ||
@@ -32,10 +38,7 @@ | ||
{ | ||
var helpers = []; | ||
var helpers = [], | ||
helperCollection = require('./spec-collection'); | ||
if(fs.statSync(folder).isDirectory()) { | ||
helpers = jasmine.getAllSpecFiles(folder, matcher); | ||
} else { | ||
folder = path.dirname(folder); | ||
helpers = jasmine.getAllSpecFiles(folder, matcher); | ||
} | ||
helperCollection.load(folder, matcher); | ||
helpers = helperCollection.getSpecPaths(); | ||
@@ -61,25 +64,25 @@ for (var i = 0, len = helpers.length; i < len; ++i) | ||
jasmine.executeSpecsInFolder = function(folder, done, isVerbose, showColors, teamcity, matcher, junitreport){ | ||
var fileMatcher = matcher || new RegExp(".(js)$", "i"); | ||
var colors = showColors || false; | ||
var specs = []; | ||
jasmine.executeSpecsInFolder = function(folder, | ||
done, | ||
isVerbose, | ||
showColors, | ||
teamcity, | ||
useRequireJs, | ||
matcher, | ||
junitreport){ | ||
var fileMatcher = matcher || new RegExp(".(js)$", "i"), | ||
colors = showColors || false, | ||
specs = require('./spec-collection'), | ||
jasmineEnv = jasmine.getEnv(); | ||
if (fs.statSync(folder).isDirectory()) { | ||
specs = jasmine.getAllSpecFiles(folder, fileMatcher); | ||
} else { | ||
specs.push(folder); | ||
} | ||
specs.load(folder, matcher); | ||
for (var i = 0, len = specs.length; i < len; ++i){ | ||
var filename = specs[i]; | ||
require(filename.replace(/\.\w+$/, "")); | ||
} | ||
var jasmineEnv = jasmine.getEnv(); | ||
if(junitreport.report) { | ||
if(!path.existsSync(junitreport.savePath)) { | ||
sys.puts('creating junit xml report save path: ' + junitreport.savePath); | ||
util.puts('creating junit xml report save path: ' + junitreport.savePath); | ||
fs.mkdirSync(junitreport.savePath, "0755"); | ||
} | ||
jasmineEnv.addReporter(new jasmine.JUnitXmlReporter(junitreport.savePath, junitreport.consolidate, junitreport.useDotNotation)); | ||
jasmineEnv.addReporter(new jasmine.JUnitXmlReporter(junitreport.savePath, | ||
junitreport.consolidate, | ||
junitreport.useDotNotation)); | ||
} | ||
@@ -90,3 +93,3 @@ | ||
} else { | ||
jasmineEnv.addReporter(new TerminalReporter({print: sys.print, | ||
jasmineEnv.addReporter(new TerminalReporter({print: util.print, | ||
verbose: isVerbose, | ||
@@ -98,48 +101,14 @@ color: showColors, | ||
jasmineEnv.execute(); | ||
}; | ||
jasmine.getAllSpecFiles = function(dir, matcher){ | ||
var specs = []; | ||
if (fs.statSync(dir).isFile() && dir.match(matcher)) { | ||
specs.push(dir); | ||
if (useRequireJs) { | ||
require('./requirejs-runner').executeJsRunner(specs, done, jasmineEnv); | ||
} else { | ||
var files = fs.readdirSync(dir); | ||
for (var i = 0, len = files.length; i < len; ++i){ | ||
var filename = dir + '/' + files[i]; | ||
// 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); | ||
}); | ||
} | ||
} | ||
var specsList = specs.getSpecPaths(); | ||
for (var i = 0, len = specsList.length; i < len; ++i) { | ||
var filename = specsList[i]; | ||
require(filename.replace(/\.\w+$/, "")); | ||
} | ||
jasmineEnv.execute(); | ||
} | ||
return specs; | ||
}; | ||
@@ -146,0 +115,0 @@ |
// | ||
// Imports | ||
// | ||
var sys = require('sys'); | ||
var util; | ||
try { | ||
util = require('util') | ||
} catch(e) { | ||
util = require('sys') | ||
} | ||
@@ -14,5 +19,5 @@ | ||
var results = runner.results(); | ||
var suites = runner.suites(); | ||
var specs = runner.specs(); | ||
var msg = ''; | ||
msg += suites.length + ' test' + ((suites.length === 1) ? '' : 's') + ', '; | ||
msg += specs.length + ' test' + ((specs.length === 1) ? '' : 's') + ', '; | ||
msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', '; | ||
@@ -23,14 +28,2 @@ msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n'; | ||
escapeTeamcityString = function(message) { | ||
return message.replace(/\|/g, "||") | ||
.replace(/\'/g, "|'") | ||
.replace(/\n/g, "|n") | ||
.replace(/\r/g, "|r") | ||
.replace(/\u0085/g, "|x") | ||
.replace(/\u2028/g, "|l") | ||
.replace(/\u2029/g, "|p") | ||
.replace(/\[/g, "|[") | ||
.replace(/]/g, "|]"); | ||
}; | ||
ANSIColors = { | ||
@@ -48,2 +41,3 @@ pass: function() { return '\033[32m'; }, // Green | ||
// | ||
@@ -53,7 +47,6 @@ // Reporter implementation | ||
TerminalReporter = function(config) { | ||
this.print_ = config.print || sys.print; | ||
this.print_ = config.print || util.print; | ||
this.isVerbose_ = config.verbose || false; | ||
this.onComplete_ = config.onComplete || noop; | ||
this.color_ = config.color? ANSIColors: NoColors; | ||
this.teamcity_ = config.teamcity; | ||
this.stackFilter = config.stackFilter || function(t) { return t; } | ||
@@ -86,42 +79,29 @@ | ||
if (this.isVerbose_ && !this.teamcity_) | ||
if (this.isVerbose_) | ||
this.log_.push('Spec ' + description); | ||
if (this.teamcity_) | ||
this.log_.push("##teamcity[testSuiteStarted name='" + escapeTeamcityString(description) + "]"); | ||
outerThis = this; | ||
specResults.items_.forEach(function(spec){ | ||
if (spec.failedCount > 0 && spec.description) { | ||
if (!outerThis.isVerbose_ && !outerThis.teamcity_) | ||
if (spec.description && spec.failedCount > 0) { | ||
if (!outerThis.isVerbose_) | ||
outerThis.log_.push(description); | ||
if (outerThis.teamcity_) { | ||
outerThis.log_.push("##teamcity[testStarted name='" + escapeTeamcityString(spec.description) + "' captureStandardOutput='true']"); | ||
} else { | ||
outerThis.log_.push(' it ' + spec.description); | ||
} | ||
outerThis.log_.push(' it ' + spec.description); | ||
spec.items_.forEach(function(result){ | ||
if (!result.passed_) { | ||
var errorMessage = result.trace.stack || result.message; | ||
if (!result.passed_) { | ||
var errorMessage = result.trace.stack || result.message; | ||
if(outerThis.teamcity_) { | ||
outerThis.log_.push("##teamcity[testFailed name='" + escapeTeamcityString(spec.description) + "' message='[FAILED]' details='" + escapeTeamcityString(outerThis.stackFilter(outerThis.stackFilter(errorMessage))) + "']"); | ||
} else { | ||
outerThis.log_.push(' ' + outerThis.stackFilter(errorMessage) + '\n'); | ||
outerThis.log_.push(result.message.indexOf('timeout:') == 0 ? | ||
' TIMEOUT:' + result.message.substr(8) : | ||
' ' + outerThis.stackFilter(errorMessage) + '\n'); | ||
} | ||
} | ||
}); | ||
if (outerThis.teamcity_) | ||
outerThis.log_.push("##teamcity[testFinished name='" + escapeTeamcityString(spec.description) + "']"); | ||
} else { | ||
if (outerThis.isVerbose_ && !outerThis.teamcity_) | ||
if (outerThis.isVerbose_) { | ||
outerThis.log_.push(' it ' + spec.description); | ||
} | ||
} | ||
}); | ||
if (this.teamcity_) | ||
this.log_.push("##teamcity[testSuiteFinished name='" + escapeTeamcityString(description) + "]"); | ||
}, | ||
@@ -128,0 +108,0 @@ |
{ | ||
"name" : "jasmine-node" | ||
, "version" : "1.0.12" | ||
, "version" : "1.0.13" | ||
, "description" : "DOM-less simple JavaScript BDD testing framework for Node" | ||
@@ -19,5 +19,5 @@ , "homepage" : [ "http://pivotal.github.com/jasmine" | ||
, "licenses" : ["MIT"] | ||
, "dependencies" : { "coffee-script" : ">=1.0.1", "jasmine-reporters" : "0.1.0"} | ||
, "dependencies" : { "coffee-script" : ">=1.0.1", "jasmine-reporters" : "0.1.0", "requirejs" : ">=0.27.1"} | ||
, "bin" : "bin/jasmine-node" | ||
, "main" : "lib/jasmine-node" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
110480
30
2726
0
3
8
1
+ Addedrequirejs@>=0.27.1
+ Addedrequirejs@2.3.7(transitive)