From 4acf1f292289c40c1abfb2552e09e28a9da3416a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 23 Jul 2021 23:14:19 -0700 Subject: [PATCH 01/18] [eslint] enable `comma-spacing` --- .eslintrc | 4 ++++ example/array.js | 2 +- example/fail.js | 2 +- example/nested_fail.js | 2 +- example/too_many_fail.js | 2 +- test/array.js | 2 +- test/browser/asserts.js | 4 ++-- test/exit/fail.js | 2 +- test/exit/ok.js | 2 +- test/exit/too_few.js | 2 +- test/fail.js | 2 +- test/nested.js | 2 +- test/too_many.js | 2 +- 13 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.eslintrc b/.eslintrc index d4840579..ed177845 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,6 +9,10 @@ }, "rules": { "comma-dangle": ["error", "never"], + "comma-spacing": [2, { + "before": false, + "after": true, + }], "indent": ["error", 4], "key-spacing": "error", "quotes": ["error", "single", { diff --git a/example/array.js b/example/array.js index 8b998041..cb17d42b 100644 --- a/example/array.js +++ b/example/array.js @@ -25,7 +25,7 @@ test('array', function (t) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/example/fail.js b/example/fail.js index 28c6ac71..4373c76b 100644 --- a/example/fail.js +++ b/example/fail.js @@ -25,7 +25,7 @@ test('array', function (t) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/example/nested_fail.js b/example/nested_fail.js index 8013a48d..44ea3fd1 100644 --- a/example/nested_fail.js +++ b/example/nested_fail.js @@ -34,7 +34,7 @@ test('nested array test', function (t) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/example/too_many_fail.js b/example/too_many_fail.js index e5780be0..e374008f 100644 --- a/example/too_many_fail.js +++ b/example/too_many_fail.js @@ -25,7 +25,7 @@ test('array', function (t) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/test/array.js b/test/array.js index 7a27038a..502b3f97 100644 --- a/test/array.js +++ b/test/array.js @@ -50,7 +50,7 @@ tap.test('array test', function (tt) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/test/browser/asserts.js b/test/browser/asserts.js index 77611f56..690597ca 100644 --- a/test/browser/asserts.js +++ b/test/browser/asserts.js @@ -6,6 +6,6 @@ test(function (t) { t.plan(4); t.ok(true); t.equal(3, 1+2); - t.deepEqual([1,2,[3,4]], [1,2,[3,4]]); - t.notDeepEqual([1,2,[3,4,5]], [1,2,[3,4]]); + t.deepEqual([1, 2, [3, 4]], [1, 2, [3, 4]]); + t.notDeepEqual([1, 2, [3, 4, 5]], [1, 2, [3, 4]]); }); diff --git a/test/exit/fail.js b/test/exit/fail.js index a976d4ce..45fc1789 100644 --- a/test/exit/fail.js +++ b/test/exit/fail.js @@ -25,7 +25,7 @@ test('array', function (t) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/test/exit/ok.js b/test/exit/ok.js index 084692f5..1c68c15e 100644 --- a/test/exit/ok.js +++ b/test/exit/ok.js @@ -26,7 +26,7 @@ test('array', function (t) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/test/exit/too_few.js b/test/exit/too_few.js index d92fe5c1..cd347e54 100644 --- a/test/exit/too_few.js +++ b/test/exit/too_few.js @@ -25,7 +25,7 @@ test('array', function (t) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/test/fail.js b/test/fail.js index c5dab576..78642c84 100644 --- a/test/fail.js +++ b/test/fail.js @@ -67,7 +67,7 @@ tap.test('array test', function (tt) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/test/nested.js b/test/nested.js index d86e94cd..2dd19583 100644 --- a/test/nested.js +++ b/test/nested.js @@ -65,7 +65,7 @@ tap.test('array test', function (tt) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; diff --git a/test/too_many.js b/test/too_many.js index 530ceb2a..f6ba5582 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -68,7 +68,7 @@ tap.test('array test', function (tt) { [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; From 233ffc623ec212b202037e03b503a6667d4deb3f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 23 Jul 2021 23:17:01 -0700 Subject: [PATCH 02/18] [eslint] enable `space-infix-ops` --- .eslintrc | 1 + example/two.js | 4 ++-- test/browser/asserts.js | 2 +- test/teardown.js | 2 +- test/todo_explanation.js | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.eslintrc b/.eslintrc index ed177845..356a6546 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,6 +26,7 @@ "no-undef": "error", "no-useless-escape": "error", "operator-linebreak": ["error", "before"], + "space-infix-ops": "error", "space-unary-ops": ["error", { "words": false, "nonwords": false, diff --git a/example/two.js b/example/two.js index 0e315163..de5b213a 100644 --- a/example/two.js +++ b/example/two.js @@ -6,13 +6,13 @@ test('one', function (t) { t.plan(2); t.ok(true); setTimeout(function () { - t.equal(1+3, 4); + t.equal(1 + 3, 4); }, 100); }); test('two', function (t) { t.plan(3); - t.equal(5, 2+3); + t.equal(5, 2 + 3); setTimeout(function () { t.equal('a'.charCodeAt(0), 97); t.ok(true); diff --git a/test/browser/asserts.js b/test/browser/asserts.js index 690597ca..fb981b7c 100644 --- a/test/browser/asserts.js +++ b/test/browser/asserts.js @@ -5,7 +5,7 @@ var test = require('../../'); test(function (t) { t.plan(4); t.ok(true); - t.equal(3, 1+2); + t.equal(3, 1 + 2); t.deepEqual([1, 2, [3, 4]], [1, 2, [3, 4]]); t.notDeepEqual([1, 2, [3, 4, 5]], [1, 2, [3, 4]]); }); diff --git a/test/teardown.js b/test/teardown.js index e5013cf4..b86da8ed 100644 --- a/test/teardown.js +++ b/test/teardown.js @@ -95,7 +95,7 @@ tap.test('teardowns', function (tt) { ' [... stack stripped ...]', ' ...', i > 0 ? [] : [ - 'not ok '+ (offset + 1) +' plan != count', + 'not ok ' + (offset + 1) + ' plan != count', ' ---', ' operator: fail', ' expected: 1', diff --git a/test/todo_explanation.js b/test/todo_explanation.js index d0a57118..ce015826 100644 --- a/test/todo_explanation.js +++ b/test/todo_explanation.js @@ -7,7 +7,7 @@ var concat = require('concat-stream'); var common = require('./common'); var stripFullStack = common.stripFullStack; -tap.test('tape todo test', { todo: process.versions.node.match(/0\.8\.\d+/) ? 'Fails on node 0.8': false }, function (assert) { +tap.test('tape todo test', { todo: process.versions.node.match(/0\.8\.\d+/) ? 'Fails on node 0.8' : false }, function (assert) { var test = tape.createHarness({ exit: false }); assert.plan(1); From 428636c047f946738ca77796599aeb32cd607072 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 23 Jul 2021 23:19:24 -0700 Subject: [PATCH 03/18] [eslint] enable `wrap-iife` --- .eslintrc | 3 +++ index.js | 4 ++-- lib/test.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 356a6546..5a8de8df 100644 --- a/.eslintrc +++ b/.eslintrc @@ -32,6 +32,9 @@ "nonwords": false, }], "strict": "error", + "wrap-iife": ["error", "outside", { + "functionPrototypeMethods": true, + }], }, "ignorePatterns": [ "syntax-error.*" ], "overrides": [ diff --git a/index.js b/index.js index 0e9bb5a2..4aa5f8e5 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,7 @@ module.exports = (function () { if (!harness) harness = createExitHarness(opts, wait); return harness; } -})(); +}()); function createExitHarness(conf, wait) { var config = conf || {}; @@ -137,7 +137,7 @@ function createHarness(conf_) { st.on('result', function (r) { if (!r.todo && !r.ok && typeof r !== 'string') test._exitCode = 1; }); - })(t); + }(t)); results.push(t); return t; diff --git a/lib/test.js b/lib/test.js index ed005cb6..bf27b818 100644 --- a/lib/test.js +++ b/lib/test.js @@ -92,7 +92,7 @@ function Test(name_, opts_, cb_) { }; } return val; - })(this, this[prop]); + }(this, this[prop])); } } From 5f8afc997c793ca16de53aa56ac4d40b8afc8d4a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 23 Jul 2021 23:21:54 -0700 Subject: [PATCH 04/18] [eslint] enable `semi-style` --- .eslintrc | 1 + index.js | 6 ++---- lib/default_stream.js | 3 +-- lib/results.js | 4 +--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.eslintrc b/.eslintrc index 5a8de8df..9d426858 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,6 +26,7 @@ "no-undef": "error", "no-useless-escape": "error", "operator-linebreak": ["error", "before"], + "semi-style": ["error", "last"], "space-infix-ops": "error", "space-unary-ops": ["error", { "words": false, diff --git a/index.js b/index.js index 4aa5f8e5..44dd0f9c 100644 --- a/index.js +++ b/index.js @@ -7,11 +7,9 @@ var createResult = require('./lib/results'); var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' && process.browser !== true -; + && typeof process.on === 'function' && process.browser !== true; var canExit = typeof process !== 'undefined' && process - && typeof process.exit === 'function' -; + && typeof process.exit === 'function'; module.exports = (function () { var wait = false; diff --git a/lib/default_stream.js b/lib/default_stream.js index f8901ed4..03dcba0a 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -12,8 +12,7 @@ module.exports = function () { for (var i = 0; i < buf.length; i++) { var c = typeof buf === 'string' ? buf.charAt(i) - : String.fromCharCode(buf[i]) - ; + : String.fromCharCode(buf[i]); if (c === '\n') flush(); else line += c; } diff --git a/lib/results.js b/lib/results.js index 37bb1917..bd5cf2d7 100644 --- a/lib/results.js +++ b/lib/results.js @@ -16,9 +16,7 @@ var $push = callBound('Array.prototype.push'); var yamlIndicators = /:|-|\?/; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate - : process.nextTick -; - + : process.nextTick; module.exports = Results; inherits(Results, EventEmitter); From 1af8f529df22eb00a62474dfd6dfe5628f8f7317 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 09:18:03 -0700 Subject: [PATCH 05/18] [eslint] enable `no-extra-semi` --- .eslintrc | 1 + index.js | 2 +- lib/results.js | 2 +- test/double_end.js | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9d426858..cd66dba1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -23,6 +23,7 @@ "anonymous": "always", "named": "never", }], + "no-extra-semi": "error", "no-undef": "error", "no-useless-escape": "error", "operator-linebreak": ["error", "before"], diff --git a/index.js b/index.js index 44dd0f9c..be759e87 100644 --- a/index.js +++ b/index.js @@ -110,7 +110,7 @@ function createExitHarness(conf, wait) { es.on('error', function (err) { harness._exitCode = 1; }); } stream.on('end', function () { ended = true; }); - }; + } } module.exports.createHarness = createHarness; diff --git a/lib/results.js b/lib/results.js index bd5cf2d7..35b6569d 100644 --- a/lib/results.js +++ b/lib/results.js @@ -158,7 +158,7 @@ function encodeResult(res, count) { output += ' # SKIP' + ((typeof res.skip === 'string') ? ' ' + coalesceWhiteSpaces(res.skip) : ''); } else if (res.todo) { output += ' # TODO' + ((typeof res.todo === 'string') ? ' ' + coalesceWhiteSpaces(res.todo) : ''); - }; + } output += '\n'; if (res.ok) return output; diff --git a/test/double_end.js b/test/double_end.js index 23d6dc7c..af630cae 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -20,7 +20,7 @@ test(function (tt) { // This code is unfortunately by necessity highly coupled to node // versions, and may require tweaking with future versions of the timers // library. - function doEnd() { throw new Error(); }; + function doEnd() { throw new Error(); } var to = setTimeout(doEnd, 5000); clearTimeout(to); to._onTimeout = doEnd; From e9b75e14068359843082fd70994b19f871432a65 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 23 Jul 2021 23:31:03 -0700 Subject: [PATCH 06/18] [eslint] enable `curly`, `object-curly-spacing`, `object-curly-newline` --- .eslintrc | 14 ++++++++++++ index.js | 18 +++++++-------- lib/default_stream.js | 4 ++-- lib/results.js | 41 +++++++++++++++++++++------------- lib/test.js | 16 ++++++++----- test/comment.js | 2 +- test/deep-equal-failure.js | 4 ++-- test/ignore_from_gitignore.js | 6 ++--- test/not-deep-equal-failure.js | 4 ++-- test/objectMode.js | 8 +++---- test/onFailure.js | 7 +++++- test/onFinish.js | 2 +- test/throws.js | 6 ++++- 13 files changed, 85 insertions(+), 47 deletions(-) diff --git a/.eslintrc b/.eslintrc index cd66dba1..7c161435 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,7 @@ "before": false, "after": true, }], + "curly": ["error", "all"], "indent": ["error", 4], "key-spacing": "error", "quotes": ["error", "single", { @@ -26,6 +27,19 @@ "no-extra-semi": "error", "no-undef": "error", "no-useless-escape": "error", + "object-curly-newline": ["error", { + "ObjectExpression": { + "multiline": true, + "consistent": true, + "minProperties": 3, + }, + "ObjectPattern": { + "multiline": true, + "consistent": true, + "minProperties": 3, + }, + }], + "object-curly-spacing": ["error", "always"], "operator-linebreak": ["error", "before"], "semi-style": ["error", "last"], "space-infix-ops": "error", diff --git a/index.js b/index.js index be759e87..10200482 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ module.exports = (function () { lazyLoad.run = function () { var run = getHarness().run; - if (run) run(); + if (run) { run(); } }; lazyLoad.only = function () { @@ -55,9 +55,9 @@ module.exports = (function () { return lazyLoad; function getHarness(opts) { - if (!opts) opts = {}; + if (!opts) { opts = {}; } opts.autoclose = !canEmitExit; - if (!harness) harness = createExitHarness(opts, wait); + if (!harness) { harness = createExitHarness(opts, wait); } return harness; } }()); @@ -76,8 +76,8 @@ function createExitHarness(conf, wait) { run(); } - if (config.exit === false) return harness; - if (!canEmitExit || !canExit) return harness; + if (config.exit === false) { return harness; } + if (!canEmitExit || !canExit) { return harness; } process.on('exit', function (code) { // let the process exit cleanly. @@ -89,7 +89,7 @@ function createExitHarness(conf, wait) { var only = harness._results._only; for (var i = 0; i < harness._tests.length; i++) { var t = harness._tests[i]; - if (only && t !== only) continue; + if (only && t !== only) { continue; } t._exit(); } } @@ -102,7 +102,7 @@ function createExitHarness(conf, wait) { return harness; function run() { - if (running) return; + if (running) { return; } running = true; var stream = harness.createStream({ objectMode: config.objectMode }); var es = stream.pipe(config.stream || createDefaultStream()); @@ -133,7 +133,7 @@ function createHarness(conf_) { inspectCode(st_); }); st.on('result', function (r) { - if (!r.todo && !r.ok && typeof r !== 'string') test._exitCode = 1; + if (!r.todo && !r.ok && typeof r !== 'string') { test._exitCode = 1; } }); }(t)); @@ -158,7 +158,7 @@ function createHarness(conf_) { var only = false; test.only = function () { - if (only) throw new Error('there can only be one only test'); + if (only) { throw new Error('there can only be one only test'); } only = true; var t = test.apply(null, arguments); results.only(t); diff --git a/lib/default_stream.js b/lib/default_stream.js index 03dcba0a..75458a9d 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -13,8 +13,8 @@ module.exports = function () { var c = typeof buf === 'string' ? buf.charAt(i) : String.fromCharCode(buf[i]); - if (c === '\n') flush(); - else line += c; + if (c === '\n') { flush(); } + else { line += c; } } } diff --git a/lib/results.js b/lib/results.js index 35b6569d..eac95bb8 100644 --- a/lib/results.js +++ b/lib/results.js @@ -25,7 +25,7 @@ function coalesceWhiteSpaces(str) { } function Results() { - if (!(this instanceof Results)) return new Results; + if (!(this instanceof Results)) { return new Results(); } this.count = 0; this.fail = 0; this.pass = 0; @@ -37,13 +37,13 @@ function Results() { } Results.prototype.createStream = function (opts) { - if (!opts) opts = {}; + if (!opts) { opts = {}; } var self = this; var output, testId = 0; if (opts.objectMode) { output = through(); self.on('_push', function ontest(t, extra) { - if (!extra) extra = {}; + if (!extra) { extra = {}; } var id = testId++; t.once('prerun', function () { var row = { @@ -85,7 +85,9 @@ Results.prototype.createStream = function (opts) { var t; while (t = getNextTest(self)) { t.run(); - if (!t.ended) return t.once('end', function () { nextTick(next); }); + if (!t.ended) { + return t.once('end', function () { nextTick(next); }); + } } self.emit('done'); }); @@ -110,8 +112,11 @@ Results.prototype._watch = function (t) { var write = function (s) { self._stream.queue(s); }; t.once('prerun', function () { var premsg = ''; - if (t._skip) premsg = 'SKIP '; - else if (t._todo) premsg = 'TODO '; + if (t._skip) { + premsg = 'SKIP '; + } else if (t._todo) { + premsg = 'TODO '; + } write('# ' + premsg + coalesceWhiteSpaces(t.name) + '\n'); }); @@ -123,8 +128,9 @@ Results.prototype._watch = function (t) { write(encodeResult(res, self.count + 1)); self.count++; - if (res.ok || res.todo) self.pass++; - else { + if (res.ok || res.todo) { + self.pass++; + } else { self.fail++; self.emit('fail'); } @@ -135,16 +141,19 @@ Results.prototype._watch = function (t) { Results.prototype.close = function () { var self = this; - if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED')); + if (self.closed) { self._stream.emit('error', new Error('ALREADY CLOSED')); } self.closed = true; var write = function (s) { self._stream.queue(s); }; write('\n1..' + self.count + '\n'); write('# tests ' + self.count + '\n'); write('# pass ' + (self.pass + self.todo) + '\n'); - if (self.todo) write('# todo ' + self.todo + '\n'); - if (self.fail) write('# fail ' + self.fail + '\n'); - else write('\n# ok\n'); + if (self.todo) { write('# todo ' + self.todo + '\n'); } + if (self.fail) { + write('# fail ' + self.fail + '\n'); + } else { + write('\n# ok\n'); + } self._stream.queue(null); }; @@ -161,7 +170,7 @@ function encodeResult(res, count) { } output += '\n'; - if (res.ok) return output; + if (res.ok) { return output; } var outer = ' '; var inner = outer + ' '; @@ -169,8 +178,8 @@ function encodeResult(res, count) { output += inner + 'operator: ' + res.operator + '\n'; if (has(res, 'expected') || has(res, 'actual')) { - var ex = inspect(res.expected, {depth: res.objectPrintDepth}); - var ac = inspect(res.actual, {depth: res.objectPrintDepth}); + var ex = inspect(res.expected, { depth: res.objectPrintDepth }); + var ac = inspect(res.actual, { depth: res.objectPrintDepth }); if (Math.max(ex.length, ac.length) > 65 || invalidYaml(ex) || invalidYaml(ac)) { output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n'; @@ -206,7 +215,7 @@ function getNextTest(results) { do { var t = $shift(results.tests); - if (!t) continue; + if (!t) { continue; } if (results._only === t) { return t; } diff --git a/lib/test.js b/lib/test.js index bf27b818..37a85348 100644 --- a/lib/test.js +++ b/lib/test.js @@ -49,7 +49,11 @@ var getTestArgs = function (name_, opts_, cb_) { cb = arg; } } - return { name: name, opts: opts, cb: cb }; + return { + name: name, + opts: opts, + cb: cb + }; }; function Test(name_, opts_, cb_) { @@ -167,7 +171,7 @@ Test.prototype.plan = function plan(n) { }; Test.prototype.timeoutAfter = function timeoutAfter(ms) { - if (!ms) throw new Error('timeoutAfter requires a timespan'); + if (!ms) { throw new Error('timeoutAfter requires a timespan'); } var self = this; var timeout = safeSetTimeout(function () { self.fail(self.name + ' timed out after ' + ms + 'ms'); @@ -201,7 +205,9 @@ Test.prototype.teardown = function teardown(fn) { Test.prototype._end = function _end(err) { var self = this; - if (!this._cb && !this._todo && !this._skip) this.fail('# TODO ' + this.name); + if (!this._cb && !this._todo && !this._skip) { + this.fail('# TODO ' + this.name); + } if (this._progeny.length) { var t = $shift(this._progeny); @@ -234,7 +240,7 @@ Test.prototype._end = function _end(err) { next(); function completeEnd() { - if (!self.ended) self.emit('end'); + if (!self.ended) { self.emit('end'); } var pendingAsserts = self._pendingAsserts(); if (!self._planError && self._plan !== undefined && pendingAsserts) { self._planError = true; @@ -363,7 +369,7 @@ Test.prototype._assert = function assert(ok, opts) { res.functionName = $split(callDescription, /\s+/)[0]; res.file = filePath; res.line = Number(m[3]); - if (m[4]) res.column = Number(m[4]); + if (m[4]) { res.column = Number(m[4]); } res.at = callDescription + ' (' + filePath + ')'; break; diff --git a/test/comment.js b/test/comment.js index 378db5a8..c63395ac 100644 --- a/test/comment.js +++ b/test/comment.js @@ -132,7 +132,7 @@ tap.test('non-string types', function (assert) { t.comment(42); t.comment(6.66); t.comment({}); - t.comment({'answer': 42}); + t.comment({ answer: 42 }); function ConstructorFunction() {} t.comment(new ConstructorFunction()); t.comment(ConstructorFunction); diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index d5f1bc74..80216ff1 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -66,7 +66,7 @@ tap.test('deep equal failure', function (assert) { test('deep equal', function (t) { t.plan(1); - t.equal({a: 1}, {b: 2}); + t.equal({ a: 1 }, { b: 2 }); }); }); @@ -125,7 +125,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { }); }); - test('deep equal', {objectPrintDepth: 6}, function (t) { + test('deep equal', { objectPrintDepth: 6 }, function (t) { t.plan(1); t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }); }); diff --git a/test/ignore_from_gitignore.js b/test/ignore_from_gitignore.js index d95260b8..cda47b84 100644 --- a/test/ignore_from_gitignore.js +++ b/test/ignore_from_gitignore.js @@ -38,7 +38,7 @@ tap.test('Should pass with ignoring', { skip: process.platform === 'win32' }, fu ]); }; - var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], {cwd: path.join(__dirname, 'ignore')}); + var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], { cwd: path.join(__dirname, 'ignore') }); ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { tt.equal(code, 0); // code 0 @@ -95,7 +95,7 @@ tap.test('Should pass', { skip: process.platform === 'win32' }, function (tt) { ]); }; - var ps = spawn(tapeBin, ['**/*.js'], {cwd: path.join(__dirname, 'ignore')}); + var ps = spawn(tapeBin, ['**/*.js'], { cwd: path.join(__dirname, 'ignore') }); ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { tt.equal(code, 1); @@ -113,7 +113,7 @@ tap.test('Should fail when ignore file does not exist', { skip: process.platform tt.ok(/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m.test(stripFullStack(rows.toString('utf8')).join('\n'))); }; - var ps = spawn(tapeBin, ['**/*.js', '-i'], {cwd: path.join(__dirname, 'ignore')}); + var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') }); ps.stdout.pipe(concat(testStdout)); ps.stderr.pipe(concat(testStderr)); ps.on('exit', function (code) { diff --git a/test/not-deep-equal-failure.js b/test/not-deep-equal-failure.js index dadfa535..c90453dc 100644 --- a/test/not-deep-equal-failure.js +++ b/test/not-deep-equal-failure.js @@ -66,7 +66,7 @@ tap.test('deep equal failure', function (assert) { test('not deep equal', function (t) { t.plan(1); - t.notDeepEqual({b: 2}, {b: 2}); + t.notDeepEqual({ b: 2 }, { b: 2 }); }); }); @@ -125,7 +125,7 @@ tap.test('not deep equal failure, depth 6, with option', function (assert) { }); }); - test('not deep equal', {objectPrintDepth: 6}, function (t) { + test('not deep equal', { objectPrintDepth: 6 }, function (t) { t.plan(1); t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }); }); diff --git a/test/objectMode.js b/test/objectMode.js index 3a7cf379..0145a691 100644 --- a/test/objectMode.js +++ b/test/objectMode.js @@ -14,7 +14,7 @@ tap.test('object results', function (assert) { }; printer.end = function (obj) { - if (obj) objects.push(obj); + if (obj) { objects.push(obj); } var todos = 0; var skips = 0; @@ -53,17 +53,17 @@ tap.test('object results', function (assert) { tape('parent', function (t1) { t1.equal(true, true); - t1.test('child1', {skip: true}, function (t2) { + t1.test('child1', { skip: true }, function (t2) { t2.equal(true, true); t2.equal(true, false); t2.end(); }); - t1.test('child2', {todo: true}, function (t3) { + t1.test('child2', { todo: true }, function (t3) { t3.equal(true, false); t3.equal(true, true); t3.end(); }); - t1.test('child3', {todo: true}); + t1.test('child3', { todo: true }); t1.equal(true, true); t1.equal(true, true); t1.end(); diff --git a/test/onFailure.js b/test/onFailure.js index 7ae77df6..8420a822 100644 --- a/test/onFailure.js +++ b/test/onFailure.js @@ -6,7 +6,12 @@ var tape = require('../').createHarness(); //Because this test passing depends on a failure, //we must direct the failing output of the inner test var noop = function () {}; -var mockSink = {on: noop, removeListener: noop, emit: noop, end: noop}; +var mockSink = { + on: noop, + removeListener: noop, + emit: noop, + end: noop +}; tape.createStream().pipe(mockSink); tap.test('on failure', { timeout: 1000 }, function (tt) { diff --git a/test/onFinish.js b/test/onFinish.js index ba7597c4..db3b7609 100644 --- a/test/onFinish.js +++ b/test/onFinish.js @@ -3,7 +3,7 @@ var tap = require('tap'); var tape = require('../'); -tap.test('on finish', {timeout: 1000}, function (tt) { +tap.test('on finish', { timeout: 1000 }, function (tt) { tt.plan(1); tape.onFinish(function () { tt.pass('tape ended'); diff --git a/test/throws.js b/test/throws.js index 70d90cef..c0cb895d 100644 --- a/test/throws.js +++ b/test/throws.js @@ -24,7 +24,11 @@ var getter = function () { return 'message'; }; var messageGetterError = Object.defineProperty( { custom: 'error' }, 'message', - { configurable: true, enumerable: true, get: getter } + { + configurable: true, + enumerable: true, + get: getter + } ); var thrower = function () { throw messageGetterError; }; From f0756f3b12329a122498f99f6448ec8c9eafec50 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 23 Jul 2021 23:51:21 -0700 Subject: [PATCH 07/18] [eslint] enable `no-shadow` --- .eslintrc | 5 +++++ bin/tape | 10 +++++----- lib/test.js | 6 +++--- test/async-await/async5.js | 4 ++-- test/child_ordering.js | 30 +++++++++++++++--------------- test/nested2.js | 10 +++++----- test/objectMode.js | 18 +++++++++--------- test/promises/subTests.js | 8 ++++---- test/skip.js | 6 +++--- test/subcount.js | 12 ++++++------ test/subtest_plan.js | 14 +++++++------- test/throws.js | 12 ------------ 12 files changed, 64 insertions(+), 71 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7c161435..4a8fb4a0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -25,6 +25,11 @@ "named": "never", }], "no-extra-semi": "error", + "no-shadow": ["error", { + "builtinGlobals": false, + "hoist": "functions", + "allow": [] + }], "no-undef": "error", "no-useless-escape": "error", "object-curly-newline": ["error", { diff --git a/bin/tape b/bin/tape index a912c087..027fbb1b 100755 --- a/bin/tape +++ b/bin/tape @@ -47,13 +47,13 @@ if (typeof opts.ignore === 'string') { var files = opts._.reduce(function (result, arg) { // If glob does not match, `files` will be an empty array. // Note: `glob.sync` may throw an error and crash the node process. - var files = glob.sync(arg); + var globFiles = glob.sync(arg); - if (!Array.isArray(files)) { + if (!Array.isArray(globFiles)) { throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.'); } - return result.concat(files); + return result.concat(globFiles); }, []).filter(function (file) { return !matcher || !matcher.shouldIgnore(file); }).map(function (file) { @@ -75,13 +75,13 @@ function importFiles(hasSupport) { tape.wait(); - var promise = files.reduce(function (promise, file) { + var filesPromise = files.reduce(function (promise, file) { return promise ? promise.then(function () { return importOrRequire(file); }) : importOrRequire(file); }, null); - return promise ? promise.then(function () { tape.run(); }) : tape.run(); + return filesPromise ? filesPromise.then(function () { tape.run(); }) : tape.run(); } // vim: ft=javascript diff --git a/lib/test.js b/lib/test.js index 37a85348..71325f52 100644 --- a/lib/test.js +++ b/lib/test.js @@ -423,7 +423,7 @@ Test.prototype.skip = function skip(msg, extra) { }); }; -function assert(value, msg, extra) { +var testAssert = function assert(value, msg, extra) { this._assert(value, { message: defined(msg, 'should be truthy'), operator: 'ok', @@ -431,11 +431,11 @@ function assert(value, msg, extra) { actual: value, extra: extra }); -} +}; Test.prototype.ok = Test.prototype['true'] = Test.prototype.assert -= assert; += testAssert; function notOK(value, msg, extra) { this._assert(!value, { diff --git a/test/async-await/async5.js b/test/async-await/async5.js index a58930ec..eca3bc4a 100644 --- a/test/async-await/async5.js +++ b/test/async-await/async5.js @@ -33,8 +33,8 @@ test('async5', async function myTest(t) { port: server.address().port, path: '/', method: 'GET' - }, function (res) { - cb(null, res); + }, function (resp) { + cb(null, resp); }); req.end(); })(); diff --git a/test/child_ordering.js b/test/child_ordering.js index c2cb2c29..6c75f587 100644 --- a/test/child_ordering.js +++ b/test/child_ordering.js @@ -5,10 +5,10 @@ var test = require('../'); var childRan = false; test('parent', function (t) { - t.test('child', function (t) { + t.test('child', function (st) { childRan = true; - t.pass('child ran'); - t.end(); + st.pass('child ran'); + st.end(); }); t.end(); }); @@ -24,22 +24,22 @@ var grandChildRan = false; test('grandparent', function (t) { t.ok(!grandParentRan, 'grand parent ran twice'); grandParentRan = true; - t.test('parent', function (t) { - t.ok(!parentRan, 'parent ran twice'); + t.test('parent', function (st) { + st.ok(!parentRan, 'parent ran twice'); parentRan = true; - t.test('grandchild', function (t) { - t.ok(!grandChildRan, 'grand child ran twice'); + st.test('grandchild', function (s2t) { + s2t.ok(!grandChildRan, 'grand child ran twice'); grandChildRan = true; - t.pass('grand child ran'); - t.end(); + s2t.pass('grand child ran'); + s2t.end(); }); - t.pass('parent ran'); - t.end(); + st.pass('parent ran'); + st.end(); }); - t.test('other parent', function (t) { - t.ok(parentRan, 'first parent runs before second parent'); - t.ok(grandChildRan, 'grandchild runs before second parent'); - t.end(); + t.test('other parent', function (st) { + st.ok(parentRan, 'first parent runs before second parent'); + st.ok(grandChildRan, 'grandchild runs before second parent'); + st.end(); }); t.pass('grandparent ran'); t.end(); diff --git a/test/nested2.js b/test/nested2.js index 130b9583..685fd15a 100644 --- a/test/nested2.js +++ b/test/nested2.js @@ -4,17 +4,17 @@ var test = require('../'); test(function (t) { var i = 0; - t.test('setup', function (t) { + t.test('setup', function (st) { process.nextTick(function () { - t.equal(i, 0, 'called once'); + st.equal(i, 0, 'called once'); i++; - t.end(); + st.end(); }); }); - t.test('teardown', function (t) { - t.end(); + t.test('teardown', function (st) { + st.end(); }); t.end(); diff --git a/test/objectMode.js b/test/objectMode.js index 0145a691..fd71d8cc 100644 --- a/test/objectMode.js +++ b/test/objectMode.js @@ -24,21 +24,21 @@ tap.test('object results', function (assert) { assert.equal(objects.length, 13); - forEach(objects, function (obj) { - if (obj.type === 'assert') { + forEach(objects, function (object) { + if (object.type === 'assert') { asserts++; - } else if (obj.type === 'test') { - testIds.push(obj.id); + } else if (object.type === 'test') { + testIds.push(object.id); - if (obj.skip) { + if (object.skip) { skips++; - } else if (obj.todo) { + } else if (object.todo) { todos++; } - } else if (obj.type === 'end') { - endIds.push(obj.text); + } else if (object.type === 'end') { + endIds.push(object.text); // test object should exist - assert.notEqual(testIds.indexOf(obj.test), -1); + assert.notEqual(testIds.indexOf(object.test), -1); } }); diff --git a/test/promises/subTests.js b/test/promises/subTests.js index a4a6b129..bb8d0d9b 100644 --- a/test/promises/subTests.js +++ b/test/promises/subTests.js @@ -4,14 +4,14 @@ var test = require('../../'); if (typeof Promise === 'function' && typeof Promise.resolve === 'function') { test('promise', function (t) { - t.test('sub test that should fail', function (t) { + t.test('sub test that should fail', function () { return new Promise(function (resolve, reject) { reject(new Error('rejection message')); }); }); - t.test('sub test that should pass', function (t) { - t.plan(1); - t.ok(true); + t.test('sub test that should pass', function (st) { + st.plan(1); + st.ok(true); }); }); } else { diff --git a/test/skip.js b/test/skip.js index 6682f048..7a1523de 100644 --- a/test/skip.js +++ b/test/skip.js @@ -44,9 +44,9 @@ test.skip('skip this too', function (t) { test('skip subtest', function (t) { ran++; - t.test('skip this', { skip: true }, function (t) { - t.fail('this should not even run'); - t.end(); + t.test('skip this', { skip: true }, function (st) { + st.fail('this should not even run'); + st.end(); }); t.end(); }); diff --git a/test/subcount.js b/test/subcount.js index 09cb1358..62b94746 100644 --- a/test/subcount.js +++ b/test/subcount.js @@ -4,13 +4,13 @@ var test = require('../'); test('parent test', function (t) { t.plan(2); - t.test('first child', function (t) { - t.plan(1); - t.pass('pass first child'); + t.test('first child', function (st) { + st.plan(1); + st.pass('pass first child'); }); - t.test(function (t) { - t.plan(1); - t.pass('pass second child'); + t.test(function (st) { + st.plan(1); + st.pass('pass second child'); }); }); diff --git a/test/subtest_plan.js b/test/subtest_plan.js index 9bab4730..b3063b96 100644 --- a/test/subtest_plan.js +++ b/test/subtest_plan.js @@ -9,15 +9,15 @@ test('parent', function (t) { t.pass('assertion in parent'); - t.test('first child', function (t) { - t.plan(1); - t.pass('pass first child'); + t.test('first child', function (st) { + st.plan(1); + st.pass('pass first child'); firstChildRan = true; }); - t.test('second child', function (t) { - t.plan(2); - t.ok(firstChildRan, 'first child ran first'); - t.pass('pass second child'); + t.test('second child', function (st) { + st.plan(2); + st.ok(firstChildRan, 'first child ran first'); + st.pass('pass second child'); }); }); diff --git a/test/throws.js b/test/throws.js index c0cb895d..e2a6d609 100644 --- a/test/throws.js +++ b/test/throws.js @@ -8,18 +8,6 @@ var assign = require('object.assign'); var stripFullStack = require('./common').stripFullStack; -function fn() { - throw new TypeError('RegExp'); -} - -function getNonFunctionMessage(fn) { - try { - fn(); - } catch (e) { - return e.message; - } -} - var getter = function () { return 'message'; }; var messageGetterError = Object.defineProperty( { custom: 'error' }, From be1eb212aeeec2c229208a4702ff99af0cabb5f7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 23 Jul 2021 23:59:35 -0700 Subject: [PATCH 08/18] [eslint] enable `no-multi-spaces`, `no-multiple-empty-lines`, `space-in-parens` --- .eslintrc | 1 + bin/tape | 2 +- test/async-await/async-bug.js | 1 - test/comment.js | 1 - test/create_multiple_streams.js | 5 ++--- test/exit.js | 2 +- test/nested2.js | 1 - 7 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 4a8fb4a0..88dc68e8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -47,6 +47,7 @@ "object-curly-spacing": ["error", "always"], "operator-linebreak": ["error", "before"], "semi-style": ["error", "last"], + "space-in-parens": ["error", "never"], "space-infix-ops": "error", "space-unary-ops": ["error", { "words": false, diff --git a/bin/tape b/bin/tape index 027fbb1b..35e1e791 100755 --- a/bin/tape +++ b/bin/tape @@ -25,7 +25,7 @@ if (typeof opts.require === 'string') { } opts.require.forEach(function (module) { - var options = { basedir: cwd, extensions: Object.keys(require.extensions) }; + var options = { basedir: cwd, extensions: Object.keys(require.extensions) }; if (module) { /* This check ensures we ignore `-r ""`, trailing `-r`, or * other silly things the user might (inadvertently) be doing. diff --git a/test/async-await/async-bug.js b/test/async-await/async-bug.js index 219db582..b9fde636 100644 --- a/test/async-await/async-bug.js +++ b/test/async-await/async-bug.js @@ -24,7 +24,6 @@ test('async-error', async function myTest(t) { t.end(); }); - function sleep(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); diff --git a/test/comment.js b/test/comment.js index c63395ac..b9933b53 100644 --- a/test/comment.js +++ b/test/comment.js @@ -64,7 +64,6 @@ tap.test('null argument', function (assert) { }); }); - // Exploratory test, how is whitespace treated? tap.test('whitespace', function (assert) { assert.plan(1); diff --git a/test/create_multiple_streams.js b/test/create_multiple_streams.js index 19cd5f9e..9307e881 100644 --- a/test/create_multiple_streams.js +++ b/test/create_multiple_streams.js @@ -13,7 +13,7 @@ tape.test('createMultipleStreams', function (tt) { th('test one', function (tht) { tht.plan(1); - setTimeout( function () { + setTimeout(function () { tht.pass(); testOneComplete = true; }, 100); @@ -26,8 +26,7 @@ tape.test('createMultipleStreams', function (tt) { th.onFinish(function () { tt.equal(th._results.count, 2, 'harness test ran'); - tt.equal(th._results.fail, 0, "harness test didn't fail"); + tt.equal(th._results.fail, 0, "harness test didn't fail"); }); }); - diff --git a/test/exit.js b/test/exit.js index d782b8f3..45c9df97 100644 --- a/test/exit.js +++ b/test/exit.js @@ -27,7 +27,7 @@ tap.test('exit ok', function (t) { '', '# ok', '', // yes, these double-blank-lines at the end are required. - '' // if you can figure out how to remove them, please do! + '' // if you can figure out how to remove them, please do! ].join('\n')); }; diff --git a/test/nested2.js b/test/nested2.js index 685fd15a..f167df61 100644 --- a/test/nested2.js +++ b/test/nested2.js @@ -12,7 +12,6 @@ test(function (t) { }); }); - t.test('teardown', function (st) { st.end(); }); From ae6de0c74a288f6d8bc83f45a7a686faf09ba9b1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 24 Jul 2021 09:13:16 -0700 Subject: [PATCH 09/18] [eslint] enable `function-paren-newline`, `function-call-argument-newline` --- .eslintrc | 2 ++ test/skip_explanation.js | 3 +- test/teardown.js | 6 ++-- test/todo_explanation.js | 70 +++++++++++++++++++--------------------- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/.eslintrc b/.eslintrc index 88dc68e8..9decf5e4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,6 +14,8 @@ "after": true, }], "curly": ["error", "all"], + "function-paren-newline": ["error", "multiline"], + "function-call-argument-newline": ["error", "consistent"], "indent": ["error", 4], "key-spacing": "error", "quotes": ["error", "single", { diff --git a/test/skip_explanation.js b/test/skip_explanation.js index 54c76883..8cdb383e 100644 --- a/test/skip_explanation.js +++ b/test/skip_explanation.js @@ -74,7 +74,8 @@ tap.test('test skip explanations', function (assert) { // var platform = process.platform; something like this needed var platform = 'win32'; - t.fail('run openssl', + t.fail( + 'run openssl', { skip: platform === 'win32' && 'Installer cannot work on windows\nand fails to add to PATH\n\n Err: (2401) denied' } ); t.end(); diff --git a/test/teardown.js b/test/teardown.js index b86da8ed..f8e4c5fc 100644 --- a/test/teardown.js +++ b/test/teardown.js @@ -124,14 +124,16 @@ tap.test('teardowns', function (tt) { ] : [ '# SKIP teardown is only ever called once, even when async', '# SKIP success (promise)' - ], [ + ], + [ '', '1..' + ((typeof Promise === 'function' ? 2 : 0) + 10 + v.nonFunctions.length), '# tests ' + ((typeof Promise === 'function' ? 2 : 0) + 10 + v.nonFunctions.length), '# pass ' + ((typeof Promise === 'function' ? 2 : 0) + 5), '# fail ' + (5 + v.nonFunctions.length), '' - ])); + ] + )); })); test('success', function (t) { diff --git a/test/todo_explanation.js b/test/todo_explanation.js index ce015826..162219f4 100644 --- a/test/todo_explanation.js +++ b/test/todo_explanation.js @@ -12,42 +12,40 @@ tap.test('tape todo test', { todo: process.versions.node.match(/0\.8\.\d+/) ? 'F assert.plan(1); test.createStream().pipe(concat(function (body) { - assert.deepEqual( - stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# success', - 'ok 1 this test runs', - '# TODO incomplete test1', - 'not ok 2 check output # TODO', - ' ---', - ' operator: equal', - ' expected: false', - ' actual: true', - ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', - ' ...', - 'not ok 3 check vars output # TODO name conflict', - ' ---', - ' operator: equal', - ' expected: 0', - ' actual: 1', - ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', - ' ...', - '# incomplete test2', - 'not ok 4 run openssl # TODO installer needs fix', - ' ---', - ' operator: fail', - ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', - ' ...', - '# TODO passing test', - '', - '1..4', - '# tests 4', - '# pass 4', - '', - '# ok', - '' - ] - ); + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# success', + 'ok 1 this test runs', + '# TODO incomplete test1', + 'not ok 2 check output # TODO', + ' ---', + ' operator: equal', + ' expected: false', + ' actual: true', + ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', + ' ...', + 'not ok 3 check vars output # TODO name conflict', + ' ---', + ' operator: equal', + ' expected: 0', + ' actual: 1', + ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', + ' ...', + '# incomplete test2', + 'not ok 4 run openssl # TODO installer needs fix', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', + ' ...', + '# TODO passing test', + '', + '1..4', + '# tests 4', + '# pass 4', + '', + '# ok', + '' + ]); })); test('success', function (t) { From 7dcbd7631a9ff5675f1ff0be477f0a1714b81dd3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 24 Jul 2021 13:28:55 -0700 Subject: [PATCH 10/18] [eslint] enable `wrap-regex` --- .eslintrc | 1 + lib/default_stream.js | 2 +- test/async-await.js | 18 +++++++++--------- test/ignore_from_gitignore.js | 2 +- test/promise_fail.js | 8 ++++---- test/stackTrace.js | 4 ++-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9decf5e4..1854a48b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -59,6 +59,7 @@ "wrap-iife": ["error", "outside", { "functionPrototypeMethods": true, }], + "wrap-regex": "error", }, "ignorePatterns": [ "syntax-error.*" ], "overrides": [ diff --git a/lib/default_stream.js b/lib/default_stream.js index 75458a9d..b750eab8 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -19,7 +19,7 @@ module.exports = function () { } function flush() { - if (fs.writeSync && /^win/.test(process.platform)) { + if (fs.writeSync && (/^win/).test(process.platform)) { try { fs.writeSync(1, line + '\n'); } catch (e) { stream.emit('error', e); } } else { diff --git a/test/async-await.js b/test/async-await.js index ef88ff01..b380dfaa 100644 --- a/test/async-await.js +++ b/test/async-await.js @@ -36,7 +36,7 @@ tap.test('async2', function (t) { runProgram('async-await', 'async2.js', function (r) { var stdout = r.stdout.toString('utf8'); var lines = stdout.split('\n').filter(function (line) { - return !/^(\s+)at(\s+)$/.test(line); + return !(/^(\s+)at(\s+)$/).test(line); }); t.same(stripFullStack(lines.join('\n')), [ @@ -184,9 +184,9 @@ tap.test('sync-error', function (t) { var stderr = r.stderr.toString('utf8'); var lines = stderr.split('\n'); lines = lines.filter(function (line) { - return !/\(timers.js:/.test(line) - && !/\(internal\/timers.js:/.test(line) - && !/Immediate\.next/.test(line); + return !(/\(timers.js:/).test(line) + && !(/\(internal\/timers.js:/).test(line) + && !(/Immediate\.next/).test(line); }); stderr = lines.join('\n'); @@ -211,7 +211,7 @@ tap.test('async-error', function (t) { var stdout = r.stdout.toString('utf8'); var lines = stdout.split('\n'); lines = lines.filter(function (line) { - return !/^(\s+)at(\s+)$/.test(line); + return !(/^(\s+)at(\s+)$/).test(line); }); stdout = lines.join('\n'); @@ -240,9 +240,9 @@ tap.test('async-error', function (t) { var stderr = r.stderr.toString('utf8'); var lines = stderr.split('\n'); lines = lines.filter(function (line) { - return !/\(timers.js:/.test(line) - && !/\(internal\/timers.js:/.test(line) - && !/Immediate\.next/.test(line); + return !(/\(timers.js:/).test(line) + && !(/\(internal\/timers.js:/).test(line) + && !(/Immediate\.next/).test(line); }); stderr = lines.join('\n'); @@ -256,7 +256,7 @@ tap.test('async-bug', function (t) { var stdout = r.stdout.toString('utf8'); var lines = stdout.split('\n'); lines = lines.filter(function (line) { - return !/^(\s+)at(\s+)$/.test(line); + return !(/^(\s+)at(\s+)$/).test(line); }); stdout = lines.join('\n'); diff --git a/test/ignore_from_gitignore.js b/test/ignore_from_gitignore.js index cda47b84..8260c2ec 100644 --- a/test/ignore_from_gitignore.js +++ b/test/ignore_from_gitignore.js @@ -110,7 +110,7 @@ tap.test('Should fail when ignore file does not exist', { skip: process.platform }; var testStderr = function (rows) { - tt.ok(/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m.test(stripFullStack(rows.toString('utf8')).join('\n'))); + tt.ok((/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m).test(stripFullStack(rows.toString('utf8')).join('\n'))); }; var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') }); diff --git a/test/promise_fail.js b/test/promise_fail.js index fc38fb75..a814917b 100644 --- a/test/promise_fail.js +++ b/test/promise_fail.js @@ -15,12 +15,12 @@ tap.test('callback returning rejected promise should cause that test (and only t ps.stdout.pipe(concat(function (rows) { var rowsString = rows.toString('utf8'); - if (/^skip\n$/.test(rowsString)) { + if ((/^skip\n$/).test(rowsString)) { return tt.pass('the test file indicated it should be skipped'); } var strippedString = stripFullStack(rowsString).filter(function (line) { - return !/^(\s+)at(\s+)(?:Test\.)?(?:$|\s)/.test(line); + return !(/^(\s+)at(\s+)(?:Test\.)?(?:$|\s)/).test(line); }).join('\n'); // hack for consistency across all versions of node @@ -63,12 +63,12 @@ tap.test('subtest callback returning rejected promise should cause that subtest ps.stdout.pipe(concat(function (rows) { var rowsString = rows.toString('utf8'); - if (/^skip\n$/.test(rowsString)) { + if ((/^skip\n$/).test(rowsString)) { return tt.pass('the test file indicated it should be skipped'); } var strippedString = stripFullStack(rowsString).filter(function (line) { - return !/^(\s+)at(\s+)(?:Test\.)?(?:$|\s)/.test(line); + return !(/^(\s+)at(\s+)(?:Test\.)?(?:$|\s)/).test(line); }).join('\n'); // hack for consistency across all versions of node diff --git a/test/stackTrace.js b/test/stackTrace.js index 7906884f..fd3fedfd 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -171,7 +171,7 @@ tap.test('preserves stack trace for failed assertions', function (tt) { tt.equal(typeof data.diag.stack, 'string'); var at = data.diag.at || ''; stack = data.diag.stack || ''; - tt.ok(/^Error: true should be false(\n at .+)+/.exec(stack), 'stack should be a stack'); + tt.ok((/^Error: true should be false(\n at .+)+/).exec(stack), 'stack should be a stack'); tt.deepEqual(data, { ok: false, id: 1, @@ -236,7 +236,7 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun tt.equal(typeof data.diag.stack, 'string'); var at = data.diag.at || ''; stack = data.diag.stack || ''; - tt.ok(/^Error: false should be true(\n at .+)+/.exec(stack), 'stack should be a stack'); + tt.ok((/^Error: false should be true(\n at .+)+/).exec(stack), 'stack should be a stack'); tt.deepEqual(data, { ok: false, id: 1, From a08dc34371a8dc406581fb85edb591150f9c0f35 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 09:29:26 -0700 Subject: [PATCH 11/18] [eslint] enable `no-extra-parens` --- .eslintrc | 9 +++++++++ lib/results.js | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 1854a48b..9c181942 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,6 +26,15 @@ "anonymous": "always", "named": "never", }], + "no-extra-parens": ["error", "all", { + "conditionalAssign": false, + "nestedBinaryExpressions": false, + "returnAssign": false, + "ignoreJSX": "all", + "enforceForArrowConditionals": false, + "enforceForSequenceExpressions": true, + "enforceForNewInMemberExpressions": false, + }], "no-extra-semi": "error", "no-shadow": ["error", { "builtinGlobals": false, diff --git a/lib/results.js b/lib/results.js index eac95bb8..92258b03 100644 --- a/lib/results.js +++ b/lib/results.js @@ -164,9 +164,9 @@ function encodeResult(res, count) { output += res.name ? ' ' + coalesceWhiteSpaces(res.name) : ''; if (res.skip) { - output += ' # SKIP' + ((typeof res.skip === 'string') ? ' ' + coalesceWhiteSpaces(res.skip) : ''); + output += ' # SKIP' + (typeof res.skip === 'string' ? ' ' + coalesceWhiteSpaces(res.skip) : ''); } else if (res.todo) { - output += ' # TODO' + ((typeof res.todo === 'string') ? ' ' + coalesceWhiteSpaces(res.todo) : ''); + output += ' # TODO' + (typeof res.todo === 'string' ? ' ' + coalesceWhiteSpaces(res.todo) : ''); } output += '\n'; From 06eba07d6b73ba2650f581372fd613f89385993c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 11:35:15 -0700 Subject: [PATCH 12/18] [eslint] enable `brace-style` --- .eslintrc | 3 +++ lib/default_stream.js | 21 +++++++++++++++------ test/double_end.js | 3 +-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9c181942..235361f5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,6 +8,9 @@ "Promise": false, }, "rules": { + "brace-style": ["error", "1tbs", { + "allowSingleLine": true, + }], "comma-dangle": ["error", "never"], "comma-spacing": [2, { "before": false, diff --git a/lib/default_stream.js b/lib/default_stream.js index b750eab8..4647d93b 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -13,18 +13,27 @@ module.exports = function () { var c = typeof buf === 'string' ? buf.charAt(i) : String.fromCharCode(buf[i]); - if (c === '\n') { flush(); } - else { line += c; } + if (c === '\n') { + flush(); + } else { + line += c; + } } } function flush() { if (fs.writeSync && (/^win/).test(process.platform)) { - try { fs.writeSync(1, line + '\n'); } - catch (e) { stream.emit('error', e); } + try { + fs.writeSync(1, line + '\n'); + } catch (e) { + stream.emit('error', e); + } } else { - try { console.log(line); } - catch (e) { stream.emit('error', e); } + try { + console.log(line); + } catch (e) { + stream.emit('error', e); + } } line = ''; } diff --git a/test/double_end.js b/test/double_end.js index af630cae..a3445ab6 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -29,8 +29,7 @@ test(function (tt) { var atExpected; try { to._onTimeout(); - } - catch (e) { + } catch (e) { stackExpected = stripFullStack(e.stack)[1]; stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js'); stackExpected = stackExpected.trim(); From 771f3ddd1a3ad3a629c1d1a0780052d51143435b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 11:55:12 -0700 Subject: [PATCH 13/18] [eslint] enable `no-lonely-if` --- test/end-as-callback.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test/end-as-callback.js b/test/end-as-callback.js index d7062022..d3cb1fc9 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -75,14 +75,11 @@ function getStackTrace(rows) { if (row.indexOf('---') > -1) { // start of stack trace extract = true; } + } else if (row.indexOf('...') > -1) { // end of stack trace + extract = false; + stacktrace += ' ...'; } else { - if (row.indexOf('...') > -1) { // end of stack trace - extract = false; - stacktrace += ' ...'; - } else { - stacktrace += row + '\n'; - } - + stacktrace += row + '\n'; } }); // console.log(stacktrace); From 2ebd23a03c71d14890dc064b29526e3d523daf93 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 12:13:46 -0700 Subject: [PATCH 14/18] [eslint] enable `no-unused-vars` --- .eslintrc | 4 ++++ index.js | 2 ++ lib/test.js | 2 ++ test/import.js | 5 ++--- test/promises/fail.js | 2 +- test/require.js | 3 +-- test/skip.js | 4 ---- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.eslintrc b/.eslintrc index 235361f5..429f72f2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -45,6 +45,10 @@ "allow": [] }], "no-undef": "error", + "no-unused-vars": ["error", { + "vars": "all", + "args": "after-used" + }], "no-useless-escape": "error", "object-curly-newline": ["error", { "ObjectExpression": { diff --git a/index.js b/index.js index 10200482..386e16b6 100644 --- a/index.js +++ b/index.js @@ -107,6 +107,8 @@ function createExitHarness(conf, wait) { var stream = harness.createStream({ objectMode: config.objectMode }); var es = stream.pipe(config.stream || createDefaultStream()); if (canEmitExit) { + // TODO: use `err` arg? + // eslint-disable-next-line no-unused-vars es.on('error', function (err) { harness._exitCode = 1; }); } stream.on('end', function () { ended = true; }); diff --git a/lib/test.js b/lib/test.js index 71325f52..31275195 100644 --- a/lib/test.js +++ b/lib/test.js @@ -33,6 +33,7 @@ var safeClearTimeout = clearTimeout; inherits(Test, EventEmitter); +// eslint-disable-next-line no-unused-vars var getTestArgs = function (name_, opts_, cb_) { var name = '(anonymous)'; var opts = {}; @@ -744,6 +745,7 @@ Test.prototype.doesNotMatch = function doesNotMatch(string, regexp, msg, extra) }); }; +// eslint-disable-next-line no-unused-vars Test.skip = function skip(name_, _opts, _cb) { var args = getTestArgs.apply(null, arguments); args.opts.skip = true; diff --git a/test/import.js b/test/import.js index b76e5bc9..e2581e75 100644 --- a/test/import.js +++ b/test/import.js @@ -92,7 +92,7 @@ tap.test('errors importing test files', function (t) { var message = options.error + ' in `' + options.mode + '` mode`'; var ps = tape(options.files, { env: { NODE_OPTIONS: '--unhandled-rejections=' + options.mode } }); ps.stderr.pipe(concat(options.unhandledRejection(message))); - ps.on('exit', function (code, sig) { + ps.on('exit', function (code/* , sig */) { t.equal(code, options.exitCode, message + ' has exit code ' + options.exitCode); }); }; @@ -191,8 +191,7 @@ tap.test('errors importing test files', function (t) { function tape(args, options) { options = assign({ cwd: __dirname }, options); - var proc = require('child_process'); var bin = __dirname + '/../bin/tape'; - return proc.spawn('node', [bin].concat(args.split(' ')), options); + return spawn('node', [bin].concat(args.split(' ')), options); } diff --git a/test/promises/fail.js b/test/promises/fail.js index 6ffb3f8d..5047c0b9 100644 --- a/test/promises/fail.js +++ b/test/promises/fail.js @@ -3,7 +3,7 @@ var test = require('../../'); if (typeof Promise === 'function' && typeof Promise.resolve === 'function') { - test('promise', function (t) { + test('promise', function () { return new Promise(function (resolve, reject) { reject(new Error('rejection message')); }); diff --git a/test/require.js b/test/require.js index d0c7c813..14014cdd 100644 --- a/test/require.js +++ b/test/require.js @@ -64,8 +64,7 @@ tap.test('requiring multiple modules', function (t) { }); function tape(args) { - var proc = require('child_process'); var bin = __dirname + '/../bin/tape'; - return proc.spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname }); + return spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname }); } diff --git a/test/skip.js b/test/skip.js index 7a1523de..d0843599 100644 --- a/test/skip.js +++ b/test/skip.js @@ -1,7 +1,6 @@ 'use strict'; var test = require('../'); -var ran = 0; var concat = require('concat-stream'); var tap = require('tap'); @@ -32,18 +31,15 @@ tap.test('test SKIP comment', function (assert) { test('skip this', { skip: true }, function (t) { t.fail('this should not even run'); - ran++; t.end(); }); test.skip('skip this too', function (t) { t.fail('this should not even run'); - ran++; t.end(); }); test('skip subtest', function (t) { - ran++; t.test('skip this', { skip: true }, function (st) { st.fail('this should not even run'); st.end(); From ef0069a9de38c89cb4b4117ffa165e7f0c6a6351 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 12:16:26 -0700 Subject: [PATCH 15/18] [eslint] enable `no-regex-spaces` --- test/stackTrace.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/stackTrace.js b/test/stackTrace.js index fd3fedfd..18616ba0 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -171,7 +171,7 @@ tap.test('preserves stack trace for failed assertions', function (tt) { tt.equal(typeof data.diag.stack, 'string'); var at = data.diag.at || ''; stack = data.diag.stack || ''; - tt.ok((/^Error: true should be false(\n at .+)+/).exec(stack), 'stack should be a stack'); + tt.ok((/^Error: true should be false(\n {4}at .+)+/).exec(stack), 'stack should be a stack'); tt.deepEqual(data, { ok: false, id: 1, @@ -236,7 +236,7 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun tt.equal(typeof data.diag.stack, 'string'); var at = data.diag.at || ''; stack = data.diag.stack || ''; - tt.ok((/^Error: false should be true(\n at .+)+/).exec(stack), 'stack should be a stack'); + tt.ok((/^Error: false should be true(\n {4}at .+)+/).exec(stack), 'stack should be a stack'); tt.deepEqual(data, { ok: false, id: 1, From b03d4c8e722841d580a581a5d492277a7c701f94 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 12:28:52 -0700 Subject: [PATCH 16/18] [eslint] update `no-redeclare` --- test/async-await.js | 6 ++---- test/stackTrace.js | 21 +++++++++------------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/test/async-await.js b/test/async-await.js index b380dfaa..b34a0499 100644 --- a/test/async-await.js +++ b/test/async-await.js @@ -238,15 +238,13 @@ tap.test('async-error', function (t) { t.same(r.exitCode, 1); var stderr = r.stderr.toString('utf8'); - var lines = stderr.split('\n'); - lines = lines.filter(function (line) { + var stderrLines = stderr.split('\n').filter(function (line) { return !(/\(timers.js:/).test(line) && !(/\(internal\/timers.js:/).test(line) && !(/Immediate\.next/).test(line); }); - stderr = lines.join('\n'); - t.same(stderr, ''); + t.same(stderrLines.join('\n'), ''); t.end(); }); }); diff --git a/test/stackTrace.js b/test/stackTrace.js index 18616ba0..e517077a 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -28,10 +28,9 @@ tap.test('preserves stack trace with newlines', function (tt) { }); stream.pipe(concat(function (body) { - var body = body.toString('utf8'); - body = stripAt(body); + var strippedBody = stripAt(body.toString('utf8')); tt.equal( - body, + strippedBody, 'TAP version 13\n' + '# multiline stack trace\n' + 'not ok 1 Error: Preserve stack\n' @@ -48,7 +47,7 @@ tap.test('preserves stack trace with newlines', function (tt) { + '# fail 1\n' ); - tt.deepEqual(getDiag(body), { + tt.deepEqual(getDiag(strippedBody), { stack: stackTrace, operator: 'error' }); @@ -187,10 +186,9 @@ tap.test('preserves stack trace for failed assertions', function (tt) { }); stream.pipe(concat(function (body) { - var body = body.toString('utf8'); - body = stripAt(body); + var strippedBody = stripAt(body.toString('utf8')); tt.equal( - body, + strippedBody, 'TAP version 13\n' + '# t.equal stack trace\n' + 'not ok 1 true should be false\n' @@ -209,7 +207,7 @@ tap.test('preserves stack trace for failed assertions', function (tt) { + '# fail 1\n' ); - tt.deepEqual(getDiag(body), { + tt.deepEqual(getDiag(strippedBody), { stack: stack, operator: 'equal', expected: false, @@ -252,10 +250,9 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun }); stream.pipe(concat(function (body) { - var body = body.toString('utf8'); - body = stripAt(body); + var strippedBody = stripAt(body.toString('utf8')); tt.equal( - body, + strippedBody, 'TAP version 13\n' + '# t.equal stack trace\n' + 'not ok 1 false should be true\n' @@ -274,7 +271,7 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun + '# fail 1\n' ); - tt.deepEqual(getDiag(body), { + tt.deepEqual(getDiag(strippedBody), { stack: stack, operator: 'equal', expected: true, From fb4e3cfc4df1f932496fbca35c013f6ad65df53b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 14:00:47 -0700 Subject: [PATCH 17/18] [eslint] enable `consistent-return` --- .eslintrc | 1 + bin/import-or-require.js | 3 ++- lib/results.js | 8 +++++--- lib/test.js | 3 ++- test/promise_fail.js | 6 ++++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index 429f72f2..bb86a337 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,6 +16,7 @@ "before": false, "after": true, }], + "consistent-return": "error", "curly": ["error", "all"], "function-paren-newline": ["error", "multiline"], "function-call-argument-newline": ["error", "consistent"], diff --git a/bin/import-or-require.js b/bin/import-or-require.js index 8b72edd3..e2aa6b45 100644 --- a/bin/import-or-require.js +++ b/bin/import-or-require.js @@ -3,7 +3,8 @@ const { extname: extnamePath } = require('path'); const getPackageType = require('get-package-type'); -module.exports = function (file) { +// eslint-disable-next-line consistent-return +module.exports = function importOrRequire(file) { const ext = extnamePath(file); if (ext === '.mjs' || (ext === '.js' && getPackageType.sync(file) === 'module')) { diff --git a/lib/results.js b/lib/results.js index 92258b03..fc8b42e3 100644 --- a/lib/results.js +++ b/lib/results.js @@ -86,7 +86,8 @@ Results.prototype.createStream = function (opts) { while (t = getNextTest(self)) { t.run(); if (!t.ended) { - return t.once('end', function () { nextTick(next); }); + t.once('end', function () { nextTick(next); }); + return; } } self.emit('done'); @@ -215,11 +216,12 @@ function getNextTest(results) { do { var t = $shift(results.tests); - if (!t) { continue; } - if (results._only === t) { + if (t && results._only === t) { return t; } } while (results.tests.length !== 0); + + return void undefined; } function invalidYaml(str) { diff --git a/lib/test.js b/lib/test.js index 31275195..abdc2e10 100644 --- a/lib/test.js +++ b/lib/test.js @@ -104,7 +104,8 @@ function Test(name_, opts_, cb_) { Test.prototype.run = function run() { this.emit('prerun'); if (!this._cb || this._skip) { - return this._end(); + this._end(); + return; } if (this._timeout != null) { this.timeoutAfter(this._timeout); diff --git a/test/promise_fail.js b/test/promise_fail.js index a814917b..f45019da 100644 --- a/test/promise_fail.js +++ b/test/promise_fail.js @@ -16,7 +16,8 @@ tap.test('callback returning rejected promise should cause that test (and only t var rowsString = rows.toString('utf8'); if ((/^skip\n$/).test(rowsString)) { - return tt.pass('the test file indicated it should be skipped'); + tt.pass('the test file indicated it should be skipped'); + return; } var strippedString = stripFullStack(rowsString).filter(function (line) { @@ -64,7 +65,8 @@ tap.test('subtest callback returning rejected promise should cause that subtest var rowsString = rows.toString('utf8'); if ((/^skip\n$/).test(rowsString)) { - return tt.pass('the test file indicated it should be skipped'); + tt.pass('the test file indicated it should be skipped'); + return; } var strippedString = stripFullStack(rowsString).filter(function (line) { From ae8b5c0639be6c3b2fd0b2e132ca50ee9f760e94 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 23 Jul 2021 23:57:20 -0700 Subject: [PATCH 18/18] [eslint] fully enable `@ljharb` eslint config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s time. --- .eslintrc | 151 ++++++++++++++++++-------------- index.js | 8 +- lib/default_stream.js | 2 +- lib/results.js | 3 +- lib/test.js | 3 + test/async-await.js | 2 +- test/async-await/async-error.js | 1 + test/async-await/sync-error.js | 1 + test/deep-equal-failure.js | 21 +++-- test/import.js | 4 +- test/max_listeners/source.js | 5 +- test/not-deep-equal-failure.js | 21 +++-- test/not-equal-failure.js | 7 +- test/onFailure.js | 3 +- test/stackTrace.js | 7 +- 15 files changed, 135 insertions(+), 104 deletions(-) diff --git a/.eslintrc b/.eslintrc index bb86a337..0403f3b8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,79 +4,27 @@ "browser": true, "node": true, }, + "extends": "@ljharb", "globals": { "Promise": false, }, "rules": { - "brace-style": ["error", "1tbs", { - "allowSingleLine": true, - }], - "comma-dangle": ["error", "never"], - "comma-spacing": [2, { - "before": false, - "after": true, - }], - "consistent-return": "error", - "curly": ["error", "all"], - "function-paren-newline": ["error", "multiline"], - "function-call-argument-newline": ["error", "consistent"], + "array-bracket-spacing": "off", + "complexity": "off", + "eqeqeq": ["error", "always", { "null": "ignore" }], + "func-style": "warn", "indent": ["error", 4], - "key-spacing": "error", - "quotes": ["error", "single", { - "avoidEscape": true, - }], - "semi": ["error", "always"], - "space-before-function-paren": ["error", { - "anonymous": "always", - "named": "never", - }], - "no-extra-parens": ["error", "all", { - "conditionalAssign": false, - "nestedBinaryExpressions": false, - "returnAssign": false, - "ignoreJSX": "all", - "enforceForArrowConditionals": false, - "enforceForSequenceExpressions": true, - "enforceForNewInMemberExpressions": false, - }], - "no-extra-semi": "error", - "no-shadow": ["error", { - "builtinGlobals": false, - "hoist": "functions", - "allow": [] - }], - "no-undef": "error", - "no-unused-vars": ["error", { - "vars": "all", - "args": "after-used" - }], - "no-useless-escape": "error", - "object-curly-newline": ["error", { - "ObjectExpression": { - "multiline": true, - "consistent": true, - "minProperties": 3, - }, - "ObjectPattern": { - "multiline": true, - "consistent": true, - "minProperties": 3, - }, - }], - "object-curly-spacing": ["error", "always"], + "no-magic-numbers": "off", + "max-lines": "warn", + "max-lines-per-function": "warn", + "max-statements": "warn", + "max-statements-per-line": [2, { "max": 2 }], + "multiline-comment-style": "off", + "no-negated-condition": "off", + "no-use-before-define": "warn", + "no-underscore-dangle": "warn", "operator-linebreak": ["error", "before"], - "semi-style": ["error", "last"], - "space-in-parens": ["error", "never"], - "space-infix-ops": "error", - "space-unary-ops": ["error", { - "words": false, - "nonwords": false, - }], - "strict": "error", - "wrap-iife": ["error", "outside", { - "functionPrototypeMethods": true, - }], - "wrap-regex": "error", + "sort-keys": "warn", }, "ignorePatterns": [ "syntax-error.*" ], "overrides": [ @@ -84,12 +32,50 @@ "files": ["*.mjs", "test/import/package_type/*.js"], "extends": "@ljharb/eslint-config/esm", }, + { + "files": ["bin/**"], + "rules": { + "global-require": "off", + "no-process-exit": "off", + "quote-props": ["error", "as-needed", { + "keywords": false, + }], + }, + }, { "files": ["bin/import-or-require.js"], "parserOptions": { "ecmaVersion": 2020, }, }, + { + "files": ["index.js"], + "rules": { + "no-param-reassign": "warn", + }, + }, + { + "files": ["lib/results.js"], + "rules": { + "no-cond-assign": "warn", + "no-param-reassign": "warn", + "no-plusplus": "warn", + }, + }, + { + "files": ["lib/test.js"], + "rules": { + "eqeqeq": "warn", + "func-name-matching": "off", + "max-params": "off", + "no-continue": "off", + "no-invalid-this": "off", + "no-param-reassign": "warn", + "no-plusplus": "warn", + "no-multi-assign": "off", + "no-restricted-syntax": "off", + }, + }, { "files": ["test/async-await/*"], "parserOptions": { @@ -101,6 +87,37 @@ "globals": { "g": false, }, + "rules": { + "no-new-func": "off", + }, + }, + { + "files": ["example/**"], + "rules": { + "array-bracket-newline": "off", + "global-require": "off", + "no-console": "off", + }, + }, + { + "files": ["test/**"], + "rules": { + "dot-notation": [2, { + "allowKeywords": true, + "allowPattern": "throws" + }], + "id-length": "off", + "max-len": "off", + "max-lines-per-function": "off", + "no-plusplus": "off", + "no-throw-literal": "off", + }, + }, + { + "files": ["test/*/**"], + "rules": { + "camelcase": "off", + }, }, ], } diff --git a/index.js b/index.js index 386e16b6..04abc529 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,7 @@ module.exports = (function () { var wait = false; var harness; var lazyLoad = function () { + // eslint-disable-next-line no-invalid-this return getHarness().apply(this, arguments); }; @@ -89,14 +90,15 @@ function createExitHarness(conf, wait) { var only = harness._results._only; for (var i = 0; i < harness._tests.length; i++) { var t = harness._tests[i]; - if (only && t !== only) { continue; } - t._exit(); + if (!only || t === only) { + t._exit(); + } } } harness.close(); process.removeAllListeners('exit'); // necessary for node v0.6 - process.exit(code || harness._exitCode); + process.exit(code || harness._exitCode); // eslint-disable-line no-process-exit }); return harness; diff --git a/lib/default_stream.js b/lib/default_stream.js index 4647d93b..9e6372ec 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -30,7 +30,7 @@ module.exports = function () { } } else { try { - console.log(line); + console.log(line); // eslint-disable-line no-console } catch (e) { stream.emit('error', e); } diff --git a/lib/results.js b/lib/results.js index fc8b42e3..89ae72fc 100644 --- a/lib/results.js +++ b/lib/results.js @@ -39,7 +39,8 @@ function Results() { Results.prototype.createStream = function (opts) { if (!opts) { opts = {}; } var self = this; - var output, testId = 0; + var output; + var testId = 0; if (opts.objectMode) { output = through(); self.on('_push', function ontest(t, extra) { diff --git a/lib/test.js b/lib/test.js index abdc2e10..117a8e98 100644 --- a/lib/test.js +++ b/lib/test.js @@ -101,6 +101,7 @@ function Test(name_, opts_, cb_) { } } +// eslint-disable-next-line consistent-return Test.prototype.run = function run() { this.emit('prerun'); if (!this._cb || this._skip) { @@ -131,6 +132,7 @@ Test.prototype.run = function run() { } self.end(); }); + // eslint-disable-next-line consistent-return return; } @@ -232,6 +234,7 @@ Test.prototype._end = function _end(err) { } if (res && typeof res.then === 'function') { res.then(next, function (_err) { + // TODO: wth? err = err || _err; }); } else { diff --git a/test/async-await.js b/test/async-await.js index b34a0499..8a6a3ebc 100644 --- a/test/async-await.js +++ b/test/async-await.js @@ -9,7 +9,7 @@ var nodeVersion = process.versions.node; var majorVersion = nodeVersion.split('.')[0]; if (Number(majorVersion) < 8) { - process.exit(0); + process.exit(0); // eslint-disable-line no-process-exit } tap.test('async1', function (t) { diff --git a/test/async-await/async-error.js b/test/async-await/async-error.js index 35fc27a2..ae02da57 100644 --- a/test/async-await/async-error.js +++ b/test/async-await/async-error.js @@ -5,5 +5,6 @@ var test = require('../../'); test('async-error', async function myTest(t) { t.ok(true, 'before throw'); throw new Error('oopsie'); + /* eslint no-unreachable: 0 */ t.ok(true, 'after throw'); }); diff --git a/test/async-await/sync-error.js b/test/async-await/sync-error.js index 989f4f7f..f2d825cc 100644 --- a/test/async-await/sync-error.js +++ b/test/async-await/sync-error.js @@ -5,6 +5,7 @@ var test = require('../../'); test('sync-error', function myTest(t) { t.ok(true, 'before throw'); throw new Error('oopsie'); + /* eslint no-unreachable: 0 */ t.ok(true, 'after throw'); t.end(); }); diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index 80216ff1..dfdff536 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -50,8 +50,6 @@ tap.test('deep equal failure', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -59,7 +57,10 @@ tap.test('deep equal failure', function (assert) { diag: { operator: 'equal', expected: '{ b: 2 }', - actual: '{ a: 1 }' + actual: '{ a: 1 }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); @@ -111,8 +112,6 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -120,7 +119,10 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { diag: { operator: 'equal', expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); @@ -172,8 +174,6 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -181,7 +181,10 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { diag: { operator: 'equal', expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); diff --git a/test/import.js b/test/import.js index e2581e75..f4072326 100644 --- a/test/import.js +++ b/test/import.js @@ -189,9 +189,7 @@ tap.test('errors importing test files', function (t) { }); function tape(args, options) { - options = assign({ cwd: __dirname }, options); - var bin = __dirname + '/../bin/tape'; - return spawn('node', [bin].concat(args.split(' ')), options); + return spawn('node', [bin].concat(args.split(' ')), assign({ cwd: __dirname }, options)); } diff --git a/test/max_listeners/source.js b/test/max_listeners/source.js index e801853e..137f8a1c 100644 --- a/test/max_listeners/source.js +++ b/test/max_listeners/source.js @@ -3,5 +3,8 @@ var test = require('../../'); for (var i = 0; i < 11; i++) { - test(function (t) { t.ok(true, 'true is truthy'); t.end(); }); + test(function (t) { + t.ok(true, 'true is truthy'); + t.end(); + }); } diff --git a/test/not-deep-equal-failure.js b/test/not-deep-equal-failure.js index c90453dc..d02ab0ef 100644 --- a/test/not-deep-equal-failure.js +++ b/test/not-deep-equal-failure.js @@ -50,8 +50,6 @@ tap.test('deep equal failure', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -59,7 +57,10 @@ tap.test('deep equal failure', function (assert) { diag: { operator: 'notDeepEqual', expected: '{ b: 2 }', - actual: '{ b: 2 }' + actual: '{ b: 2 }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); @@ -111,8 +112,6 @@ tap.test('not deep equal failure, depth 6, with option', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -120,7 +119,10 @@ tap.test('not deep equal failure, depth 6, with option', function (assert) { diag: { operator: 'notDeepEqual', expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); @@ -172,8 +174,6 @@ tap.test('not deep equal failure, depth 6, without option', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -181,7 +181,10 @@ tap.test('not deep equal failure, depth 6, without option', function (assert) { diag: { operator: 'notDeepEqual', expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); diff --git a/test/not-equal-failure.js b/test/not-equal-failure.js index 4cf11f02..87a66453 100644 --- a/test/not-equal-failure.js +++ b/test/not-equal-failure.js @@ -48,8 +48,6 @@ tap.test('not equal failure', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -57,7 +55,10 @@ tap.test('not equal failure', function (assert) { diag: { operator: 'notEqual', expected: '2', - actual: '2' + actual: '2', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); diff --git a/test/onFailure.js b/test/onFailure.js index 8420a822..5eb05142 100644 --- a/test/onFailure.js +++ b/test/onFailure.js @@ -3,8 +3,7 @@ var tap = require('tap'); var tape = require('../').createHarness(); -//Because this test passing depends on a failure, -//we must direct the failing output of the inner test +// Because this test passing depends on a failure, we must direct the failing output of the inner test var noop = function () {}; var mockSink = { on: noop, diff --git a/test/stackTrace.js b/test/stackTrace.js index e517077a..99afa1bf 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -15,14 +15,14 @@ tap.test('preserves stack trace with newlines', function (tt) { var stackTrace = 'foo\n bar'; parser.once('assert', function (data) { - delete data.diag.at; tt.deepEqual(data, { ok: false, id: 1, name: 'Error: Preserve stack', diag: { stack: stackTrace, - operator: 'error' + operator: 'error', + at: data.diag.at // we don't care about this one } }); }); @@ -292,8 +292,7 @@ function getDiag(body) { return line.slice(2); }).join('\n'); - // Get rid of 'at' variable (which has a line number / path of its own that's - // difficult to check). + // Get rid of 'at' variable (which has a line number / path of its own that's difficult to check). var withStack = yaml.safeLoad(diag); delete withStack.at; return withStack;