diff --git a/bin/cmd.js b/bin/cmd.js index d978228..c13bae4 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'); @@ -15,7 +16,17 @@ var path = require('path'); var regexTester = require('safe-regex-test'); var jsFile = regexTester(/\.js$/i); -var argv = minimist(process.argv.slice(2)); +var faucetArgs = []; +var opts = []; +process.argv.slice(2).forEach(function(arg) { + if (arg !== '-' && arg[0] === '-') { + opts.push(arg); + } else { + faucetArgs.push(arg); + } +}); +var argv = minimist(faucetArgs); + var tap = faucet({ width: defined(argv.w, argv.width, process.stdout.isTTY ? process.stdout.columns - 5 @@ -59,7 +70,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/index.js b/index.js index fe5936e..122dcd5 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) { @@ -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); diff --git a/readme.markdown b/readme.markdown index f9f13db..4d51f15 100644 --- a/readme.markdown +++ b/readme.markdown @@ -135,10 +135,14 @@ Once you've got a way to get TAP out of your tests, just pipe into `faucet`: ``` usage: - faucet [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