[Pkg-javascript-commits] [node-tap-mocha-reporter] 05/137: make tap reporter a pass-through
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Sep 7 09:49:21 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-tap-mocha-reporter.
commit 16d0b633f7f89a82eb84f6b4e301933b13eb2802
Author: isaacs <i at izs.me>
Date: Fri Apr 10 15:24:23 2015 -0700
make tap reporter a pass-through
---
index.js | 21 +++++++++++++++
lib/reporters/index.js | 2 +-
lib/reporters/tap.js | 72 --------------------------------------------------
lib/suite.js | 2 +-
4 files changed, 23 insertions(+), 74 deletions(-)
diff --git a/index.js b/index.js
index a2ccd42..39458fa 100644
--- a/index.js
+++ b/index.js
@@ -6,6 +6,7 @@ var util = require('util')
var reporters = require('./lib/reporters/index.js')
var Writable = require('stream').Writable
var Runner = require('./lib/runner.js')
+var Parser = require('tap-parser')
util.inherits(Formatter, Writable)
@@ -15,6 +16,26 @@ function Formatter (type, options) {
type = 'silent'
}
+ // don't actually need a reporter to report the tap we're getting
+ // just parse it so that we exit with the correct code, but otherwise
+ // dump it straight through to stdout.
+ if (type === 'tap') {
+ var p = new Parser()
+ this.write = function (chunk) {
+ process.stdout.write(chunk)
+ return p.write(chunk)
+ }
+ this.end = p.end.bind(p)
+ p.on('complete', function () {
+ if (!p.ok) {
+ process.nextTick(function () {
+ process.exit(1)
+ })
+ }
+ })
+ return this
+ }
+
var runner = this.runner = new Runner(options)
this.reporter = new reporters[type](this.runner)
Writable.call(this, options)
diff --git a/lib/reporters/index.js b/lib/reporters/index.js
index bdde95b..0fe87bd 100644
--- a/lib/reporters/index.js
+++ b/lib/reporters/index.js
@@ -1,7 +1,7 @@
exports.base = require('./base.js')
exports.dot = require('./dot.js')
exports.doc = require('./doc.js')
-exports.tap = require('./tap.js')
+exports.tap = true
exports.json = require('./json.js')
exports.html = require('./html.js')
exports.list = require('./list.js')
diff --git a/lib/reporters/tap.js b/lib/reporters/tap.js
deleted file mode 100644
index 01a92eb..0000000
--- a/lib/reporters/tap.js
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , cursor = Base.cursor
- , color = Base.color;
-
-/**
- * Expose `TAP`.
- */
-
-exports = module.exports = TAP;
-
-/**
- * Initialize a new `TAP` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function TAP(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , n = 1
- , passes = 0
- , failures = 0;
-
- runner.on('start', function(){
- var total = runner.grepTotal(runner.suite);
- console.log('%d..%d', 1, total);
- });
-
- runner.on('test end', function(){
- ++n;
- });
-
- runner.on('pending', function(test){
- console.log('ok %d %s # SKIP -', n, title(test));
- });
-
- runner.on('pass', function(test){
- passes++;
- console.log('ok %d %s', n, title(test));
- });
-
- runner.on('fail', function(test, err){
- failures++;
- console.log('not ok %d %s', n, title(test));
- if (err.stack) console.log(err.stack.replace(/^/gm, ' '));
- });
-
- runner.on('end', function(){
- console.log('# tests ' + (passes + failures));
- console.log('# pass ' + passes);
- console.log('# fail ' + failures);
- });
-}
-
-/**
- * Return a TAP-safe title of `test`
- *
- * @param {Object} test
- * @return {String}
- * @api private
- */
-
-function title(test) {
- return test.fullTitle().replace(/#/g, '');
-}
diff --git a/lib/suite.js b/lib/suite.js
index 24b0cb3..2bd1b6a 100644
--- a/lib/suite.js
+++ b/lib/suite.js
@@ -8,7 +8,7 @@ function Suite (parent) {
else
this.root = false
- this.title = parent.name
+ this.title = parent.name || ''
this.suites = []
this.tests = []
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap-mocha-reporter.git
More information about the Pkg-javascript-commits
mailing list