From 8492627aab7a03f0e0dc77fc40da3f5f84be21e1 Mon Sep 17 00:00:00 2001 From: Joe Lapp Date: Mon, 18 Jul 2016 00:00:25 -0500 Subject: [PATCH 1/4] Now passes command line -arg options to the tape command. Supports the proposed tape -n command option. --- bin/cmd.js | 13 +++++++++++-- readme.markdown | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index d978228..2da326e 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -15,7 +15,15 @@ var path = require('path'); var regexTester = require('safe-regex-test'); var jsFile = regexTester(/\.js$/i); -var argv = minimist(process.argv.slice(2)); +var faucetArgs = process.argv.slice(2); +var opts = []; +faucetArgs.forEach(function (arg) { + if (arg[0] === '-') { + opts.push(arg); + } +}); +var argv = minimist(faucetArgs); + var tap = faucet({ width: defined(argv.w, argv.width, process.stdout.isTTY ? process.stdout.columns - 5 @@ -59,7 +67,8 @@ if (files.length === 0) { process.exit(1); } -var tape = spawn(tapeCmd, files); +var tapeArgs = opts.concat(files); +var tape = spawn(tapeCmd, tapeArgs); tape.stderr.pipe(process.stderr); tape.stdout.pipe(tap).pipe(process.stdout); diff --git a/readme.markdown b/readme.markdown index f9f13db..a1e3637 100644 --- a/readme.markdown +++ b/readme.markdown @@ -136,6 +136,8 @@ Once you've got a way to get TAP out of your tests, just pipe into `faucet`: ``` usage: faucet [FILES] + faucet -n [FILES] + faucet -n[N] [FILES] command | faucet ``` From 599934003909eb7b7e1a85f83c81f0a05bebc379 Mon Sep 17 00:00:00 2001 From: Joe Lapp Date: Wed, 3 Aug 2016 18:24:00 -0500 Subject: [PATCH 2/4] supports FAUCET_TAP_CMD env var; accepts an 'assertions' summary count --- bin/cmd.js | 3 ++- index.js | 2 +- readme.markdown | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index 2da326e..c7e7987 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -6,7 +6,8 @@ var faucet = require('../'); var minimist = require('minimist'); var defined = require('defined'); var which = require('npm-which'); -var tapeCmd = which.sync('tape', { cwd: process.cwd() }); + +var tapeCmd = process.env.FAUCET_TAP_CMD || which.sync('tape', { cwd: process.cwd() }); var spawn = require('child_process').spawn; var fs = require('fs'); diff --git a/index.js b/index.js index fe5936e..3bc3cfc 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ var split = require('string.prototype.split'); var trim = require('string.prototype.trim'); var regexTester = require('safe-regex-test'); -var isPassing = regexTester(/^(tests|pass)\s+\d+$/); +var isPassing = regexTester(/^(assertions|tests|pass)\s+\d+$/); var isFailing = regexTester(/^fail\s+\d+$/); module.exports = function (opts) { diff --git a/readme.markdown b/readme.markdown index a1e3637..4d51f15 100644 --- a/readme.markdown +++ b/readme.markdown @@ -135,12 +135,14 @@ Once you've got a way to get TAP out of your tests, just pipe into `faucet`: ``` usage: - faucet [FILES] - faucet -n [FILES] - faucet -n[N] [FILES] + faucet [OPTIONS] [FILES] command | faucet ``` +The command options and files arguments are both optional. Command options begin with `-` (dash). All other arguments are files. + +By default, `faucet` passes the command options and files to the `tape` executable found in the [`tape` module](https://github.com/substack/tape). The environment variable `FAUCET_TAP_CMD` may override this with a a path to a different TAP-producing command. + # license MIT From 0d7e916af3c9d21366a124d0925d259152eb0f15 Mon Sep 17 00:00:00 2001 From: Joe Lapp Date: Thu, 4 Aug 2016 08:54:56 -0500 Subject: [PATCH 3/4] allow faucet to get - arg --- bin/cmd.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index c7e7987..c61202f 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -16,11 +16,13 @@ var path = require('path'); var regexTester = require('safe-regex-test'); var jsFile = regexTester(/\.js$/i); -var faucetArgs = process.argv.slice(2); +var faucetArgs = []; var opts = []; faucetArgs.forEach(function (arg) { - if (arg[0] === '-') { + if (arg.length > 1 && arg.charAt(0) === '-') { opts.push(arg); + } else { + faucetArgs.push(arg); } }); var argv = minimist(faucetArgs); From fa3c290b483db0de855e3772c658b02b49d9ca7d Mon Sep 17 00:00:00 2001 From: Joe Lapp Date: Thu, 4 Aug 2016 23:20:10 -0500 Subject: [PATCH 4/4] added support for TAP bail outs --- bin/cmd.js | 4 ++-- index.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index c61202f..c13bae4 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -18,8 +18,8 @@ var jsFile = regexTester(/\.js$/i); var faucetArgs = []; var opts = []; -faucetArgs.forEach(function (arg) { - if (arg.length > 1 && arg.charAt(0) === '-') { +process.argv.slice(2).forEach(function(arg) { + if (arg !== '-' && arg[0] === '-') { opts.push(arg); } else { faucetArgs.push(arg); diff --git a/index.js b/index.js index 3bc3cfc..122dcd5 100644 --- a/index.js +++ b/index.js @@ -33,6 +33,7 @@ module.exports = function (opts) { } var test; + var bailout = null; tap.on('comment', function (comment) { if (comment === 'fail 0') { return; } // a mocha thing @@ -87,6 +88,12 @@ module.exports = function (opts) { }); tap.on('extra', function (extra) { + if (/^bail out!/i.test(extra)) { + // faucet is incompatible with tap-parser that supports bail out + bailout = extra; + return; + } + if (!test || test.assertions.length === 0) { return; } var last = test.assertions[test.assertions.length - 1]; if (!last.ok) { @@ -123,7 +130,10 @@ module.exports = function (opts) { (res.errors.length + res.fail.length) || '' )); } - + + if (bailout !== null) { + out.push('\r\x1b[1m\x1b[31m- '+ bailout + '\x1b[0m\x1b[K\n'); + } out.push(null); dup.emit('results', res);