diff --git a/.eslintrc b/.eslintrc index d4840579..0403f3b8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,29 +4,27 @@ "browser": true, "node": true, }, + "extends": "@ljharb", "globals": { "Promise": false, }, "rules": { - "comma-dangle": ["error", "never"], + "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-undef": "error", - "no-useless-escape": "error", + "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"], - "space-unary-ops": ["error", { - "words": false, - "nonwords": false, - }], - "strict": "error", + "sort-keys": "warn", }, "ignorePatterns": [ "syntax-error.*" ], "overrides": [ @@ -34,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": { @@ -51,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/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/bin/tape b/bin/tape index a912c087..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. @@ -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/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/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/index.js b/index.js index 0e9bb5a2..04abc529 100644 --- a/index.js +++ b/index.js @@ -7,16 +7,15 @@ 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; var harness; var lazyLoad = function () { + // eslint-disable-next-line no-invalid-this return getHarness().apply(this, arguments); }; @@ -27,7 +26,7 @@ module.exports = (function () { lazyLoad.run = function () { var run = getHarness().run; - if (run) run(); + if (run) { run(); } }; lazyLoad.only = function () { @@ -57,12 +56,12 @@ 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; } -})(); +}()); function createExitHarness(conf, wait) { var config = conf || {}; @@ -78,8 +77,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. @@ -91,28 +90,31 @@ 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; function run() { - if (running) return; + if (running) { return; } running = true; 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; }); - }; + } } module.exports.createHarness = createHarness; @@ -135,9 +137,9 @@ 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); + }(t)); results.push(t); return t; @@ -160,7 +162,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 f8901ed4..9e6372ec 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -12,20 +12,28 @@ module.exports = function () { for (var i = 0; i < buf.length; i++) { var c = typeof buf === 'string' ? buf.charAt(i) - : String.fromCharCode(buf[i]) - ; - if (c === '\n') flush(); - else line += c; + : String.fromCharCode(buf[i]); + 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); } + if (fs.writeSync && (/^win/).test(process.platform)) { + 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); // eslint-disable-line no-console + } catch (e) { + stream.emit('error', e); + } } line = ''; } diff --git a/lib/results.js b/lib/results.js index 37bb1917..89ae72fc 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); @@ -27,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; @@ -39,13 +37,14 @@ function Results() { } Results.prototype.createStream = function (opts) { - if (!opts) 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) { - if (!extra) extra = {}; + if (!extra) { extra = {}; } var id = testId++; t.once('prerun', function () { var row = { @@ -87,7 +86,10 @@ 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) { + t.once('end', function () { nextTick(next); }); + return; + } } self.emit('done'); }); @@ -112,8 +114,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'); }); @@ -125,8 +130,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'); } @@ -137,16 +143,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); }; @@ -157,13 +166,13 @@ 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'; - if (res.ok) return output; + if (res.ok) { return output; } var outer = ' '; var inner = outer + ' '; @@ -171,8 +180,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'; @@ -208,11 +217,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 ed005cb6..117a8e98 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 = {}; @@ -49,7 +50,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_) { @@ -92,14 +97,16 @@ function Test(name_, opts_, cb_) { }; } return val; - })(this, this[prop]); + }(this, this[prop])); } } +// eslint-disable-next-line consistent-return 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); @@ -125,6 +132,7 @@ Test.prototype.run = function run() { } self.end(); }); + // eslint-disable-next-line consistent-return return; } @@ -167,7 +175,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 +209,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); @@ -224,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 { @@ -234,7 +245,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 +374,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; @@ -417,7 +428,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', @@ -425,11 +436,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, { @@ -738,6 +749,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/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/async-await.js b/test/async-await.js index ef88ff01..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) { @@ -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'); @@ -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) { - return !/\(timers.js:/.test(line) - && !/\(internal\/timers.js:/.test(line) - && !/Immediate\.next/.test(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(); }); }); @@ -256,7 +254,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/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/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/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/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/browser/asserts.js b/test/browser/asserts.js index 77611f56..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.deepEqual([1,2,[3,4]], [1,2,[3,4]]); - t.notDeepEqual([1,2,[3,4,5]], [1,2,[3,4]]); + 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/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/comment.js b/test/comment.js index 378db5a8..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); @@ -132,7 +131,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/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/deep-equal-failure.js b/test/deep-equal-failure.js index d5f1bc74..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,14 +57,17 @@ 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 } }); }); test('deep equal', function (t) { t.plan(1); - t.equal({a: 1}, {b: 2}); + t.equal({ a: 1 }, { b: 2 }); }); }); @@ -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,12 +119,15 @@ 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 } }); }); - 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 } } } } } }); }); @@ -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/double_end.js b/test/double_end.js index 23d6dc7c..a3445ab6 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; @@ -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(); 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); 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/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/ignore_from_gitignore.js b/test/ignore_from_gitignore.js index d95260b8..8260c2ec 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); @@ -110,10 +110,10 @@ 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')}); + 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/import.js b/test/import.js index b76e5bc9..f4072326 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); }); }; @@ -189,10 +189,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(' ')), 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/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/nested2.js b/test/nested2.js index 130b9583..f167df61 100644 --- a/test/nested2.js +++ b/test/nested2.js @@ -4,17 +4,16 @@ 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/not-deep-equal-failure.js b/test/not-deep-equal-failure.js index dadfa535..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,14 +57,17 @@ 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 } }); }); test('not deep equal', function (t) { t.plan(1); - t.notDeepEqual({b: 2}, {b: 2}); + t.notDeepEqual({ b: 2 }, { b: 2 }); }); }); @@ -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,12 +119,15 @@ 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 } }); }); - 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 } } } } } }); }); @@ -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/objectMode.js b/test/objectMode.js index 3a7cf379..fd71d8cc 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; @@ -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); } }); @@ -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..5eb05142 100644 --- a/test/onFailure.js +++ b/test/onFailure.js @@ -3,10 +3,14 @@ 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, 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/promise_fail.js b/test/promise_fail.js index fc38fb75..f45019da 100644 --- a/test/promise_fail.js +++ b/test/promise_fail.js @@ -15,12 +15,13 @@ 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)) { - return tt.pass('the test file indicated it should be skipped'); + if ((/^skip\n$/).test(rowsString)) { + tt.pass('the test file indicated it should be skipped'); + return; } 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 +64,13 @@ 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)) { - return tt.pass('the test file indicated it should be skipped'); + if ((/^skip\n$/).test(rowsString)) { + tt.pass('the test file indicated it should be skipped'); + return; } 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/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/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/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 6682f048..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,21 +31,18 @@ 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 (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/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/stackTrace.js b/test/stackTrace.js index 7906884f..99afa1bf 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -15,23 +15,22 @@ 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 } }); }); 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' }); @@ -171,7 +170,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, @@ -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, @@ -236,7 +234,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, @@ -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, @@ -295,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; 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/teardown.js b/test/teardown.js index e5013cf4..f8e4c5fc 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', @@ -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/throws.js b/test/throws.js index 70d90cef..e2a6d609 100644 --- a/test/throws.js +++ b/test/throws.js @@ -8,23 +8,15 @@ 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' }, 'message', - { configurable: true, enumerable: true, get: getter } + { + configurable: true, + enumerable: true, + get: getter + } ); var thrower = function () { throw messageGetterError; }; diff --git a/test/todo_explanation.js b/test/todo_explanation.js index d0a57118..162219f4 100644 --- a/test/todo_explanation.js +++ b/test/todo_explanation.js @@ -7,47 +7,45 @@ 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); 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) { 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;