Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tape-testing/faucet
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8b3bd3f4fefdde657caa1c306cfbcc370bd68ca6
Choose a base ref
..
head repository: tape-testing/faucet
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 825fff74759f47dcb4c21c41be4b84ce92f857c4
Choose a head ref
Showing with 397 additions and 238 deletions.
  1. +32 −0 .eslintrc
  2. +7 −0 .gitignore
  3. +1 −0 .npmrc
  4. +15 −12 LICENSE
  5. +36 −35 bin/cmd.js
  6. +13 −9 example/tape.js
  7. +25 −19 example/test.js
  8. +123 −119 index.js
  9. +50 −35 package.json
  10. +9 −9 readme.markdown
  11. +20 −0 test/long-message/failed.tap
  12. +53 −0 test/long-message/index.js
  13. +13 −0 test/long-message/succeeded.tap
32 changes: 32 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"root": true,

"extends": "@ljharb",

"rules": {
"func-style": ["error", "declaration"],
"max-lines-per-function": "off",
"max-statements-per-line": ["error", { "max": 2 }],
"no-plusplus": "warn",
"sort-keys": "off",
},

"overrides": [
{
"files": "bin/**",
"env": {
"node": true,
},
"rules": {
"no-process-exit": "off",
}
},
{
"files": "example/**",
"rules": {
"no-magic-numbers": "off",
"no-plusplus": "off",
},
},
],
}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# gitignore

node_modules/

npm-shrinkwrap.json
package-lock.json
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
27 changes: 15 additions & 12 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
This software is released under the MIT license:
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
Copyright (c) 2013 James Halliday

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
71 changes: 36 additions & 35 deletions bin/cmd.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
#!/usr/bin/env node

'use strict';

var faucet = require('../');
var minimist = require('minimist');
var defined = require('defined');
var tapeCmd = require.resolve('tape/bin/tape');
var which = require('npm-which');
var tapeCmd = which.sync('tape', { cwd: process.cwd() });

var spawn = require('child_process').spawn;
var fs = require('fs');
var path = require('path');

var regexTester = require('safe-regex-test');
var jsFile = regexTester(/\.js$/i);

var argv = minimist(process.argv.slice(2));
var tap = faucet({
width: defined(argv.w, argv.width, process.stdout.isTTY
? process.stdout.columns - 5
: 0
)
width: defined(argv.w, argv.width, process.stdout.isTTY
? process.stdout.columns - 5
: 0)
});
process.on('exit', function (code) {
if (code === 0 && tap.exitCode !== 0) {
process.exit(tap.exitCode);
}
if (code === 0 && tap.exitCode !== 0) {
process.exit(tap.exitCode);
}
});
process.stdout.on('error', function () {});

if (!process.stdin.isTTY || argv._[0] === '-') {
process.stdin.pipe(tap).pipe(process.stdout);
return;
process.stdin.pipe(tap).pipe(process.stdout);
return;
}

var files = argv._.reduce(function (acc, file) {
if (fs.statSync(file).isDirectory()) {
return acc.concat(fs.readdirSync(file).map(function (x) {
return path.join(file, x);
}).filter(jsFile));
}
else return acc.concat(file);
if (fs.statSync(file).isDirectory()) {
return acc.concat(fs.readdirSync(file).map(function (x) {
return path.join(file, x);
}).filter(jsFile));
}
return acc.concat(file);
}, []);

if (files.length === 0 && fs.existsSync('test')) {
files.push.apply(files, fs.readdirSync('test').map(function (x) {
return path.join('test', x);
}).filter(jsFile));
files.push.apply(files, fs.readdirSync('test').map(function (x) {
return path.join('test', x);
}).filter(jsFile));
}
if (files.length === 0 && fs.existsSync('tests')) {
files.push.apply(files, fs.readdirSync('tests').map(function (x) {
return path.join('tests', x);
}).filter(jsFile));
files.push.apply(files, fs.readdirSync('tests').map(function (x) {
return path.join('tests', x);
}).filter(jsFile));
}

if (files.length === 0) {
console.error('usage: `faucet [FILES]` or `| faucet`\n');
console.error(
'No test files or stdin provided and no files in test/ or tests/'
+ ' directories found.'
);
return process.exit(1);
console.error('usage: `faucet [FILES]` or `| faucet`\n');
console.error('No test files or stdin provided and no files in test/ or tests/ directories found.');
process.exit(1);
}

var tape = spawn(tapeCmd, files);
tape.stderr.pipe(process.stderr);
tape.stdout.pipe(tap).pipe(process.stdout);

var tapeCode;
tape.on('exit', function (code) { tapeCode = code });
tape.on('exit', function (code) { tapeCode = code; });
process.on('exit', function (code) {
if (code === 0 && tapeCode !== 0) {
console.error('# non-zero exit from the `tape` command');
process.exit(tapeCode);
}
if (code === 0 && tapeCode !== 0) {
console.error('# non-zero exit from the `tape` command');
process.exit(tapeCode);
}
});

function jsFile (x) { return /\.js$/i.test(x) }
22 changes: 13 additions & 9 deletions example/tape.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'use strict';

var test = require('tape');

test('beep boop', function (t) {
t.plan(2);

t.equal(1 + 1, 2);
setTimeout(function () {
t.deepEqual(
'ABC'.toLowerCase().split(''),
['a','b','c']
);
});
t.plan(2);

t.equal(1 + 1, 2);
setTimeout(function () {
t.deepEqual(
'ABC'.toLowerCase().split(''),
[
'a', 'b', 'c'
]
);
});
});
44 changes: 25 additions & 19 deletions example/test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
'use strict';

var test = require('tape');
function getMessage () {
var msgs = [ 'yes', 'equals', 'matches', 'yep', 'pretty much', 'woo' ];
return msgs[Math.floor(Math.random() * msgs.length)];

function getMessage() {
var msgs = [
'yes', 'equals', 'matches', 'yep', 'pretty much', 'woo'
];
return msgs[Math.floor(Math.random() * msgs.length)];
}

test('beep affirmative', function (t) {
t.plan(24);
var i = 0, n = 0;
var iv = setInterval(function () {
t.equal(i++, n++, getMessage());
if (i === 24) clearInterval(iv);
}, 50);
t.plan(24);
var i = 0,
n = 0;
var iv = setInterval(function () {
t.equal(i++, n++, getMessage());
if (i === 24) { clearInterval(iv); }
}, 50);
});

test('boop exterminate', function (t) {
t.plan(20);
var i = 0, n = 0;
var iv = setInterval(function () {
if ((i + 2) % 8 === 0) {
t.equal(i, n + 6, getMessage())
}
else t.equal(i, n, getMessage());
i++; n++;
if (i === 20) clearInterval(iv);
}, 100);
t.plan(20);
var i = 0,
n = 0;
var iv = setInterval(function () {
if ((i + 2) % 8 === 0) {
t.equal(i, n + 6, getMessage());
} else { t.equal(i, n, getMessage()); }
i++; n++;
if (i === 20) { clearInterval(iv); }
}, 100);
});
Loading