Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative TAP command support #20

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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