Skip to content

Commit

Permalink
[Robustness] use safe-regex-test
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 22, 2022
1 parent edcea74 commit 418c79e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var spawn = require('child_process').spawn;
var fs = require('fs');
var path = require('path');

function jsFile(x) { return (/\.js$/i).test(x); }
var regexTester = require('safe-regex-test');
var jsFile = regexTester(/\.js$/i);

var argv = minimist(process.argv.slice(2));
var tap = faucet({
Expand Down
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ var sprintf = require('sprintf-js').sprintf;
var forEach = require('array.prototype.foreach');
var push = require('array.prototype.push');
var trim = require('string.prototype.trim');
var regexTester = require('safe-regex-test');

var isPassing = regexTester(/^(tests|pass)\s+\d+$/);
var isFailing = regexTester(/^fail\s+\d+$/);

module.exports = function (opts) {
var tap = parser();
Expand All @@ -32,7 +36,7 @@ module.exports = function (opts) {
test
&& test.ok
&& test.assertions.length === 0
&& (/^(tests|pass)\s+\d+$/).test(test.name)
&& isPassing(test.name)
) {
push(out, '\r' + trimWidth(test.name));
} else if (test && test.ok) {
Expand Down Expand Up @@ -90,7 +94,7 @@ module.exports = function (opts) {
var dup = duplexer(tap, out);

tap.on('results', function (res) {
if (test && (/^fail\s+\d+$/).test(test.name)) {
if (test && isFailing(test.name)) {
push(out, updateName(test.offset + 1, '⨯ ' + test.name, 31));
} else if (test && test.ok) {
push(out, updateName(test.offset + 1, '✓ ' + test.name, 32));
Expand All @@ -104,7 +108,7 @@ module.exports = function (opts) {
));
});

if (!res.ok && !(/^fail\s+\d+$/).test(test && test.name)) {
if (!res.ok && !isFailing(test && test.name)) {
push(out, sprintf(
'\r\x1b[1m\x1b[31m⨯ fail %s\x1b[0m\x1b[K\n',
(res.errors.length + res.fail.length) || ''
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"duplexer": "^0.1.2",
"minimist": "^1.2.6",
"npm-which": "^1.0.2",
"safe-regex-test": "^1.0.0",
"sprintf-js": "^1.1.2",
"string.prototype.trim": "^1.2.6",
"tap-parser": "^0.4.3",
Expand Down

0 comments on commit 418c79e

Please sign in to comment.