Comparing version 1.0.1 to 2.0.0
95
index.js
var through = require('through2'); | ||
var parser = require('tap-parser'); | ||
var duplexer = require('duplexer'); | ||
var chalk = require('chalk'); | ||
var format = require('chalk'); | ||
var prettyMs = require('pretty-ms'); | ||
@@ -20,39 +21,90 @@ var symbols = { | ||
module.exports = function() { | ||
var startTime = new Date().getTime(); | ||
var endTime; | ||
var out = through(); | ||
var tap = parser(); | ||
var dup = duplexer(tap, out); | ||
var previousTestName = ''; | ||
var currentTestName = ''; | ||
var testNumber = 0; | ||
var errors = []; | ||
var runnerData = {}; | ||
var res; | ||
out.push('\n'); | ||
// Comments from tests | ||
tap.on('comment', function (comment) { | ||
previousTestName = currentTestName; | ||
currentTestName = comment; | ||
// Keep track of test number | ||
if (currentTestName !== previousTestName) { | ||
testNumber += 1; | ||
} | ||
if (/^tests\s+[1-9]/gi.test(comment)) comment = chalk.white(comment); | ||
else if (/^pass\s+[1-9]/gi.test(comment)) comment = chalk.green(comment); | ||
else if (/^fail\s+[1-9]/gi.test(comment)) comment = chalk.red(comment); | ||
else if (/^ok$/gi.test(comment)) return; | ||
else out.push('\n'); | ||
if (/^tests\s+[1-9]/gi.test(comment)) { | ||
return; | ||
} | ||
else if (/^pass\s+[1-9]/gi.test(comment)) { | ||
return; | ||
} | ||
else if (/^fail\s+[1-9]/gi.test(comment)) { | ||
return; | ||
} | ||
else if (/^ok$/gi.test(comment)) { | ||
return; | ||
} | ||
else { | ||
// Test name | ||
comment = testNumber + ') ' + comment + '\n'; | ||
out.push('\n'); | ||
} | ||
out.push(' ' + comment + '\n'); | ||
}); | ||
// Asserts | ||
tap.on('assert', function (res) { | ||
var output = (res.ok) | ||
? chalk.green(symbols.ok) | ||
: chalk.red(symbols.err); | ||
? format.green(symbols.ok) | ||
: format.red(symbols.err); | ||
if (!res.ok) errors.push(currentTestName + ' ' + res.name); | ||
out.push(' ' + output + ' ' + chalk.gray(res.name) + '\n'); | ||
out.push(' ' + output + ' ' + format.gray(res.name) + '\n'); | ||
}); | ||
// Generic outputs | ||
tap.on('extra', function (extra) { | ||
out.push(' ' + extra + '\n'); | ||
out.push(' ' + format.yellow(extra) + '\n'); | ||
}); | ||
// All done | ||
tap.on('results', function (_res) { | ||
res = _res | ||
// Test number | ||
out.push(' total: ' + res.asserts.length + '\n'); | ||
// Pass number | ||
out.push(format.green(' passing: ' + res.pass.length + '\n')); | ||
// Fail number | ||
if (res.fail.length > 0) { | ||
out.push(format.red(' failing: ' + res.fail.length + '\n')); | ||
} | ||
// Duration | ||
out.push(' duration: ' + prettyMs(new Date().getTime() - startTime) + '\n'); | ||
out.push('\n'); | ||
if (errors.length) { | ||
@@ -62,18 +114,21 @@ var past = (errors.length == 1) ? 'was' : 'were'; | ||
out.push(' ' + chalk.red('Failed Tests: ')); | ||
out.push('There ' + past + ' ' + chalk.red(errors.length) + ' ' + plural + '\n\n'); | ||
out.push(' ' + format.red('Failed Tests: ')); | ||
out.push('There ' + past + ' ' + format.red(errors.length) + ' ' + plural + '\n\n'); | ||
errors.forEach(function (error) { | ||
out.push(' ' + chalk.red(symbols.err) + ' ' + chalk.red(error) + '\n'); | ||
out.push(' ' + format.red(symbols.err) + ' ' + format.red(error) + '\n'); | ||
}); | ||
} | ||
else if (!res.ok) { | ||
out.push(' ' + chalk.red('Fail!') + '\n'); | ||
out.push(' ' + format.red('Fail!') + '\n'); | ||
} | ||
else{ | ||
out.push(' ' + chalk.green('Pass!') + '\n'); | ||
out.push(' ' + format.green.bold('All tests pass!') + '\n'); | ||
} | ||
out.push('\n'); | ||
// Expose errors and res on returned dup stream | ||
@@ -80,0 +135,0 @@ dup.errors = errors; |
{ | ||
"name": "tap-spec", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Formatted TAP output like Mocha's spec reporter", | ||
@@ -26,6 +26,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"chalk": "~0.5.1", | ||
"through2": "~0.6.1", | ||
"tap-parser": "~0.7.0", | ||
"duplexer": "~0.1.1" | ||
"chalk": "^0.5.1", | ||
"duplexer": "^0.1.1", | ||
"pretty-ms": "^1.0.0", | ||
"tap-parser": "^0.7.0", | ||
"through2": "^0.6.3" | ||
}, | ||
@@ -32,0 +33,0 @@ "bin": { |
@@ -5,3 +5,3 @@ # tap-spec | ||
![Output screenshot](http://i.imgur.com/3yh5prr.png) | ||
![screen shot 2014-11-20 at 3 32 32 pm](https://cloud.githubusercontent.com/assets/974723/5135186/a7d15ff6-70ca-11e4-9526-e1e5cbaa0f4b.png) | ||
@@ -8,0 +8,0 @@ ## Install |
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
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
4918
115
5
+ Addedpretty-ms@^1.0.0
+ Addedarray-find-index@1.0.2(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcamelcase-keys@2.1.0(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@2.1.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmeow@3.7.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedparse-ms@1.0.1(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedplur@1.0.0(transitive)
+ Addedpretty-ms@1.4.0(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedredent@1.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedstrip-indent@1.0.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtrim-newlines@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
Updatedchalk@^0.5.1
Updatedduplexer@^0.1.1
Updatedtap-parser@^0.7.0
Updatedthrough2@^0.6.3