Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tap-spec

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tap-spec - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc