diff --git a/bin/cmd.js b/bin/cmd.js index 2c12800..d978228 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -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({ diff --git a/index.js b/index.js index ea05592..6482556 100644 --- a/index.js +++ b/index.js @@ -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(); @@ -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) { @@ -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)); @@ -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) || '' diff --git a/package.json b/package.json index b7a4e51..2abbea2 100644 --- a/package.json +++ b/package.json @@ -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",