From 17006422fa8189a7e361edfb1e803b73a72b4894 Mon Sep 17 00:00:00 2001 From: David Anson Date: Thu, 21 May 2020 21:10:57 -0700 Subject: [PATCH 01/30] [Tests] add test case for #519 for test.comment() in createStream/objectMode context --- test/comment.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/comment.js b/test/comment.js index 007d457a..ff055e00 100644 --- a/test/comment.js +++ b/test/comment.js @@ -173,3 +173,18 @@ tap.test('multiline string', function (assert) { t.end(); }); }); + +tap.test('comment with createStream/objectMode', function (assert) { + assert.plan(1); + + var test = tape.createHarness(); + test.createStream({ objectMode: true }).on('data', function (row) { + if (typeof row === 'string') { + assert.equal(row, 'comment message'); + } + }); + test('t.comment', function (t) { + t.comment('comment message'); + t.end(); + }); +}); From 1515ff4a8f749aa6d075bffdcda543ca94c559a9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 25 May 2020 13:46:44 -0700 Subject: [PATCH 02/30] [eslint] remove useless regex escapes --- .eslintrc | 1 + lib/results.js | 2 +- lib/test.js | 4 ++-- test/common.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index 40369d2a..5cc84b03 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,5 +11,6 @@ "anonymous": "always", "named": "never", }], + "no-useless-escape": "error", }, } diff --git a/lib/results.js b/lib/results.js index 89da4b0a..d4bf0ab2 100644 --- a/lib/results.js +++ b/lib/results.js @@ -7,7 +7,7 @@ var inspect = require('object-inspect'); var bind = require('function-bind'); var has = require('has'); var regexpTest = bind.call(Function.call, RegExp.prototype.test); -var yamlIndicators = /\:|\-|\?/; +var yamlIndicators = /:|-|\?/; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick diff --git a/lib/test.js b/lib/test.js index 3e75ee2f..ff22871c 100644 --- a/lib/test.js +++ b/lib/test.js @@ -269,8 +269,8 @@ Test.prototype._assert = function assert(ok, opts) { /((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?/ */ - var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?$/; - var lineWithTokens = err[i].replace(process.cwd(), '/\$CWD').replace(__dirname, '/\$TEST'); + var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/; + var lineWithTokens = err[i].replace(process.cwd(), '/$CWD').replace(__dirname, '/$TEST'); var m = re.exec(lineWithTokens); if (!m) { diff --git a/test/common.js b/test/common.js index e7df7d1c..856c9250 100644 --- a/test/common.js +++ b/test/common.js @@ -37,7 +37,7 @@ var stripChangingData = function (line) { var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE'); var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/'); var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL'); - var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \:\$LINE:\$COL\)$/, ')'); + var withoutNestedLineNumbers = withoutLineNumbers.replace(/, :\$LINE:\$COL\)$/, ')'); return withoutNestedLineNumbers; }; From d0286f48f221fc699c91eb6ec8d1911ed38535a8 Mon Sep 17 00:00:00 2001 From: Matt Riley Date: Sun, 14 Jun 2020 19:06:58 +1000 Subject: [PATCH 03/30] [readme] add `tape-describe` to 'other' section (#523) Closes #522 --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index 4676bce8..a3e456a8 100644 --- a/readme.markdown +++ b/readme.markdown @@ -136,6 +136,7 @@ By default, uncaught exceptions in your tests will not be intercepted, and will - Electron test runner with https://github.com/tundrax/electron-tap - Concurrency support with https://github.com/imsnif/mixed-tape - In-process reporting with https://github.com/DavidAnson/tape-player +- Describe blocks with https://github.com/mattriley/tape-describe # methods From 78b4d9833a2df7593f653b263588b9a49ca3fe08 Mon Sep 17 00:00:00 2001 From: Ryan Hamley Date: Mon, 17 Aug 2020 15:23:00 -0700 Subject: [PATCH 04/30] [New] Include name of test in log when test times out (#524) --- lib/test.js | 2 +- test/timeoutAfter.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/test.js b/lib/test.js index ff22871c..9ce1082c 100644 --- a/lib/test.js +++ b/lib/test.js @@ -136,7 +136,7 @@ Test.prototype.timeoutAfter = function (ms) { if (!ms) throw new Error('timeoutAfter requires a timespan'); var self = this; var timeout = safeSetTimeout(function () { - self.fail('test timed out after ' + ms + 'ms'); + self.fail(self.name + ' timed out after ' + ms + 'ms'); self.end(); }, ms); this.once('end', function () { diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index 80752d28..5d198e2a 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -12,11 +12,11 @@ tap.test('timeoutAfter test', function (tt) { tt.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# timeoutAfter', - 'not ok 1 test timed out after 1ms', + 'not ok 1 timeoutAfter timed out after 1ms', ' ---', ' operator: fail', ' stack: |-', - ' Error: test timed out after 1ms', + ' Error: timeoutAfter timed out after 1ms', ' [... stack stripped ...]', ' ...', '', From e344080b1a4b097e1baa1a2b2e843fc283f3f5c2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 16 Oct 2020 22:42:04 -0700 Subject: [PATCH 05/30] [Deps] update `is-regex`, `object-inspect`, `string.prototype.trim` --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8ba3a13e..a10e1bcd 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,12 @@ "glob": "~7.1.6", "has": "~1.0.3", "inherits": "~2.0.4", - "is-regex": "~1.0.5", + "is-regex": "~1.1.1", "minimist": "~1.2.5", - "object-inspect": "~1.7.0", + "object-inspect": "~1.8.0", "resolve": "~1.17.0", "resumer": "~0.0.0", - "string.prototype.trim": "~1.2.1", + "string.prototype.trim": "~1.2.2", "through": "~2.3.8" }, "devDependencies": { From 79a0f4b7b1d0c6db9228cdedf918f20a34dd7762 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 16 Oct 2020 22:42:51 -0700 Subject: [PATCH 06/30] [Dev Deps] update `eslint` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a10e1bcd..cb0a9e55 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "concat-stream": "^1.6.2", "eclint": "^2.8.1", "ecstatic": "^4.1.4", - "eslint": "^7.1.0", + "eslint": "^7.11.0", "falafel": "^2.2.4", "js-yaml": "^3.14.0", "tap": "^8.0.1", From 6e71e6ea1e009a62546a401a35974ca867a24b9a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 16:32:22 -0700 Subject: [PATCH 07/30] [Deps] update `glob`, `is-regex`, `object-inspect`, `resolve`, `string.prototype.trim` --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cb0a9e55..3629431a 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,15 @@ "dotignore": "~0.1.2", "for-each": "~0.3.3", "function-bind": "~1.1.1", - "glob": "~7.1.6", + "glob": "~7.1.7", "has": "~1.0.3", "inherits": "~2.0.4", - "is-regex": "~1.1.1", + "is-regex": "~1.1.3", "minimist": "~1.2.5", - "object-inspect": "~1.8.0", - "resolve": "~1.17.0", + "object-inspect": "~1.11.0", + "resolve": "~1.20.0", "resumer": "~0.0.0", - "string.prototype.trim": "~1.2.2", + "string.prototype.trim": "~1.2.4", "through": "~2.3.8" }, "devDependencies": { From fad6165ae85ebff132daedd1a1bdf3ee307c4ea1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 16:39:36 -0700 Subject: [PATCH 08/30] [Dev Deps] update `eslint` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3629431a..68791203 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "concat-stream": "^1.6.2", "eclint": "^2.8.1", "ecstatic": "^4.1.4", - "eslint": "^7.11.0", + "eslint": "^7.31.0", "falafel": "^2.2.4", "js-yaml": "^3.14.0", "tap": "^8.0.1", From 3907aa560caa2c8d30a6a9168c0d7a3d65a3ba3e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 2 Jan 2021 13:48:16 -0800 Subject: [PATCH 09/30] [meta] run `aud` in `posttest` --- .gitignore | 4 ++++ package.json | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 77f05fa4..1e3b179d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ # Only apps should have lockfiles yarn.lock package-lock.json + +# coverage data +coverage/ +.nyc_output/ diff --git a/package.json b/package.json index 68791203..0f07f253 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "through": "~2.3.8" }, "devDependencies": { + "aud": "~1.1.5", "concat-stream": "^1.6.2", "eclint": "^2.8.1", "ecstatic": "^4.1.4", @@ -40,7 +41,8 @@ "lint": "eslint .", "pretest": "npm run lint", "test": "npm run tests-only", - "tests-only": "tap test/*.js" + "posttest": "aud --production", + "tests-only": "nyc tap test/*.js" }, "testling": { "files": "test/browser/*.js", From c3d434d8b86a0be162efb7fb548f0405239a2688 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 5 May 2021 08:41:21 -0700 Subject: [PATCH 10/30] [meta] add `safe-publish-latest`; use `prepublishOnly` script for npm 7+ --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 0f07f253..03c5e22f 100644 --- a/package.json +++ b/package.json @@ -33,10 +33,13 @@ "eslint": "^7.31.0", "falafel": "^2.2.4", "js-yaml": "^3.14.0", + "safe-publish-latest": "^1.1.4", "tap": "^8.0.1", "tap-parser": "^3.0.5" }, "scripts": { + "prepublishOnly": "safe-publish-latest", + "prepublish": "not-in-publish || npm run prepublishOnly", "prelint": "eclint check", "lint": "eslint .", "pretest": "npm run lint", From 46aff81f10ad63990f6047c0bdba3be0c90bd3dd Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 5 May 2021 08:41:39 -0700 Subject: [PATCH 11/30] [actions] use `node/install` instead of `node/run`; use `codecov` action --- .editorconfig | 7 +++ .eslintignore | 2 + .github/workflows/node-4+.yml | 60 +++++++++++++++++++++ .github/workflows/node-iojs.yml | 62 ++++++++++++++++++++++ .github/workflows/node-pretest.yml | 26 +++++++++ .github/workflows/node-zero.yml | 64 +++++++++++++++++++++++ .github/workflows/rebase.yml | 15 ++++++ .github/workflows/require-allow-edits.yml | 12 +++++ .nycrc | 11 ++++ 9 files changed, 259 insertions(+) create mode 100644 .eslintignore create mode 100644 .github/workflows/node-4+.yml create mode 100644 .github/workflows/node-iojs.yml create mode 100644 .github/workflows/node-pretest.yml create mode 100644 .github/workflows/node-zero.yml create mode 100644 .github/workflows/rebase.yml create mode 100644 .github/workflows/require-allow-edits.yml create mode 100644 .nycrc diff --git a/.editorconfig b/.editorconfig index 1474ee61..32f9d03c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,10 +12,17 @@ block_comment_start = /* block_comment = * block_comment_end = */ +[.nycrc] +indent_style = tab + [*.md] indent_style = space indent_size = 4 +[*.yml] +indent_style = space +indent_size = 2 + [readme.markdown] indent_size = off max_line_length = off diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..ed88d37f --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +coverage/ +.nyc_output/ diff --git a/.github/workflows/node-4+.yml b/.github/workflows/node-4+.yml new file mode 100644 index 00000000..007f7736 --- /dev/null +++ b/.github/workflows/node-4+.yml @@ -0,0 +1,60 @@ +name: 'Tests: node.js' + +on: [pull_request, push] + +jobs: + matrix: + runs-on: ubuntu-latest + outputs: + latest: ${{ steps.set-matrix.outputs.requireds }} + minors: ${{ steps.set-matrix.outputs.optionals }} + steps: + - uses: ljharb/actions/node/matrix@main + id: set-matrix + with: + preset: '>=4' + + latest: + needs: [matrix] + name: 'latest minors' + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.matrix.outputs.latest) }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install ${{ matrix.node-version }} && npm install' + with: + node-version: ${{ matrix.node-version }} + - run: npm run tests-only + - uses: codecov/codecov-action@v1 + + minors: + needs: [matrix, latest] + name: 'non-latest minors' + continue-on-error: true + if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.matrix.outputs.minors) }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install ${{ matrix.node-version }} && npm install' + with: + node-version: ${{ matrix.node-version }} + - run: npm run tests-only + - uses: codecov/codecov-action@v1 + + node: + name: 'node 4+' + needs: [latest, minors] + runs-on: ubuntu-latest + steps: + - run: 'echo tests completed' diff --git a/.github/workflows/node-iojs.yml b/.github/workflows/node-iojs.yml new file mode 100644 index 00000000..891b73d0 --- /dev/null +++ b/.github/workflows/node-iojs.yml @@ -0,0 +1,62 @@ +name: 'Tests: node.js (io.js)' + +on: [pull_request, push] + +jobs: + matrix: + runs-on: ubuntu-latest + outputs: + latest: ${{ steps.set-matrix.outputs.requireds }} + minors: ${{ steps.set-matrix.outputs.optionals }} + steps: + - uses: ljharb/actions/node/matrix@main + id: set-matrix + with: + preset: 'iojs' + + latest: + needs: [matrix] + name: 'latest minors' + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.matrix.outputs.latest) }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install ${{ matrix.node-version }} && npm install' + with: + node-version: ${{ matrix.node-version }} + skip-ls-check: true + - run: npm run tests-only + - uses: codecov/codecov-action@v1 + + minors: + needs: [matrix, latest] + name: 'non-latest minors' + continue-on-error: true + if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.matrix.outputs.minors) }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install ${{ matrix.node-version }} && npm install' + with: + node-version: ${{ matrix.node-version }} + skip-ls-check: true + - run: npm run tests-only + - uses: codecov/codecov-action@v1 + + node: + name: 'io.js' + needs: [latest, minors] + runs-on: ubuntu-latest + steps: + - run: 'echo tests completed' diff --git a/.github/workflows/node-pretest.yml b/.github/workflows/node-pretest.yml new file mode 100644 index 00000000..969d1386 --- /dev/null +++ b/.github/workflows/node-pretest.yml @@ -0,0 +1,26 @@ +name: 'Tests: pretest/posttest' + +on: [pull_request, push] + +jobs: + pretest: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install lts/* && npm install' + with: + node-version: 'lts/*' + - run: npm run pretest + + posttest: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install lts/* && npm install' + with: + node-version: 'lts/*' + - run: npm run posttest diff --git a/.github/workflows/node-zero.yml b/.github/workflows/node-zero.yml new file mode 100644 index 00000000..18dcd1a1 --- /dev/null +++ b/.github/workflows/node-zero.yml @@ -0,0 +1,64 @@ +name: 'Tests: node.js (0.x)' + +on: [pull_request, push] + +jobs: + matrix: + runs-on: ubuntu-latest + outputs: + stable: ${{ steps.set-matrix.outputs.requireds }} + unstable: ${{ steps.set-matrix.outputs.optionals }} + steps: + - uses: ljharb/actions/node/matrix@main + id: set-matrix + with: + preset: '0.x' + + stable: + needs: [matrix] + name: 'stable minors' + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.matrix.outputs.stable) }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install ${{ matrix.node-version }} && npm install' + with: + node-version: ${{ matrix.node-version }} + cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }} + skip-ls-check: true + - run: npm run tests-only + - uses: codecov/codecov-action@v1 + + unstable: + needs: [matrix, stable] + name: 'unstable minors' + continue-on-error: true + if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.matrix.outputs.unstable) }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install ${{ matrix.node-version }} && npm install' + with: + node-version: ${{ matrix.node-version }} + cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }} + skip-ls-check: true + - run: npm run tests-only + - uses: codecov/codecov-action@v1 + + node: + name: 'node 0.x' + needs: [stable, unstable] + runs-on: ubuntu-latest + steps: + - run: 'echo tests completed' diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 00000000..027aed07 --- /dev/null +++ b/.github/workflows/rebase.yml @@ -0,0 +1,15 @@ +name: Automatic Rebase + +on: [pull_request_target] + +jobs: + _: + name: "Automatic Rebase" + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/rebase@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/require-allow-edits.yml b/.github/workflows/require-allow-edits.yml new file mode 100644 index 00000000..549d7b48 --- /dev/null +++ b/.github/workflows/require-allow-edits.yml @@ -0,0 +1,12 @@ +name: Require “Allow Edits” + +on: [pull_request_target] + +jobs: + _: + name: "Require “Allow Edits”" + + runs-on: ubuntu-latest + + steps: + - uses: ljharb/require-allow-edits@main diff --git a/.nycrc b/.nycrc new file mode 100644 index 00000000..daab59ba --- /dev/null +++ b/.nycrc @@ -0,0 +1,11 @@ +{ + "all": true, + "check-coverage": false, + "reporter": ["text-summary", "text", "html", "json"], + "exclude": [ + "bin/import-or-require.js", + "coverage", + "example", + "test" + ] +} From b7b01ec38ede9f9722b5cce90574782e1eda1305 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 19 Oct 2020 20:05:08 -0700 Subject: [PATCH 12/30] [Tests] handle stack differences in node 15 --- test/common.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/common.js b/test/common.js index 856c9250..0ddc4312 100644 --- a/test/common.js +++ b/test/common.js @@ -52,7 +52,11 @@ module.exports.stripFullStack = function (output) { return line; }); - var deduped = withDuplicates.filter(function (line, ix) { + var withoutInternals = withDuplicates.filter(function (line) { + return !line.match(/ \(node:[^)]+\)$/); + }); + + var deduped = withoutInternals.filter(function (line, ix) { var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped; return !hasPrior; }); From f2997591a038fa48239f205e40eed5c75278a261 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 3 Jan 2021 14:01:58 -0800 Subject: [PATCH 13/30] [Tests] make `stripFullStack` output an array of lines, for better failure messages --- test/anonymous-fn.js | 5 +- test/circular-things.js | 48 ++-- test/common.js | 2 +- test/deep-equal-failure.js | 144 +++++------ test/default-messages.js | 7 +- test/double_end.js | 9 +- test/edge-cases.js | 451 +++++++++++++++++---------------- test/error.js | 43 ++++ test/exit.js | 36 ++- test/fail.js | 2 +- test/has spaces.js | 2 +- test/ignore_from_gitignore.js | 6 +- test/match.js | 4 +- test/not-deep-equal-failure.js | 144 +++++------ test/not-equal-failure.js | 44 ++-- test/numerics.js | 279 ++++++++++---------- test/skip_explanation.js | 4 +- test/throws.js | 309 +++++++++++----------- test/timeoutAfter.js | 5 +- test/todo.js | 36 +-- test/todo_explanation.js | 70 +++-- test/todo_single.js | 36 +-- test/too_many.js | 5 +- test/undef.js | 48 ++-- 24 files changed, 900 insertions(+), 839 deletions(-) create mode 100644 test/error.js diff --git a/test/anonymous-fn.js b/test/anonymous-fn.js index a402eb9c..f28c4340 100644 --- a/test/anonymous-fn.js +++ b/test/anonymous-fn.js @@ -30,8 +30,9 @@ tap.test('inside anonymous functions', function (tt) { '1..1', '# tests 1', '# pass 0', - '# fail 1' - ].join('\n') + '\n'); + '# fail 1', + '' + ]); }; test.createStream().pipe(concat(tc)); diff --git a/test/circular-things.js b/test/circular-things.js index dcab2b12..46562e1a 100644 --- a/test/circular-things.js +++ b/test/circular-things.js @@ -9,30 +9,30 @@ tap.test('circular test', function (assert) { assert.plan(1); test.createStream().pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# circular\n' - + 'not ok 1 should be equal\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: |-\n' - + ' {}\n' - + ' actual: |-\n' - + ' { circular: [Circular] }\n' - + ' at: Test. ($TEST/circular-things.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should be equal\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/circular-things.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# circular', + 'not ok 1 should be equal', + ' ---', + ' operator: equal', + ' expected: |-', + ' {}', + ' actual: |-', + ' { circular: [Circular] }', + ' at: Test. ($TEST/circular-things.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/circular-things.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); })); test('circular', function (t) { diff --git a/test/common.js b/test/common.js index 0ddc4312..3f6bab84 100644 --- a/test/common.js +++ b/test/common.js @@ -65,5 +65,5 @@ module.exports.stripFullStack = function (output) { // Handle stack trace variation in Node v0.8 /at(:?) Test\.(?:module\.exports|tap\.test\.err\.code)/g, 'at$1 Test.' - ); + ).split('\n'); }; diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index e1f2659e..b086d2c3 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -15,30 +15,30 @@ tap.test('deep equal failure', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# deep equal\n' - + 'not ok 1 should be equal\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: |-\n' - + ' { b: 2 }\n' - + ' actual: |-\n' - + ' { a: 1 }\n' - + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should be equal\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# deep equal', + 'not ok 1 should be equal', + ' ---', + ' operator: equal', + ' expected: |-', + ' { b: 2 }', + ' actual: |-', + ' { a: 1 }', + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); assert.deepEqual(getDiag(body), { operator: 'equal', @@ -76,30 +76,30 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# deep equal\n' - + 'not ok 1 should be equal\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: |-\n' - + ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }\n' - + ' actual: |-\n' - + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' - + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should be equal\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# deep equal', + 'not ok 1 should be equal', + ' ---', + ' operator: equal', + ' expected: |-', + ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', + ' actual: |-', + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); assert.deepEqual(getDiag(body), { operator: 'equal', @@ -137,30 +137,30 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# deep equal\n' - + 'not ok 1 should be equal\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: |-\n' - + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' - + ' actual: |-\n' - + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' - + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should be equal\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# deep equal', + 'not ok 1 should be equal', + ' ---', + ' operator: equal', + ' expected: |-', + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', + ' actual: |-', + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); assert.deepEqual(getDiag(body), { operator: 'equal', diff --git a/test/default-messages.js b/test/default-messages.js index 5651a8ec..799bb2f7 100644 --- a/test/default-messages.js +++ b/test/default-messages.js @@ -13,7 +13,6 @@ tap.test('default messages', function (t) { var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]); ps.stdout.pipe(concat(function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# default messages', @@ -44,7 +43,9 @@ tap.test('default messages', function (t) { '1..12', '# tests 12', '# pass 11', - '# fail 1' - ].join('\n') + '\n\n'); + '# fail 1', + '', + '' + ]); })); }); diff --git a/test/double_end.js b/test/double_end.js index b2fbc5b9..ff4618b3 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -29,14 +29,13 @@ test(function (t) { to._onTimeout(); } catch (e) { - stackExpected = stripFullStack(e.stack).split('\n')[1]; + stackExpected = stripFullStack(e.stack)[1]; stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js'); stackExpected = stackExpected.trim(); atExpected = stackExpected.replace(/^at\s+/, 'at: '); } - var stripped = stripFullStack(body.toString('utf8')); - t.equal(stripped, [ + t.same(stripFullStack(body.toString('utf8')), [ 'TAP version 13', '# double end', 'ok 1 should be equal', @@ -55,6 +54,8 @@ test(function (t) { '# tests 2', '# pass 1', '# fail 1', - ].join('\n') + '\n\n'); + '', + '' + ]); })); }); diff --git a/test/edge-cases.js b/test/edge-cases.js index 96da8548..78ea70d6 100644 --- a/test/edge-cases.js +++ b/test/edge-cases.js @@ -11,231 +11,232 @@ tap.test('edge cases', function (tt) { var test = tape.createHarness(); test.createStream().pipe(concat(function (body) { - tt.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# zeroes\n' - + 'ok 1 0 equal to -0\n' - + 'ok 2 -0 equal to 0\n' - + 'not ok 3 0 notEqual to -0\n' - + ' ---\n' - + ' operator: notEqual\n' - + ' expected: |-\n' - + ' -0\n' - + ' actual: |-\n' - + ' 0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: 0 notEqual to -0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 4 -0 notEqual to 0\n' - + ' ---\n' - + ' operator: notEqual\n' - + ' expected: |-\n' - + ' 0\n' - + ' actual: |-\n' - + ' -0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: -0 notEqual to 0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 5 0 looseEqual to -0\n' - + 'ok 6 -0 looseEqual to 0\n' - + 'not ok 7 0 notLooseEqual to -0\n' - + ' ---\n' - + ' operator: notDeepLooseEqual\n' - + ' expected: |-\n' - + ' -0\n' - + ' actual: |-\n' - + ' 0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: 0 notLooseEqual to -0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 8 -0 notLooseEqual to 0\n' - + ' ---\n' - + ' operator: notDeepLooseEqual\n' - + ' expected: |-\n' - + ' 0\n' - + ' actual: |-\n' - + ' -0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: -0 notLooseEqual to 0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 9 0 strictEqual to -0\n' - + 'ok 10 -0 strictEqual to 0\n' - + 'not ok 11 0 notStrictEqual to -0\n' - + ' ---\n' - + ' operator: notEqual\n' - + ' expected: |-\n' - + ' -0\n' - + ' actual: |-\n' - + ' 0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: 0 notStrictEqual to -0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 12 -0 notStrictEqual to 0\n' - + ' ---\n' - + ' operator: notEqual\n' - + ' expected: |-\n' - + ' 0\n' - + ' actual: |-\n' - + ' -0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: -0 notStrictEqual to 0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 13 0 deepLooseEqual to -0\n' - + 'ok 14 -0 deepLooseEqual to 0\n' - + 'not ok 15 0 notDeepLooseEqual to -0\n' - + ' ---\n' - + ' operator: notDeepLooseEqual\n' - + ' expected: |-\n' - + ' -0\n' - + ' actual: |-\n' - + ' 0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: 0 notDeepLooseEqual to -0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 16 -0 notDeepLooseEqual to 0\n' - + ' ---\n' - + ' operator: notDeepLooseEqual\n' - + ' expected: |-\n' - + ' 0\n' - + ' actual: |-\n' - + ' -0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: -0 notDeepLooseEqual to 0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 17 0 deepEqual to -0\n' - + ' ---\n' - + ' operator: deepEqual\n' - + ' expected: |-\n' - + ' -0\n' - + ' actual: |-\n' - + ' 0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: 0 deepEqual to -0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 18 -0 deepEqual to 0\n' - + ' ---\n' - + ' operator: deepEqual\n' - + ' expected: |-\n' - + ' 0\n' - + ' actual: |-\n' - + ' -0\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: -0 deepEqual to 0\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 19 0 notDeepEqual to -0\n' - + 'ok 20 -0 notDeepEqual to 0\n' - + '# NaNs\n' - + 'not ok 21 NaN equal to NaN\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: NaN\n' - + ' actual: NaN\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: NaN equal to NaN\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 22 NaN notEqual to NaN\n' - + 'not ok 23 NaN looseEqual to NaN\n' - + ' ---\n' - + ' operator: deepLooseEqual\n' - + ' expected: NaN\n' - + ' actual: NaN\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: NaN looseEqual to NaN\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 24 NaN notLooseEqual to NaN\n' - + 'not ok 25 NaN strictEqual to NaN\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: NaN\n' - + ' actual: NaN\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: NaN strictEqual to NaN\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 26 NaN notStrictEqual to NaN\n' - + 'not ok 27 NaN deepLooseEqual to NaN\n' - + ' ---\n' - + ' operator: deepLooseEqual\n' - + ' expected: NaN\n' - + ' actual: NaN\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: NaN deepLooseEqual to NaN\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 28 NaN notDeepLooseEqual to NaN\n' - + 'ok 29 NaN deepEqual to NaN\n' - + 'not ok 30 NaN notDeepEqual to NaN\n' - + ' ---\n' - + ' operator: notDeepEqual\n' - + ' expected: NaN\n' - + ' actual: NaN\n' - + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: NaN notDeepEqual to NaN\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n1..30\n' - + '# tests 30\n' - + '# pass 15\n' - + '# fail 15\n' - ); + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# zeroes', + 'ok 1 0 equal to -0', + 'ok 2 -0 equal to 0', + 'not ok 3 0 notEqual to -0', + ' ---', + ' operator: notEqual', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 notEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 4 -0 notEqual to 0', + ' ---', + ' operator: notEqual', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 notEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 5 0 looseEqual to -0', + 'ok 6 -0 looseEqual to 0', + 'not ok 7 0 notLooseEqual to -0', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 notLooseEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 -0 notLooseEqual to 0', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 notLooseEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 9 0 strictEqual to -0', + 'ok 10 -0 strictEqual to 0', + 'not ok 11 0 notStrictEqual to -0', + ' ---', + ' operator: notEqual', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 notStrictEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 12 -0 notStrictEqual to 0', + ' ---', + ' operator: notEqual', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 notStrictEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 13 0 deepLooseEqual to -0', + 'ok 14 -0 deepLooseEqual to 0', + 'not ok 15 0 notDeepLooseEqual to -0', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 notDeepLooseEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 16 -0 notDeepLooseEqual to 0', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 notDeepLooseEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 17 0 deepEqual to -0', + ' ---', + ' operator: deepEqual', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 deepEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 18 -0 deepEqual to 0', + ' ---', + ' operator: deepEqual', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 deepEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 19 0 notDeepEqual to -0', + 'ok 20 -0 notDeepEqual to 0', + '# NaNs', + 'not ok 21 NaN equal to NaN', + ' ---', + ' operator: equal', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN equal to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 22 NaN notEqual to NaN', + 'not ok 23 NaN looseEqual to NaN', + ' ---', + ' operator: deepLooseEqual', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN looseEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 24 NaN notLooseEqual to NaN', + 'not ok 25 NaN strictEqual to NaN', + ' ---', + ' operator: equal', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN strictEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 26 NaN notStrictEqual to NaN', + 'not ok 27 NaN deepLooseEqual to NaN', + ' ---', + ' operator: deepLooseEqual', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN deepLooseEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 28 NaN notDeepLooseEqual to NaN', + 'ok 29 NaN deepEqual to NaN', + 'not ok 30 NaN notDeepEqual to NaN', + ' ---', + ' operator: notDeepEqual', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN notDeepEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..30', + '# tests 30', + '# pass 15', + '# fail 15', + '' + ]); })); test('zeroes', function (t) { diff --git a/test/error.js b/test/error.js new file mode 100644 index 00000000..83e80100 --- /dev/null +++ b/test/error.js @@ -0,0 +1,43 @@ +'use strict'; + +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +var stripFullStack = require('./common').stripFullStack; + +tap.test('failures', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# error', + 'not ok 1 Error: this is a message', + ' ---', + ' operator: error', + ' expected: |-', + ' undefined', + ' actual: |-', + ' [Error: this is a message]', + ' at: Test. ($TEST/error.js:$LINE:$COL)', + ' stack: |-', + ' Error: this is a message', + ' at Test. ($TEST/error.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '', + ]); + })); + + test('error', function (t) { + t.plan(1); + t.error(new Error('this is a message')); + }); +}); diff --git a/test/exit.js b/test/exit.js index 4ba1f9a5..80ef8ad5 100644 --- a/test/exit.js +++ b/test/exit.js @@ -66,8 +66,10 @@ tap.test('exit fail', function (t) { '1..5', '# tests 5', '# pass 4', - '# fail 1' - ].join('\n') + '\n\n'); + '# fail 1', + '', + '' + ]); }; var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'fail.js')]); @@ -103,8 +105,10 @@ tap.test('too few exit', function (t) { '1..6', '# tests 6', '# pass 5', - '# fail 1' - ].join('\n') + '\n\n'); + '# fail 1', + '', + '' + ]); }; var ps = spawn(process.execPath, [path.join(__dirname, '/exit/too_few.js')]); @@ -138,8 +142,10 @@ tap.test('more planned in a second test', function (t) { '1..3', '# tests 3', '# pass 2', - '# fail 1' - ].join('\n') + '\n\n'); + '# fail 1', + '', + '' + ]); }; var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]); @@ -162,8 +168,10 @@ tap.test('todo passing', function (t) { '# tests 1', '# pass 1', '', - '# ok' - ].join('\n') + '\n\n'); + '# ok', + '', + '' + ]); }; var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo.js')]); @@ -192,8 +200,10 @@ tap.test('todo failing', function (t) { '# tests 1', '# pass 1', '', - '# ok' - ].join('\n') + '\n\n'); + '# ok', + '', + '' + ]); }; var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo_fail.js')]); @@ -225,8 +235,10 @@ tap.test('forgot to call t.end()', function (t) { '1..3', '# tests 3', '# pass 2', - '# fail 1' - ].join('\n') + '\n\n'); + '# fail 1', + '', + '' + ]); }; var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]); diff --git a/test/fail.js b/test/fail.js index 580e40a0..45df8d66 100644 --- a/test/fail.js +++ b/test/fail.js @@ -38,7 +38,7 @@ tap.test('array test', function (tt) { '# pass 4', '# fail 1', '' - ].join('\n')); + ]); }; test.createStream().pipe(concat(tc)); diff --git a/test/has spaces.js b/test/has spaces.js index f8630de3..3e8c80db 100644 --- a/test/has spaces.js +++ b/test/has spaces.js @@ -28,7 +28,7 @@ tap.test('array test', function (tt) { '# pass 0', '# fail 1', '' - ].join('\n')); + ]); }; test.createStream().pipe(concat(tc)); diff --git a/test/ignore_from_gitignore.js b/test/ignore_from_gitignore.js index 16b076a4..d95260b8 100644 --- a/test/ignore_from_gitignore.js +++ b/test/ignore_from_gitignore.js @@ -35,7 +35,7 @@ tap.test('Should pass with ignoring', { skip: process.platform === 'win32' }, fu '# ok', '', '' - ].join('\n')); + ]); }; var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], {cwd: path.join(__dirname, 'ignore')}); @@ -92,7 +92,7 @@ tap.test('Should pass', { skip: process.platform === 'win32' }, function (tt) { '# fail 2', '', '' - ].join('\n')); + ]); }; var ps = spawn(tapeBin, ['**/*.js'], {cwd: path.join(__dirname, 'ignore')}); @@ -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')))); + 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/match.js b/test/match.js index 09ccd343..b598b9db 100644 --- a/test/match.js +++ b/test/match.js @@ -48,7 +48,7 @@ tap.test('match', function (tt) { '# pass 4', '# fail 2', '' - ].join('\n')); + ]); }; test.createStream().pipe(concat(tc)); @@ -142,7 +142,7 @@ tap.test('doesNotMatch', function (tt) { '# pass 2', '# fail 4', '' - ].join('\n')); + ]); }; test.createStream().pipe(concat(tc)); diff --git a/test/not-deep-equal-failure.js b/test/not-deep-equal-failure.js index 63fbd614..5ac49cc9 100644 --- a/test/not-deep-equal-failure.js +++ b/test/not-deep-equal-failure.js @@ -15,30 +15,30 @@ tap.test('deep equal failure', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# not deep equal\n' - + 'not ok 1 should not be equivalent\n' - + ' ---\n' - + ' operator: notDeepEqual\n' - + ' expected: |-\n' - + ' { b: 2 }\n' - + ' actual: |-\n' - + ' { b: 2 }\n' - + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should not be equivalent\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# not deep equal', + 'not ok 1 should not be equivalent', + ' ---', + ' operator: notDeepEqual', + ' expected: |-', + ' { b: 2 }', + ' actual: |-', + ' { b: 2 }', + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); assert.deepEqual(getDiag(body), { operator: 'notDeepEqual', @@ -76,30 +76,30 @@ tap.test('not deep equal failure, depth 6, with option', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# not deep equal\n' - + 'not ok 1 should not be equivalent\n' - + ' ---\n' - + ' operator: notDeepEqual\n' - + ' expected: |-\n' - + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' - + ' actual: |-\n' - + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' - + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should not be equivalent\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# not deep equal', + 'not ok 1 should not be equivalent', + ' ---', + ' operator: notDeepEqual', + ' expected: |-', + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + ' actual: |-', + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); assert.deepEqual(getDiag(body), { operator: 'notDeepEqual', @@ -137,30 +137,30 @@ tap.test('not deep equal failure, depth 6, without option', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# not deep equal\n' - + 'not ok 1 should not be equivalent\n' - + ' ---\n' - + ' operator: notDeepEqual\n' - + ' expected: |-\n' - + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' - + ' actual: |-\n' - + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' - + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should not be equivalent\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# not deep equal', + 'not ok 1 should not be equivalent', + ' ---', + ' operator: notDeepEqual', + ' expected: |-', + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', + ' actual: |-', + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); assert.deepEqual(getDiag(body), { operator: 'notDeepEqual', diff --git a/test/not-equal-failure.js b/test/not-equal-failure.js index 28e31a65..bb7f9167 100644 --- a/test/not-equal-failure.js +++ b/test/not-equal-failure.js @@ -15,28 +15,28 @@ tap.test('not equal failure', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# not equal\n' - + 'not ok 1 should not be equal\n' - + ' ---\n' - + ' operator: notEqual\n' - + ' expected: 2\n' - + ' actual: 2\n' - + ' at: Test. ($TEST/not-equal-failure.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should not be equal\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/not-equal-failure.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# not equal', + 'not ok 1 should not be equal', + ' ---', + ' operator: notEqual', + ' expected: 2', + ' actual: 2', + ' at: Test. ($TEST/not-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/not-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); assert.deepEqual(getDiag(body), { operator: 'notEqual', diff --git a/test/numerics.js b/test/numerics.js index a425de4d..b4e7ef32 100644 --- a/test/numerics.js +++ b/test/numerics.js @@ -11,145 +11,146 @@ tap.test('numerics', function (tt) { var test = tape.createHarness(); test.createStream().pipe(concat(function (body) { - tt.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# numeric strings\n' - + 'not ok 1 number equal to string\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: \'3\'\n' - + ' actual: 3\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: number equal to string\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 2 string equal to number\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: 3\n' - + ' actual: \'3\'\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: string equal to number\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 3 number notEqual to string\n' - + 'ok 4 string notEqual to number\n' - + 'ok 5 number looseEqual to string\n' - + 'ok 6 string looseEqual to number\n' - + 'not ok 7 number notLooseEqual to string\n' - + ' ---\n' - + ' operator: notDeepLooseEqual\n' - + ' expected: \'3\'\n' - + ' actual: 3\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: number notLooseEqual to string\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 8 string notLooseEqual to number\n' - + ' ---\n' - + ' operator: notDeepLooseEqual\n' - + ' expected: 3\n' - + ' actual: \'3\'\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: string notLooseEqual to number\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 9 number strictEqual to string\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: \'3\'\n' - + ' actual: 3\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: number strictEqual to string\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 10 string strictEqual to number\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: 3\n' - + ' actual: \'3\'\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: string strictEqual to number\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 11 number notStrictEqual to string\n' - + 'ok 12 string notStrictEqual to number\n' - + 'ok 13 number deepLooseEqual to string\n' - + 'ok 14 string deepLooseEqual to number\n' - + 'not ok 15 number notDeepLooseEqual to string\n' - + ' ---\n' - + ' operator: notDeepLooseEqual\n' - + ' expected: \'3\'\n' - + ' actual: 3\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: number notDeepLooseEqual to string\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 16 string notDeepLooseEqual to number\n' - + ' ---\n' - + ' operator: notDeepLooseEqual\n' - + ' expected: 3\n' - + ' actual: \'3\'\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: string notDeepLooseEqual to number\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 17 number deepEqual to string\n' - + ' ---\n' - + ' operator: deepEqual\n' - + ' expected: \'3\'\n' - + ' actual: 3\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: number deepEqual to string\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 18 string deepEqual to number\n' - + ' ---\n' - + ' operator: deepEqual\n' - + ' expected: 3\n' - + ' actual: \'3\'\n' - + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: string deepEqual to number\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'ok 19 number notDeepEqual to string\n' - + 'ok 20 string notDeepEqual to number\n' - + '\n1..20\n' - + '# tests 20\n' - + '# pass 10\n' - + '# fail 10\n' - ); + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# numeric strings', + 'not ok 1 number equal to string', + ' ---', + ' operator: equal', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number equal to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 2 string equal to number', + ' ---', + ' operator: equal', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string equal to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 3 number notEqual to string', + 'ok 4 string notEqual to number', + 'ok 5 number looseEqual to string', + 'ok 6 string looseEqual to number', + 'not ok 7 number notLooseEqual to string', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number notLooseEqual to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 string notLooseEqual to number', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string notLooseEqual to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 9 number strictEqual to string', + ' ---', + ' operator: equal', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number strictEqual to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 10 string strictEqual to number', + ' ---', + ' operator: equal', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string strictEqual to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 11 number notStrictEqual to string', + 'ok 12 string notStrictEqual to number', + 'ok 13 number deepLooseEqual to string', + 'ok 14 string deepLooseEqual to number', + 'not ok 15 number notDeepLooseEqual to string', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number notDeepLooseEqual to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 16 string notDeepLooseEqual to number', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string notDeepLooseEqual to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 17 number deepEqual to string', + ' ---', + ' operator: deepEqual', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number deepEqual to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 18 string deepEqual to number', + ' ---', + ' operator: deepEqual', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string deepEqual to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 19 number notDeepEqual to string', + 'ok 20 string notDeepEqual to number', + '', + '1..20', + '# tests 20', + '# pass 10', + '# fail 10', + '' + ]); })); test('numeric strings', function (t) { diff --git a/test/skip_explanation.js b/test/skip_explanation.js index 09928ffa..1752dcfd 100644 --- a/test/skip_explanation.js +++ b/test/skip_explanation.js @@ -7,7 +7,7 @@ tap.test('test skip explanations', function (assert) { assert.plan(1); var verify = function (output) { - assert.equal(stripFullStack(output.toString('utf8')), [ + assert.same(stripFullStack(output.toString('utf8')), [ 'TAP version 13', '# SKIP (this skips)', '# some tests might skip', @@ -30,7 +30,7 @@ tap.test('test skip explanations', function (assert) { '', '# ok', '' - ].join('\n')); + ]); }; var tapeTest = test.createHarness(); diff --git a/test/throws.js b/test/throws.js index 1628d822..5cad0334 100644 --- a/test/throws.js +++ b/test/throws.js @@ -29,160 +29,161 @@ tap.test('failures', function (tt) { var test = tape.createHarness(); test.createStream().pipe(concat(function (body) { - tt.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# non functions\n' - + 'not ok 1 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + ' { [TypeError: ' + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(undefined) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 2 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + ' { [TypeError: ' + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(null) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 3 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + ' { [TypeError: ' + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(true) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 4 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + ' { [TypeError: ' + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(false) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 5 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + ' { [TypeError: ' + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage('abc') + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 6 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + ' { [TypeError: ' + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(/a/g) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 7 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + ' { [TypeError: ' + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage([]) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 8 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + ' { [TypeError: ' + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage({}) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '# function\n' - + 'not ok 9 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: undefined\n' - + ' actual: undefined\n' - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should throw\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '# custom error messages\n' - + 'ok 10 "message" is enumerable\n' - + "ok 11 { custom: 'error', message: 'message' }\n" - + 'ok 12 getter is still the same\n' - + '# throws null\n' - + 'ok 13 throws null\n' - + '# wrong type of error\n' - + 'not ok 14 throws actual\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' [Function: TypeError]\n' - + ' actual: |-\n' - + " { [RangeError: actual!] message: 'actual!' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' RangeError: actual!\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n1..14\n' - + '# tests 14\n' - + '# pass 4\n' - + '# fail 10\n' - ); + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# non functions', + 'not ok 1 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' undefined', + ' actual: |-', + ' { [TypeError: ' + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' TypeError: ' + getNonFunctionMessage(undefined) + '', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 2 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' undefined', + ' actual: |-', + ' { [TypeError: ' + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' TypeError: ' + getNonFunctionMessage(null) + '', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 3 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' undefined', + ' actual: |-', + ' { [TypeError: ' + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' TypeError: ' + getNonFunctionMessage(true) + '', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 4 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' undefined', + ' actual: |-', + ' { [TypeError: ' + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' TypeError: ' + getNonFunctionMessage(false) + '', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 5 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' undefined', + ' actual: |-', + ' { [TypeError: ' + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' TypeError: ' + getNonFunctionMessage('abc') + '', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 6 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' undefined', + ' actual: |-', + ' { [TypeError: ' + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' TypeError: ' + getNonFunctionMessage(/a/g) + '', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 7 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' undefined', + ' actual: |-', + ' { [TypeError: ' + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' TypeError: ' + getNonFunctionMessage([]) + '', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' undefined', + ' actual: |-', + ' { [TypeError: ' + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' TypeError: ' + getNonFunctionMessage({}) + '', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# function', + 'not ok 9 should throw', + ' ---', + ' operator: throws', + ' expected: undefined', + ' actual: undefined', + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' Error: should throw', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# custom error messages', + 'ok 10 "message" is enumerable', + "ok 11 { custom: 'error', message: 'message' }", + 'ok 12 getter is still the same', + '# throws null', + 'ok 13 throws null', + '# wrong type of error', + 'not ok 14 throws actual', + ' ---', + ' operator: throws', + ' expected: |-', + ' [Function: TypeError]', + ' actual: |-', + " { [RangeError: actual!] message: 'actual!' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' RangeError: actual!', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..14', + '# tests 14', + '# pass 4', + '# fail 10', + '' + ]); })); test('non functions', function (t) { diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index 5d198e2a..366b5d6f 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -23,8 +23,9 @@ tap.test('timeoutAfter test', function (tt) { '1..1', '# tests 1', '# pass 0', - '# fail 1' - ].join('\n') + '\n'); + '# fail 1', + '' + ]); }; test.createStream().pipe(concat(tc)); diff --git a/test/todo.js b/test/todo.js index 73a8f6a6..5b9351ee 100644 --- a/test/todo.js +++ b/test/todo.js @@ -10,24 +10,24 @@ tap.test('tape todo test', function (assert) { assert.plan(1); test.createStream().pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# success\n' - + 'ok 1 this test runs\n' - + '# TODO failure\n' - + 'not ok 2 should never happen # TODO\n' - + ' ---\n' - + ' operator: fail\n' - + ' at: Test. ($TEST/todo.js:$LINE:$COL)\n' - + ' ...\n' - + '\n' - + '1..2\n' - + '# tests 2\n' - + '# pass 2\n' - + '\n' - + '# ok\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# success', + 'ok 1 this test runs', + '# TODO failure', + 'not ok 2 should never happen # TODO', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/todo.js:$LINE:$COL)', + ' ...', + '', + '1..2', + '# tests 2', + '# pass 2', + '', + '# ok', + '' + ]); })); test('success', function (t) { diff --git a/test/todo_explanation.js b/test/todo_explanation.js index 5269b08f..225d584f 100644 --- a/test/todo_explanation.js +++ b/test/todo_explanation.js @@ -10,42 +10,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.equal( - 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', - '' - ].join('\n') - ); + assert.same(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/todo_single.js b/test/todo_single.js index 48cd287e..0359bcfa 100644 --- a/test/todo_single.js +++ b/test/todo_single.js @@ -10,24 +10,24 @@ tap.test('tape todo test', function (assert) { assert.plan(1); test.createStream().pipe(concat(function (body) { - assert.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# TODO failure\n' - + 'not ok 1 should be equal # TODO\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: false\n' - + ' actual: true\n' - + ' at: Test. ($TEST/todo_single.js:$LINE:$COL)\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 1\n' - + '\n' - + '# ok\n' - ); + assert.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# TODO failure', + 'not ok 1 should be equal # TODO', + ' ---', + ' operator: equal', + ' expected: false', + ' actual: true', + ' at: Test. ($TEST/todo_single.js:$LINE:$COL)', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok', + '' + ]); })); test('failure', { todo: true }, function (t) { diff --git a/test/too_many.js b/test/too_many.js index 946ceb8e..6ac3e164 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -37,8 +37,9 @@ tap.test('array test', function (tt) { '1..6', '# tests 6', '# pass 5', - '# fail 1' - ].join('\n') + '\n'); + '# fail 1', + '' + ]); }; test.createStream().pipe(concat(tc)); diff --git a/test/undef.js b/test/undef.js index 52759ac7..5b219d99 100644 --- a/test/undef.js +++ b/test/undef.js @@ -9,30 +9,30 @@ tap.test('array test', function (tt) { var test = tape.createHarness(); test.createStream().pipe(concat(function (body) { - tt.equal( - stripFullStack(body.toString('utf8')), - 'TAP version 13\n' - + '# undef\n' - + 'not ok 1 should be equivalent\n' - + ' ---\n' - + ' operator: deepEqual\n' - + ' expected: |-\n' - + ' { beep: undefined }\n' - + ' actual: |-\n' - + ' {}\n' - + ' at: Test. ($TEST/undef.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should be equivalent\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/undef.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# undef', + 'not ok 1 should be equivalent', + ' ---', + ' operator: deepEqual', + ' expected: |-', + ' { beep: undefined }', + ' actual: |-', + ' {}', + ' at: Test. ($TEST/undef.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/undef.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); })); test('undef', function (t) { From faa51b5baa709ba2e72f78be7cb7ce243c02a771 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 23 Dec 2019 13:06:54 -0800 Subject: [PATCH 14/30] [Tests] ensure bin/tape is linted --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 03c5e22f..f43a4d4c 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", "prelint": "eclint check", - "lint": "eslint .", + "lint": "eslint . bin/*", "pretest": "npm run lint", "test": "npm run tests-only", "posttest": "aud --production", From da8ca46cc0be28a3d4690a4009e0ddec7fc6f779 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 29 Dec 2019 09:58:10 -0800 Subject: [PATCH 15/30] [Refactor] generalize error message from calling `.end` more than once --- lib/test.js | 2 +- test/double_end.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/test.js b/lib/test.js index 9ce1082c..b44388bf 100644 --- a/lib/test.js +++ b/lib/test.js @@ -151,7 +151,7 @@ Test.prototype.end = function (err) { } if (this.calledEnd) { - this.fail('.end() called twice'); + this.fail('.end() already called'); } this.calledEnd = true; this._end(); diff --git a/test/double_end.js b/test/double_end.js index ff4618b3..f254ed35 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -39,12 +39,12 @@ test(function (t) { 'TAP version 13', '# double end', 'ok 1 should be equal', - 'not ok 2 .end() called twice', + 'not ok 2 .end() already called', ' ---', ' operator: fail', ' ' + atExpected, ' stack: |-', - ' Error: .end() called twice', + ' Error: .end() already called', ' [... stack stripped ...]', ' ' + stackExpected, ' [... stack stripped ...]', From 9dfb680e7543a3a701b3e410bfccbcce3b274d9f Mon Sep 17 00:00:00 2001 From: Aria Stewart Date: Sun, 29 Dec 2019 19:51:05 -0500 Subject: [PATCH 16/30] [Refactor] Avoid setting message property on primitives; use strict mode to catch this --- lib/test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index b44388bf..df4d0ec5 100644 --- a/lib/test.js +++ b/lib/test.js @@ -1,3 +1,5 @@ +'use strict'; + var deepEqual = require('deep-equal'); var defined = require('defined'); var path = require('path'); @@ -497,7 +499,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { fn(); } catch (err) { caught = { error: err }; - if ((err != null) && (!isEnumerable(err, 'message') || !has(err, 'message'))) { + if (Object(err) === err && (!isEnumerable(err, 'message') || !has(err, 'message'))) { var message = err.message; delete err.message; err.message = message; From 1461611bce87b190179d1ac0e2c69438f2b12f31 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 1 Jan 2020 13:58:43 -0800 Subject: [PATCH 17/30] [readme] remove long-dead testling-ci badge --- readme.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/readme.markdown b/readme.markdown index a3e456a8..4185a879 100644 --- a/readme.markdown +++ b/readme.markdown @@ -2,8 +2,6 @@ tap-producing test harness for node and browsers -[![browser support](https://ci.testling.com/substack/tape.png)](http://ci.testling.com/substack/tape) - [![build status](https://secure.travis-ci.org/substack/tape.svg?branch=master)](http://travis-ci.org/substack/tape) ![tape](https://web.archive.org/web/20170612184731if_/http://substack.net/images/tape_drive.png) From 6bb34964abb1e704fe3dcc9fcf8d27d16ff5e296 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 3 Jan 2021 13:26:23 -0800 Subject: [PATCH 18/30] [meta] do not publish github action workflow files --- .npmignore | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..f156b8d7 --- /dev/null +++ b/.npmignore @@ -0,0 +1,13 @@ +# gitignore + +/node_modules + +# Only apps should have lockfiles +yarn.lock +package-lock.json + +# coverage data +coverage/ +.nyc_output/ + +.github/workflows From 57a7cc906ec4f24f503350580c5859e5b3e56805 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 5 May 2021 08:46:43 -0700 Subject: [PATCH 19/30] [readme] remove travis badge; add actions and codecov badges --- readme.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 4185a879..df3e0676 100644 --- a/readme.markdown +++ b/readme.markdown @@ -2,7 +2,8 @@ tap-producing test harness for node and browsers -[![build status](https://secure.travis-ci.org/substack/tape.svg?branch=master)](http://travis-ci.org/substack/tape) +[![github actions][actions-image]][actions-url] +[![coverage][codecov-image]][codecov-url] ![tape](https://web.archive.org/web/20170612184731if_/http://substack.net/images/tape_drive.png) @@ -403,3 +404,8 @@ npm install tape --save-dev # license MIT + +[codecov-image]: https://codecov.io/gh/substack/tape/branch/master/graphs/badge.svg +[codecov-url]: https://app.codecov.io/gh/substack/tape/ +[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/substack/tape +[actions-url]: https://github.com/substack/tape/actions From 2a0619d3193287aaa948fc4edf0bb2ccb4150a7b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 5 May 2021 09:04:33 -0700 Subject: [PATCH 20/30] =?UTF-8?q?[meta]=20ensure=20`not-in-publish`?= =?UTF-8?q?=E2=80=98s=20absence=20does=20not=20fail=20anything?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f43a4d4c..aa064336 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ }, "scripts": { "prepublishOnly": "safe-publish-latest", - "prepublish": "not-in-publish || npm run prepublishOnly", + "prepublish": "!(type not-in-publish) || not-in-publish || npm run prepublishOnly", "prelint": "eclint check", "lint": "eslint . bin/*", "pretest": "npm run lint", From d81f9f6681ae72d3425b91e2f7a294e6d4225675 Mon Sep 17 00:00:00 2001 From: Yves Darmaillac Date: Fri, 2 Jul 2021 15:14:39 +0200 Subject: [PATCH 21/30] [readme] Another way to create custom reporters --- readme.markdown | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/readme.markdown b/readme.markdown index df3e0676..57f500f6 100644 --- a/readme.markdown +++ b/readme.markdown @@ -393,6 +393,20 @@ $ node object.js test/x.js test/y.js {"type":"end","test":2} ``` +A convenient alternative to achieve the same: +```js +// report.js +var test = require('tape'); + +test.createStream({ objectMode: true }).on('data', function (row) { + console.log(JSON.stringify(row)) // for example +}); +``` +and then: +```sh +$ tape -r ./report.js **/*.test.js +``` + # install With [npm](https://npmjs.org) do: From 967b73fe882e9c95c0436e6ce93f24fa3a2e14a9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 4 Jan 2021 11:48:30 -0800 Subject: [PATCH 22/30] [Refactor] use `call-bind/callBound` instead of `function-bind` directly --- lib/results.js | 4 ++-- lib/test.js | 8 ++++---- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/results.js b/lib/results.js index d4bf0ab2..3299fbc8 100644 --- a/lib/results.js +++ b/lib/results.js @@ -4,9 +4,9 @@ var inherits = require('inherits'); var through = require('through'); var resumer = require('resumer'); var inspect = require('object-inspect'); -var bind = require('function-bind'); +var callBound = require('call-bind/callBound'); var has = require('has'); -var regexpTest = bind.call(Function.call, RegExp.prototype.test); +var regexpTest = callBound('RegExp.prototype.test'); var yamlIndicators = /:|-|\?/; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate diff --git a/lib/test.js b/lib/test.js index df4d0ec5..6a1c488d 100644 --- a/lib/test.js +++ b/lib/test.js @@ -8,12 +8,12 @@ var EventEmitter = require('events').EventEmitter; var has = require('has'); var isRegExp = require('is-regex'); var trim = require('string.prototype.trim'); -var bind = require('function-bind'); +var callBound = require('call-bind/callBound'); var forEach = require('for-each'); var inspect = require('object-inspect'); -var isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable); -var toLowerCase = bind.call(Function.call, String.prototype.toLowerCase); -var $test = bind.call(Function.call, RegExp.prototype.test); +var isEnumerable = callBound('Object.prototype.propertyIsEnumerable'); +var toLowerCase = callBound('String.prototype.toLowerCase'); +var $test = callBound('RegExp.prototype.test'); module.exports = Test; diff --git a/package.json b/package.json index aa064336..bc85faab 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,11 @@ "test": "test" }, "dependencies": { + "call-bind": "~1.0.2", "deep-equal": "~1.1.1", "defined": "~1.0.0", "dotignore": "~0.1.2", "for-each": "~0.3.3", - "function-bind": "~1.1.1", "glob": "~7.1.7", "has": "~1.0.3", "inherits": "~2.0.4", From 283f537f56885d18afbc2328c0c52ee60d528332 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 5 May 2021 09:30:13 -0700 Subject: [PATCH 23/30] [Tests] exclude examples from coverage --- example/{throw.js => throw_fail.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename example/{throw.js => throw_fail.js} (100%) diff --git a/example/throw.js b/example/throw_fail.js similarity index 100% rename from example/throw.js rename to example/throw_fail.js From b36f81698fbf4d172a49abb75b9474c4a978df5c Mon Sep 17 00:00:00 2001 From: Carl Gross Date: Tue, 26 Jan 2021 19:43:37 +0700 Subject: [PATCH 24/30] [readme] improve `t.throws` documentation * Added usage example for when expected parameter is a validation object. See #540. --- readme.markdown | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 57f500f6..fea21764 100644 --- a/readme.markdown +++ b/readme.markdown @@ -270,7 +270,48 @@ Aliases: `t.notLooseEqual()`, `t.notLooseEquals()` ## t.throws(fn, expected, msg) -Assert that the function call `fn()` throws an exception. `expected`, if present, must be a `RegExp` or `Function`. The `RegExp` matches the string representation of the exception, as generated by `err.toString()`. The `Function` is the exception thrown (e.g. `Error`). `msg` is an optional description of the assertion. +Assert that the function call `fn()` throws an exception. `expected`, if present, must be a `RegExp`, `Function`, or `Object`. The `RegExp` matches the string representation of the exception, as generated by `err.toString()`. For example, if you set `expected` to `/user/`, the test will pass only if the string representation of the exception contains the word `user`. Any other exception will result in a failed test. The `Function` is the exception thrown (e.g. `Error`). `Object` in this case corresponds to a so-called validation object, in which each property is tested for strict deep equality. As an example, see the following two tests--each passes a validation object to `t.throws()` as the second parameter. The first test will pass, because all property values in the actual error object are deeply strictly equal to the property values in the validation object. +``` + const err = new TypeError("Wrong value"); + err.code = 404; + err.check = true; + + // Passing test. + t.throws( + () => { + throw err; + }, + { + code: 404, + check: true + }, + "Test message." + ); +``` +This next test will fail, because all property values in the actual error object are _not_ deeply strictly equal to the property values in the validation object. +``` + const err = new TypeError("Wrong value"); + err.code = 404; + err.check = "true"; + + // Failing test. + t.throws( + () => { + throw err; + }, + { + code: 404, + check: true // This is not deeply strictly equal to err.check. + }, + "Test message." + ); +``` + +This is very similar to how Node's `assert.throws()` method tests validation objects (please see the [Node _assert.throws()_ documentation](https://nodejs.org/api/assert.html#assert_assert_throws_fn_error_message) for more information). + +If `expected` is not of type `RegExp`, `Function`, or `Object`, or omitted entirely, any exception will result in a passed test. `msg` is an optional description of the assertion. + +Please note that the second parameter, `expected`, cannot be of type `string`. If a value of type `string` is provided for `expected`, then `t.throws(fn, expected, msg)` will execute, but the value of `expected` will be set to `undefined`, and the specified string will be set as the value for the `msg` parameter (regardless of what _actually_ passed as the third parameter). This can cause unexpected results, so please be mindful. ## t.doesNotThrow(fn, expected, msg) From a04439c3027f3dc0dac8cf8ef5d24a493366be6a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 24 Jul 2021 09:15:12 -0700 Subject: [PATCH 25/30] [Refactor] remove use of legacy `exports` --- index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7ab29516..ad4dc251 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,8 @@ var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' ; -exports = module.exports = (function () { +module.exports = (function () { + var wait = false; var harness; var lazyLoad = function () { return getHarness().apply(this, arguments); @@ -90,10 +91,10 @@ function createExitHarness(conf) { return harness; } -exports.createHarness = createHarness; -exports.Test = Test; -exports.test = exports; // tap compat -exports.test.skip = Test.skip; +module.exports.createHarness = createHarness; +module.exports.Test = Test; +module.exports.test = module.exports; // tap compat +module.exports.test.skip = Test.skip; function createHarness(conf_) { if (!conf_) conf_ = {}; From da0cdf1651fec20f66a6bed2d1b17944e18dcd48 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 24 Jul 2021 09:17:01 -0700 Subject: [PATCH 26/30] [Refactor] remove unused line, unneeded var initialization; add missing `new` --- lib/test.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/test.js b/lib/test.js index 6a1c488d..b5a6b08a 100644 --- a/lib/test.js +++ b/lib/test.js @@ -146,8 +146,7 @@ Test.prototype.timeoutAfter = function (ms) { }); }; -Test.prototype.end = function (err) { - var self = this; +Test.prototype.end = function end(err) { if (arguments.length >= 1 && !!err) { this.ifError(err); } @@ -493,7 +492,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { expected = undefined; } - var caught = undefined; + var caught; try { fn(); @@ -532,11 +531,10 @@ Test.prototype.doesNotThrow = function (fn, expected, msg, extra) { msg = expected; expected = undefined; } - var caught = undefined; + var caught; try { fn(); - } - catch (err) { + } catch (err) { caught = { error: err }; } this._assert(!caught, { @@ -595,7 +593,7 @@ Test.prototype.doesNotMatch = function doesNotMatch(string, regexp, msg, extra) Test.skip = function (name_, _opts, _cb) { var args = getTestArgs.apply(null, arguments); args.opts.skip = true; - return Test(args.name, args.opts, args.cb); + return new Test(args.name, args.opts, args.cb); }; // vim: set softtabstop=4 shiftwidth=4: From 5c4052fcf51479320c9482c425a66dcbcc4a509a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 24 Jul 2021 13:23:57 -0700 Subject: [PATCH 27/30] [Refactor] avoid reassigning arguments --- index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index ad4dc251..839cd20d 100644 --- a/index.js +++ b/index.js @@ -23,13 +23,13 @@ module.exports = (function () { }; lazyLoad.createStream = function (opts) { - if (!opts) opts = {}; + var options = opts || {}; if (!harness) { var output = through(); - getHarness({ stream: output, objectMode: opts.objectMode }); + getHarness({ stream: output, objectMode: options.objectMode }); return output; } - return harness.createStream(opts); + return harness.createStream(options); }; lazyLoad.onFinish = function () { @@ -53,9 +53,9 @@ module.exports = (function () { })(); function createExitHarness(conf) { - if (!conf) conf = {}; + var config = conf || {}; var harness = createHarness({ - autoclose: defined(conf.autoclose, false) + autoclose: defined(config.autoclose, false) }); var stream = harness.createStream({ objectMode: conf.objectMode }); @@ -67,7 +67,7 @@ function createExitHarness(conf) { var ended = false; stream.on('end', function () { ended = true; }); - if (conf.exit === false) return harness; + if (config.exit === false) return harness; if (!canEmitExit || !canExit) return harness; process.on('exit', function (code) { @@ -97,9 +97,8 @@ module.exports.test = module.exports; // tap compat module.exports.test.skip = Test.skip; function createHarness(conf_) { - if (!conf_) conf_ = {}; var results = createResult(); - if (conf_.autoclose !== false) { + if (!conf_ || conf_.autoclose !== false) { results.once('done', function () { results.close(); }); } From 1020639f7f4bf76492b52d3b046754aa15edb4e4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 13 Feb 2021 14:02:58 -0800 Subject: [PATCH 28/30] [New] add `.teardown()` on `t` instances (#546) Fixes #531. Co-authored-by: Matteo Collina Co-authored-by: Jordan Harband --- lib/test.js | 59 +++++++++-- package.json | 4 +- readme.markdown | 4 + test/common.js | 8 ++ test/teardown.js | 267 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 332 insertions(+), 10 deletions(-) create mode 100644 test/teardown.js diff --git a/lib/test.js b/lib/test.js index b5a6b08a..b002a67f 100644 --- a/lib/test.js +++ b/lib/test.js @@ -61,6 +61,7 @@ function Test(name_, opts_, cb_) { this._plan = undefined; this._cb = args.cb; this._progeny = []; + this._teardown = []; this._ok = true; var depthEnvVar = process.env.NODE_TAPE_OBJECT_PRINT_DEPTH; if (args.opts.objectPrintDepth) { @@ -158,6 +159,14 @@ Test.prototype.end = function end(err) { this._end(); }; +Test.prototype.teardown = function (fn) { + if (typeof fn !== 'function') { + this.fail('teardown: ' + inspect(fn) + ' is not a function'); + } else { + this._teardown.push(fn); + } +}; + Test.prototype._end = function (err) { var self = this; if (this._progeny.length) { @@ -167,16 +176,48 @@ Test.prototype._end = function (err) { return; } - if (!this.ended) this.emit('end'); - var pendingAsserts = this._pendingAsserts(); - if (!this._planError && this._plan !== undefined && pendingAsserts) { - this._planError = true; - this.fail('plan != count', { - expected: this._plan, - actual: this.assertCount - }); + + function next(i) { + if (i === self._teardown.length) { + completeEnd(); + return; + } + var fn = self._teardown[i]; + var res; + try { + res = fn(); + } catch (e) { + self.fail(e); + } + if (res && typeof res.then === 'function') { + res.then(function () { + next(++i); + }, function (_err) { + err = err || _err; + }); + } else { + next(++i); + } + } + + if (this._teardown.length > 0) { + next(0); + } else { + completeEnd(); + } + + function completeEnd() { + if (!self.ended) self.emit('end'); + var pendingAsserts = self._pendingAsserts(); + if (!self._planError && self._plan !== undefined && pendingAsserts) { + self._planError = true; + self.fail('plan != count', { + expected: self._plan, + actual: self.assertCount + }); + } + self.ended = true; } - this.ended = true; }; Test.prototype._exit = function () { diff --git a/package.json b/package.json index bc85faab..1b8c6ab0 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,12 @@ "through": "~2.3.8" }, "devDependencies": { - "aud": "~1.1.5", + "array.prototype.flatmap": "^1.2.4", + "aud": "^1.1.5", "concat-stream": "^1.6.2", "eclint": "^2.8.1", "ecstatic": "^4.1.4", + "es-value-fixtures": "^1.2.1", "eslint": "^7.31.0", "falafel": "^2.2.4", "js-yaml": "^3.14.0", diff --git a/readme.markdown b/readme.markdown index fea21764..3288a82c 100644 --- a/readme.markdown +++ b/readme.markdown @@ -165,6 +165,10 @@ don't call `t.end()` explicitly, your test will hang. Generate a new test that will be skipped over. +## test.teardown(cb) + +Register a callback to run after the individual test has completed. Multiple registered teardown callbacks will run in order. Useful for undoing side effects, closing network connections, etc. + ## test.onFinish(fn) The onFinish hook will get invoked when ALL `tape` tests have finished diff --git a/test/common.js b/test/common.js index 3f6bab84..8188fe65 100644 --- a/test/common.js +++ b/test/common.js @@ -65,5 +65,13 @@ module.exports.stripFullStack = function (output) { // Handle stack trace variation in Node v0.8 /at(:?) Test\.(?:module\.exports|tap\.test\.err\.code)/g, 'at$1 Test.' + ).replace( + // Handle stack trace variation in Node v0.8 + /at(:?) (Test\.)?tap\.test\.test\.skip/g, + 'at$1 $2' + ).replace( + // Handle stack trace variation in Node v0.8 + /(\[\.\.\. stack stripped \.\.\.\]\n *at) \(([^)]+)\)/g, + '$1 $2' ).split('\n'); }; diff --git a/test/teardown.js b/test/teardown.js new file mode 100644 index 00000000..51f16498 --- /dev/null +++ b/test/teardown.js @@ -0,0 +1,267 @@ +'use strict'; + +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); +var forEach = require('for-each'); +var v = require('es-value-fixtures'); +var inspect = require('object-inspect'); +var flatMap = require('array.prototype.flatmap'); + +var stripFullStack = require('./common').stripFullStack; + +tap.test('teardowns', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [].concat( + 'TAP version 13', + '# success', + 'ok 1 should be truthy', + '# success teardown', + '# success teardown 2', + '# success (async)', + 'ok 2 should be truthy', + '# success (async) teardown', + '# success (async) teardown 2', + '# nested teardowns', + '# nested success', + 'ok 3 should be truthy', + '# nested teardown (nested success level)', + '# nested teardown (nested success level) 2', + '# nested failure', + 'not ok 4 nested failure!', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/teardown.js:$LINE:$COL)', + ' stack: |-', + ' Error: nested failure!', + ' [... stack stripped ...]', + ' at Test. ($TEST/teardown.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# nested teardown (nested fail level)', + '# nested teardown (nested fail level) 2', + '# nested teardown (top level)', + '# nested teardown (top level) 2', + '# fail', + 'not ok 5 failure!', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/teardown.js:$LINE:$COL)', + ' stack: |-', + ' Error: failure!', + ' [... stack stripped ...]', + ' at Test. ($TEST/teardown.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# failure teardown', + '# failure teardown 2', + '# teardown errors do not stop the next teardown fn from running', + 'ok 6 should be truthy', + 'not ok 7 SyntaxError: teardown error!', + ' ---', + ' operator: fail', + ' stack: |-', + ' Error: SyntaxError: teardown error!', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 plan != count', + ' ---', + ' operator: fail', + ' expected: 1', + ' actual: 2', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' ...', + '# teardown runs after teardown error', + '# teardown given non-function fails the test', + 'ok 9 should be truthy', + flatMap(v.nonFunctions, function (nonFunction, i) { + var offset = 10; + return [].concat( + 'not ok ' + (offset + (i > 0 ? i + 1 : i)) + ' teardown: ' + inspect(nonFunction) + ' is not a function', + ' ---', + ' operator: fail', + ' at: ($TEST/teardown.js:$LINE:$COL)', + ' stack: |-', + ' Error: teardown: ' + inspect(nonFunction) + ' is not a function', + ' [... stack stripped ...]', + ' at $TEST/teardown.js:$LINE:$COL', + ' [... stack stripped ...]', + ' at Test. ($TEST/teardown.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + i > 0 ? [] : [ + 'not ok '+ (offset + 1) +' plan != count', + ' ---', + ' operator: fail', + ' expected: 1', + ' actual: 2', + ' at: ($TEST/teardown.js:$LINE:$COL)', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' at $TEST/teardown.js:$LINE:$COL', + ' [... stack stripped ...]', + ' at Test. ($TEST/teardown.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...' + ] + ); + }), + typeof Promise === 'function' ? [ + '# success (promise)', + 'ok ' + (11 + v.nonFunctions.length) + ' should be truthy', + '# success (promise) teardown: 1', + '# success (promise) teardown: 2', + '# success (promise) teardown: 3' + ] : [ + '# SKIP success (promise)' + ], [ + '', + '1..' + ((typeof Promise === 'function' ? 1 : 0) + 10 + v.nonFunctions.length), + '# tests ' + ((typeof Promise === 'function' ? 1 : 0) + 10 + v.nonFunctions.length), + '# pass ' + ((typeof Promise === 'function' ? 1 : 0) + 5), + '# fail ' + (5 + v.nonFunctions.length), + '' + ])); + })); + + test('success', function (t) { + t.plan(1); + t.teardown(function () { + t.comment('success teardown'); + }); + t.teardown(function () { + t.comment('success teardown 2'); + }); + t.ok('success!'); + }); + + test('success (async)', function (t) { + t.plan(1); + t.teardown(function () { + t.comment('success (async) teardown'); + }); + t.teardown(function () { + t.comment('success (async) teardown 2'); + }); + setTimeout(function () { + t.ok('success!'); + }, 10); + }); + + test('nested teardowns', function (t) { + t.plan(2); + + t.teardown(function () { + t.comment('nested teardown (top level)'); + }); + t.teardown(function () { + t.comment('nested teardown (top level) 2'); + }); + + t.test('nested success', function (st) { + st.teardown(function () { + st.comment('nested teardown (nested success level)'); + }); + st.teardown(function () { + st.comment('nested teardown (nested success level) 2'); + }); + + st.ok('nested success!'); + st.end(); + }); + + t.test('nested failure', function (st) { + st.plan(1); + + st.teardown(function () { + st.comment('nested teardown (nested fail level)'); + }); + st.teardown(function () { + st.comment('nested teardown (nested fail level) 2'); + }); + + st.fail('nested failure!'); + }); + }); + + test('fail', function (t) { + t.plan(1); + + t.teardown(function () { + t.comment('failure teardown'); + }); + t.teardown(function () { + t.comment('failure teardown 2'); + }); + + t.fail('failure!'); + }); + + test('teardown errors do not stop the next teardown fn from running', function (t) { + t.plan(1); + + t.ok('teardown error test'); + + t.teardown(function () { + throw new SyntaxError('teardown error!'); + }); + t.teardown(function () { + t.comment('teardown runs after teardown error'); + }); + }); + + test('teardown given non-function fails the test', function (t) { + t.plan(1); + + t.ok('non-function test'); + + forEach(v.nonFunctions, function (nonFunction) { + t.teardown(nonFunction); + }); + }); + + test('success (promise)', { skip: typeof Promise !== 'function' }, function (t) { + t.plan(1); + + t.teardown(function () { + return new Promise(function (resolve) { + t.comment('success (promise) teardown: 1'); + setTimeout(resolve, 10); + }).then(function () { + t.comment('success (promise) teardown: 2'); + }); + }); + t.teardown(function () { + t.comment('success (promise) teardown: 3'); + }); + + setTimeout(function () { + t.ok('success!'); + }, 10); + }); +}); + +tap.test('teardown with promise', { skip: typeof Promise !== 'function', timeout: 1e3 }, function (tt) { + tt.plan(2); + tape('dummy test', function (t) { + var resolved = false; + t.teardown(function () { + tt.pass('tape teardown'); + var p = Promise.resolve(); + p.then(function () { + resolved = true; + }); + return p; + }); + t.on('end', function () { + tt.is(resolved, true); + }); + t.end(); + }); +}); From 836610d9772b91a8d31f311834ae1325f2f740bf Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jul 2021 22:27:32 -0700 Subject: [PATCH 29/30] [eslint] fully enable `@ljharb` eslint config --- .eslintrc | 128 +++++++++++++++++++++++++++--- bin/tape | 9 +-- example/array.js | 12 +-- example/fail.js | 6 +- example/nested.js | 18 +++-- example/nested_fail.js | 6 +- example/not_enough.js | 6 +- example/static/server.js | 2 + example/stream/object.js | 2 + example/stream/tap.js | 2 + example/stream/test/x.js | 2 + example/stream/test/y.js | 4 +- example/timing.js | 6 +- example/too_many.js | 18 +++-- example/two.js | 6 +- index.js | 34 ++++---- lib/default_stream.js | 28 ++++--- lib/results.js | 67 +++++++++------- lib/test.js | 36 +++++---- package.json | 1 + test/add-subtest-async.js | 2 + test/anonymous-fn.js | 2 + test/anonymous-fn/test-wrapper.js | 2 + test/array.js | 20 ++--- test/bound.js | 2 + test/browser/asserts.js | 8 +- test/child_ordering.js | 32 ++++---- test/circular-things.js | 2 + test/comment.js | 9 ++- test/common.js | 2 + test/create_multiple_streams.js | 7 +- test/deep-equal-failure.js | 6 +- test/deep.js | 10 ++- test/double_end.js | 7 +- test/double_end/double.js | 2 + test/end-as-callback.js | 13 ++- test/error.js | 2 +- test/exit.js | 4 +- test/exit/fail.js | 20 ++--- test/exit/ok.js | 20 ++--- test/exit/second.js | 2 + test/exit/todo.js | 2 + test/exit/todo_fail.js | 2 + test/exit/too_few.js | 20 ++--- test/exposed-harness.js | 2 + test/fail.js | 20 ++--- test/has spaces.js | 2 + test/ignore_from_gitignore.js | 8 +- test/many.js | 2 + test/match.js | 8 +- test/max_listeners.js | 2 + test/max_listeners/source.js | 9 ++- test/nested-async-plan-noend.js | 2 + test/nested-sync-noplan-noend.js | 2 + test/nested.js | 20 ++--- test/nested2.js | 13 +-- test/no_callback.js | 2 + test/not-deep-equal-failure.js | 6 +- test/not-equal-failure.js | 2 + test/objectMode.js | 28 ++++--- test/onFailure.js | 8 +- test/onFinish.js | 4 +- test/only-twice.js | 4 +- test/only.js | 4 +- test/only2.js | 2 + test/only3.js | 2 + test/only4.js | 2 + test/only5.js | 2 + test/order.js | 2 + test/plan_optional.js | 2 + test/require.js | 5 +- test/require/a.js | 2 + test/require/b.js | 2 + test/require/test-a.js | 2 + test/require/test-b.js | 2 + test/skip.js | 12 ++- test/skip_explanation.js | 5 +- test/stackTrace.js | 37 ++++----- test/subcount.js | 14 ++-- test/subtest_and_async.js | 2 + test/subtest_plan.js | 16 ++-- test/teardown.js | 8 +- test/throws.js | 47 ++++++----- test/timeout.js | 2 + test/timeoutAfter.js | 2 + test/todo.js | 2 + test/todo_explanation.js | 4 +- test/todo_single.js | 2 + test/too_many.js | 20 ++--- test/undef.js | 2 + 90 files changed, 611 insertions(+), 328 deletions(-) diff --git a/.eslintrc b/.eslintrc index 5cc84b03..0f0ffc01 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,16 +1,124 @@ { "root": true, + "env": { + "browser": true, + "node": true, + }, + "extends": "@ljharb", + "globals": { + "Promise": false, + }, "rules": { + "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-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-param-reassign": "warn", + "no-negated-condition": "off", + "no-use-before-define": "warn", + "no-underscore-dangle": "warn", + "operator-linebreak": ["error", "before"], + "sort-keys": "warn", }, + "ignorePatterns": [ "syntax-error.*" ], + "overrides": [ + { + "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": { + "ecmaVersion": 2017, + }, + }, + { + "files": ["example/**", "test/**"], + "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/tape b/bin/tape index 3ea1cec5..a0c755a1 100755 --- a/bin/tape +++ b/bin/tape @@ -1,5 +1,7 @@ #!/usr/bin/env node +'use strict'; + var resolveModule = require('resolve').sync; var resolvePath = require('path').resolve; var readFileSync = require('fs').readFileSync; @@ -21,9 +23,7 @@ if (typeof opts.require === 'string') { opts.require.forEach(function (module) { if (module) { - /* This check ensures we ignore `-r ""`, trailing `-r`, or - * other silly things the user might (inadvertently) be doing. - */ + // This check ensures we ignore `-r ""`, trailing `-r`, or other silly things the user might (inadvertently) be doing. require(resolveModule(module, { basedir: cwd })); } }); @@ -39,8 +39,7 @@ if (typeof opts.ignore === 'string') { } opts._.forEach(function (arg) { - // If glob does not match, `files` will be an empty array. - // Note: `glob.sync` may throw an error and crash the node process. + // 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); if (!Array.isArray(files)) { diff --git a/example/array.js b/example/array.js index bec161f4..40be4847 100644 --- a/example/array.js +++ b/example/array.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var test = require('../'); @@ -17,13 +19,13 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[ 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 a0db0b11..4373c76b 100644 --- a/example/fail.js +++ b/example/fail.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var test = require('../'); @@ -20,10 +22,10 @@ test('array', function (t) { [ 3, 4 ], [ 1, 2, [ 3, 4 ] ], [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [ [ 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.js b/example/nested.js index 2a36f25e..299f6bb4 100644 --- a/example/nested.js +++ b/example/nested.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var test = require('../'); @@ -5,8 +7,8 @@ test('nested array test', function (t) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; g([ xs, ys ]); } + ')()'; @@ -26,19 +28,19 @@ test('nested array test', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[ 1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/example/nested_fail.js b/example/nested_fail.js index ba168c7e..44ea3fd1 100644 --- a/example/nested_fail.js +++ b/example/nested_fail.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var test = require('../'); @@ -29,10 +31,10 @@ test('nested array test', function (t) { [ 3, 4 ], [ 1, 2, [ 3, 4 ] ], [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [ [ 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/not_enough.js b/example/not_enough.js index fffc714f..e50ccac3 100644 --- a/example/not_enough.js +++ b/example/not_enough.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var test = require('../'); @@ -20,10 +22,10 @@ test('array', function (t) { [ 3, 4 ], [ 1, 2, [ 3, 4 ] ], [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [ [ 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/static/server.js b/example/static/server.js index 80cea43d..6b1e3532 100644 --- a/example/static/server.js +++ b/example/static/server.js @@ -1,3 +1,5 @@ +'use strict'; + var http = require('http'); var ecstatic = require('ecstatic')(__dirname); var server = http.createServer(ecstatic); diff --git a/example/stream/object.js b/example/stream/object.js index 20f0819f..39c662ce 100644 --- a/example/stream/object.js +++ b/example/stream/object.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../../'); var path = require('path'); diff --git a/example/stream/tap.js b/example/stream/tap.js index 9ea9ff74..53d7e232 100644 --- a/example/stream/tap.js +++ b/example/stream/tap.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../../'); var path = require('path'); diff --git a/example/stream/test/x.js b/example/stream/test/x.js index 7dbb98ad..670baa56 100644 --- a/example/stream/test/x.js +++ b/example/stream/test/x.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../../../'); test(function (t) { t.plan(1); diff --git a/example/stream/test/y.js b/example/stream/test/y.js index 28606d51..0a0928f2 100644 --- a/example/stream/test/y.js +++ b/example/stream/test/y.js @@ -1,7 +1,9 @@ +'use strict'; + var test = require('../../../'); test(function (t) { t.plan(2); - t.equal(1+1, 2); + t.equal(1 + 1, 2); t.ok(true); }); diff --git a/example/timing.js b/example/timing.js index 614c1441..4754776f 100644 --- a/example/timing.js +++ b/example/timing.js @@ -1,12 +1,14 @@ +'use strict'; + var test = require('../'); test('timing test', function (t) { t.plan(2); t.equal(typeof Date.now, 'function'); - var start = new Date; + var start = new Date(); setTimeout(function () { - t.equal(new Date - start, 100); + t.equal(new Date() - start, 100); }, 100); }); diff --git a/example/too_many.js b/example/too_many.js index cdcb5ee9..2ae76502 100644 --- a/example/too_many.js +++ b/example/too_many.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var test = require('../'); @@ -5,8 +7,8 @@ test('array', function (t) { t.plan(3); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; g([ xs, ys ]); } + ')()'; @@ -17,19 +19,19 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/example/two.js b/example/two.js index 78e49c37..de5b213a 100644 --- a/example/two.js +++ b/example/two.js @@ -1,16 +1,18 @@ +'use strict'; + var test = require('../'); 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 839cd20d..7e402af3 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +'use strict'; + var defined = require('defined'); var createDefaultStream = require('./lib/default_stream'); var Test = require('./lib/test'); @@ -5,16 +7,14 @@ 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); }; @@ -45,12 +45,12 @@ module.exports = (function () { return lazyLoad; function getHarness(opts) { - if (!opts) opts = {}; + if (!opts) { opts = {}; } opts.autoclose = !canEmitExit; - if (!harness) harness = createExitHarness(opts); + if (!harness) { harness = createExitHarness(opts); } return harness; } -})(); +}()); function createExitHarness(conf) { var config = conf || {}; @@ -61,14 +61,15 @@ function createExitHarness(conf) { var stream = harness.createStream({ objectMode: conf.objectMode }); var es = stream.pipe(conf.stream || createDefaultStream()); if (canEmitExit) { + // eslint-disable-next-line no-unused-vars es.on('error', function (err) { harness._exitCode = 1; }); } var ended = false; stream.on('end', function () { ended = true; }); - 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. @@ -80,12 +81,13 @@ function createExitHarness(conf) { 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.exit(code || harness._exitCode); + process.exit(code || harness._exitCode); // eslint-disable-line no-process-exit }); return harness; @@ -111,9 +113,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; @@ -136,7 +138,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 2744258a..9e6372ec 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -1,3 +1,5 @@ +'use strict'; + var through = require('through'); var fs = require('fs'); @@ -10,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 3299fbc8..29d8e242 100644 --- a/lib/results.js +++ b/lib/results.js @@ -1,3 +1,5 @@ +'use strict'; + var defined = require('defined'); var EventEmitter = require('events').EventEmitter; var inherits = require('inherits'); @@ -8,11 +10,7 @@ var callBound = require('call-bind/callBound'); var has = require('has'); var regexpTest = callBound('RegExp.prototype.test'); var yamlIndicators = /:|-|\?/; -var nextTick = typeof setImmediate !== 'undefined' - ? setImmediate - : process.nextTick -; - +var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick; module.exports = Results; inherits(Results, EventEmitter); @@ -21,7 +19,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; @@ -33,13 +31,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 = { @@ -81,7 +80,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'); }); @@ -106,8 +108,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'); }); @@ -117,11 +122,12 @@ Results.prototype._watch = function (t) { return; } write(encodeResult(res, self.count + 1)); - self.count ++; + self.count++; - if (res.ok || res.todo) self.pass ++; - else { - self.fail ++; + if (res.ok || res.todo) { + self.pass++; + } else { + self.fail++; self.emit('fail'); } }); @@ -131,16 +137,20 @@ 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); }; @@ -151,13 +161,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 + ' '; @@ -165,8 +175,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'; @@ -202,11 +212,12 @@ function getNextTest(results) { do { var t = results.tests.shift(); - 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 b002a67f..94fb175c 100644 --- a/lib/test.js +++ b/lib/test.js @@ -25,6 +25,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 = {}; @@ -41,11 +42,15 @@ 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_) { - if (! (this instanceof Test)) { + if (!(this instanceof Test)) { return new Test(name_, opts_, cb_); } @@ -84,14 +89,15 @@ function Test(name_, opts_, cb_) { }; } return val; - })(this, this[prop]); + }(this, this[prop])); } } -Test.prototype.run = function () { +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); @@ -136,7 +142,7 @@ Test.prototype.plan = function (n) { }; Test.prototype.timeoutAfter = function (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'); @@ -176,7 +182,6 @@ Test.prototype._end = function (err) { return; } - function next(i) { if (i === self._teardown.length) { completeEnd(); @@ -207,7 +212,7 @@ Test.prototype._end = function (err) { } 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; @@ -221,8 +226,7 @@ Test.prototype._end = function (err) { }; Test.prototype._exit = function () { - if (this._plan !== undefined && - !this._planError && this.assertCount !== this._plan) { + if (this._plan !== undefined && !this._planError && this.assertCount !== this._plan) { this._planError = true; this.fail('plan != count', { expected: this._plan, @@ -326,12 +330,11 @@ Test.prototype._assert = function assert(ok, opts) { continue; } - // Function call description may not (just) be a function name. - // Try to extract function name by looking at first "word" only. + // Function call description may not (just) be a function name. Try to extract function name by looking at first "word" only. res.functionName = callDescription.split(/\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; @@ -385,7 +388,7 @@ Test.prototype.skip = function (msg, extra) { }); }; -function assert(value, msg, extra) { +var tapeAssert = function assert(value, msg, extra) { this._assert(value, { message: defined(msg, 'should be truthy'), operator: 'ok', @@ -393,11 +396,11 @@ function assert(value, msg, extra) { actual: value, extra: extra }); -} +}; Test.prototype.ok = Test.prototype['true'] = Test.prototype.assert -= assert; += tapeAssert; function notOK(value, msg, extra) { this._assert(!value, { @@ -631,6 +634,7 @@ Test.prototype.doesNotMatch = function doesNotMatch(string, regexp, msg, extra) }); }; +// eslint-disable-next-line no-unused-vars Test.skip = function (name_, _opts, _cb) { var args = getTestArgs.apply(null, arguments); args.opts.skip = true; diff --git a/package.json b/package.json index 1b8c6ab0..f1aea39e 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "through": "~2.3.8" }, "devDependencies": { + "@ljharb/eslint-config": "^17.6.0", "array.prototype.flatmap": "^1.2.4", "aud": "^1.1.5", "concat-stream": "^1.6.2", diff --git a/test/add-subtest-async.js b/test/add-subtest-async.js index 12b2e2d3..9d13d44e 100644 --- a/test/add-subtest-async.js +++ b/test/add-subtest-async.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('parent', function (t) { diff --git a/test/anonymous-fn.js b/test/anonymous-fn.js index f28c4340..9a73ed8a 100644 --- a/test/anonymous-fn.js +++ b/test/anonymous-fn.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); diff --git a/test/anonymous-fn/test-wrapper.js b/test/anonymous-fn/test-wrapper.js index 38e8ba1a..f79ef485 100644 --- a/test/anonymous-fn/test-wrapper.js +++ b/test/anonymous-fn/test-wrapper.js @@ -1,3 +1,5 @@ +'use strict'; + // Example of wrapper function that would invoke tape module.exports = function (testCase) { return function (t) { diff --git a/test/array.js b/test/array.js index dc4a4a40..982ddd87 100644 --- a/test/array.js +++ b/test/array.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); @@ -30,9 +32,9 @@ tap.test('array test', function (tt) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -42,19 +44,19 @@ tap.test('array test', function (tt) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/bound.js b/test/bound.js index 58f26920..cff296b3 100644 --- a/test/bound.js +++ b/test/bound.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('bind works', function (t) { diff --git a/test/browser/asserts.js b/test/browser/asserts.js index a1b24f6d..fb981b7c 100644 --- a/test/browser/asserts.js +++ b/test/browser/asserts.js @@ -1,9 +1,11 @@ +'use strict'; + 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 08d3c760..6c75f587 100644 --- a/test/child_ordering.js +++ b/test/child_ordering.js @@ -1,12 +1,14 @@ +'use strict'; + 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(); }); @@ -22,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/circular-things.js b/test/circular-things.js index 46562e1a..140727ea 100644 --- a/test/circular-things.js +++ b/test/circular-things.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); diff --git a/test/comment.js b/test/comment.js index ff055e00..b9933b53 100644 --- a/test/comment.js +++ b/test/comment.js @@ -1,3 +1,5 @@ +'use strict'; + var concat = require('concat-stream'); var tap = require('tap'); var tape = require('../'); @@ -62,7 +64,6 @@ tap.test('null argument', function (assert) { }); }); - // Exploratory test, how is whitespace treated? tap.test('whitespace', function (assert) { assert.plan(1); @@ -130,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); @@ -164,11 +165,11 @@ tap.test('multiline string', function (assert) { test('multiline strings', function (t) { t.comment([ 'a', - 'b', + 'b' ].join('\n')); t.comment([ 'c', - 'd', + 'd' ].join('\r\n')); t.end(); }); diff --git a/test/common.js b/test/common.js index 8188fe65..eedc70ca 100644 --- a/test/common.js +++ b/test/common.js @@ -1,3 +1,5 @@ +'use strict'; + var path = require('path'); var yaml = require('js-yaml'); diff --git a/test/create_multiple_streams.js b/test/create_multiple_streams.js index 8ecac498..9307e881 100644 --- a/test/create_multiple_streams.js +++ b/test/create_multiple_streams.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); tape.test('createMultipleStreams', function (tt) { @@ -11,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); @@ -24,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 b086d2c3..c227ff4b 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); @@ -64,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 }); }); }); @@ -123,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/deep.js b/test/deep.js index 909ebe10..c5820043 100644 --- a/test/deep.js +++ b/test/deep.js @@ -1,17 +1,19 @@ +'use strict'; + var test = require('../'); test('deep strict equal', function (t) { t.notDeepEqual( - [ { a: '3' } ], - [ { a: 3 } ] + [{ a: '3' }], + [{ a: 3 }] ); t.end(); }); test('deep loose equal', function (t) { t.deepLooseEqual( - [ { a: '3' } ], - [ { a: 3 } ] + [{ a: '3' }], + [{ a: 3 }] ); t.end(); }); diff --git a/test/double_end.js b/test/double_end.js index f254ed35..64edb526 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('tap').test; var path = require('path'); var concat = require('concat-stream'); @@ -18,7 +20,7 @@ test(function (t) { // 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; @@ -27,8 +29,7 @@ test(function (t) { 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/double_end/double.js b/test/double_end/double.js index 43929e51..2c0ae405 100644 --- a/test/double_end/double.js +++ b/test/double_end/double.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../../'); test('double end', function (t) { diff --git a/test/end-as-callback.js b/test/end-as-callback.js index a8c70940..301cad50 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var forEach = require('for-each'); var tape = require('../'); @@ -73,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/error.js b/test/error.js index 83e80100..18dcb0bd 100644 --- a/test/error.js +++ b/test/error.js @@ -32,7 +32,7 @@ tap.test('failures', function (tt) { '# tests 1', '# pass 0', '# fail 1', - '', + '' ]); })); diff --git a/test/exit.js b/test/exit.js index 80ef8ad5..7c528666 100644 --- a/test/exit.js +++ b/test/exit.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var path = require('path'); var spawn = require('child_process').spawn; @@ -25,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 07a65ca3..930f51df 100644 --- a/test/exit/fail.js +++ b/test/exit/fail.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../../'); var falafel = require('falafel'); @@ -5,9 +7,9 @@ test('array', function (t) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -17,19 +19,19 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4444]], [5, 6]]); } ); }); diff --git a/test/exit/ok.js b/test/exit/ok.js index 6d405c7c..7649d940 100644 --- a/test/exit/ok.js +++ b/test/exit/ok.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var test = require('../../'); @@ -6,9 +8,9 @@ test('array', function (t) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -18,19 +20,19 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/exit/second.js b/test/exit/second.js index 8a206bb3..79e632e2 100644 --- a/test/exit/second.js +++ b/test/exit/second.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../../'); test('first', function (t) { diff --git a/test/exit/todo.js b/test/exit/todo.js index acbf960a..bf0de1a8 100644 --- a/test/exit/todo.js +++ b/test/exit/todo.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../../'); test('todo pass', { todo: true }, function (t) { diff --git a/test/exit/todo_fail.js b/test/exit/todo_fail.js index f8ffa67c..06ec32f1 100644 --- a/test/exit/todo_fail.js +++ b/test/exit/todo_fail.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../../'); test('todo fail', { todo: true }, function (t) { diff --git a/test/exit/too_few.js b/test/exit/too_few.js index 68ba71db..33bc0855 100644 --- a/test/exit/too_few.js +++ b/test/exit/too_few.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var test = require('../../'); @@ -5,9 +7,9 @@ test('array', function (t) { t.plan(6); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -17,19 +19,19 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/exposed-harness.js b/test/exposed-harness.js index 1056ddbc..d153eda7 100644 --- a/test/exposed-harness.js +++ b/test/exposed-harness.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); diff --git a/test/fail.js b/test/fail.js index 45df8d66..7a1f7285 100644 --- a/test/fail.js +++ b/test/fail.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); @@ -47,9 +49,9 @@ tap.test('array test', function (tt) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -59,19 +61,19 @@ tap.test('array test', function (tt) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4444]], [5, 6]]); } ); }); diff --git a/test/has spaces.js b/test/has spaces.js index 3e8c80db..990c9d88 100644 --- a/test/has spaces.js +++ b/test/has spaces.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); 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/many.js b/test/many.js index d6e85158..6e5368a3 100644 --- a/test/many.js +++ b/test/many.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('many tests', function (t) { diff --git a/test/match.js b/test/match.js index b598b9db..407d6b5d 100644 --- a/test/match.js +++ b/test/match.js @@ -56,13 +56,13 @@ tap.test('match', function (tt) { test('match', function (t) { t.plan(6); - t.throws( + t['throws']( function () { t.match(/abc/, 'string'); }, TypeError, 'regex arg must be a regex' ); - t.throws( + t['throws']( function () { t.match({ abc: 123 }, /abc/); }, TypeError, 'string arg must be a string' @@ -150,13 +150,13 @@ tap.test('doesNotMatch', function (tt) { test('doesNotMatch', function (t) { t.plan(6); - t.throws( + t['throws']( function () { t.doesNotMatch(/abc/, 'string'); }, TypeError, 'regex arg must be a regex' ); - t.throws( + t['throws']( function () { t.doesNotMatch({ abc: 123 }, /abc/); }, TypeError, 'string arg must be a string' diff --git a/test/max_listeners.js b/test/max_listeners.js index 23ebea8c..286a2b15 100644 --- a/test/max_listeners.js +++ b/test/max_listeners.js @@ -1,3 +1,5 @@ +'use strict'; + var spawn = require('child_process').spawn; var path = require('path'); diff --git a/test/max_listeners/source.js b/test/max_listeners/source.js index 2179f97d..137f8a1c 100644 --- a/test/max_listeners/source.js +++ b/test/max_listeners/source.js @@ -1,5 +1,10 @@ +'use strict'; + var test = require('../../'); -for (var i = 0; i < 11; i ++) { - test(function (t) { t.ok(true, 'true is truthy'); t.end(); }); +for (var i = 0; i < 11; i++) { + test(function (t) { + t.ok(true, 'true is truthy'); + t.end(); + }); } diff --git a/test/nested-async-plan-noend.js b/test/nested-async-plan-noend.js index 1acc1416..a086d8ed 100644 --- a/test/nested-async-plan-noend.js +++ b/test/nested-async-plan-noend.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('Harness async test support', function (t) { diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index c0e5d4ac..80a7da04 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); diff --git a/test/nested.js b/test/nested.js index 46822594..a2b5a390 100644 --- a/test/nested.js +++ b/test/nested.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); @@ -36,9 +38,9 @@ tap.test('array test', function (tt) { t.plan(6); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -57,19 +59,19 @@ tap.test('array test', function (tt) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/nested2.js b/test/nested2.js index 1612b9b6..f167df61 100644 --- a/test/nested2.js +++ b/test/nested2.js @@ -1,18 +1,19 @@ +'use strict'; + 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/no_callback.js b/test/no_callback.js index 760ff26c..99f268b5 100644 --- a/test/no_callback.js +++ b/test/no_callback.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('No callback.'); diff --git a/test/not-deep-equal-failure.js b/test/not-deep-equal-failure.js index 5ac49cc9..40fcb9d9 100644 --- a/test/not-deep-equal-failure.js +++ b/test/not-deep-equal-failure.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); @@ -64,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 }); }); }); @@ -123,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/not-equal-failure.js b/test/not-equal-failure.js index bb7f9167..6db2861a 100644 --- a/test/not-equal-failure.js +++ b/test/not-equal-failure.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); diff --git a/test/objectMode.js b/test/objectMode.js index 33df4661..fd71d8cc 100644 --- a/test/objectMode.js +++ b/test/objectMode.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var tape = require('../'); var forEach = require('for-each'); @@ -12,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; @@ -22,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); } }); @@ -51,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 666227d7..0d7c1cc0 100644 --- a/test/onFailure.js +++ b/test/onFailure.js @@ -1,10 +1,12 @@ +'use strict'; + 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 7881273e..db3b7609 100644 --- a/test/onFinish.js +++ b/test/onFinish.js @@ -1,7 +1,9 @@ +'use strict'; + 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/only-twice.js b/test/only-twice.js index cca7c758..98008c90 100644 --- a/test/only-twice.js +++ b/test/only-twice.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); @@ -8,7 +10,7 @@ tap.test('only twice error', function (assert) { t.end(); }); - assert.throws(function () { + assert['throws'](function () { test.only('second only', function (t) { t.end(); }); diff --git a/test/only.js b/test/only.js index 41f2f839..27253efa 100644 --- a/test/only.js +++ b/test/only.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var tape = require('../'); var concat = require('concat-stream'); @@ -18,7 +20,7 @@ tap.test('tape only test', function (tt) { '', '# ok' ].join('\n') + '\n'); - tt.deepEqual(ran, [ 3 ]); + tt.deepEqual(ran, [3]); tt.end(); }; diff --git a/test/only2.js b/test/only2.js index fcf4f439..bf629978 100644 --- a/test/only2.js +++ b/test/only2.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('only2 test 1', function (t) { diff --git a/test/only3.js b/test/only3.js index b192a4e0..6c73ef83 100644 --- a/test/only3.js +++ b/test/only3.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('only3 test 1', function (t) { diff --git a/test/only4.js b/test/only4.js index d570b5bc..b4362124 100644 --- a/test/only4.js +++ b/test/only4.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('only4 duplicate test name', function (t) { diff --git a/test/only5.js b/test/only5.js index 0e158872..abbfbe20 100644 --- a/test/only5.js +++ b/test/only5.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test.only('only5 duplicate test name', function (t) { diff --git a/test/order.js b/test/order.js index 02aaa055..5c0ea715 100644 --- a/test/order.js +++ b/test/order.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); var current = 0; diff --git a/test/plan_optional.js b/test/plan_optional.js index 680dbcbb..6731f269 100644 --- a/test/plan_optional.js +++ b/test/plan_optional.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('plan should be optional', function (t) { diff --git a/test/require.js b/test/require.js index 7420bb7e..14014cdd 100644 --- a/test/require.js +++ b/test/require.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var spawn = require('child_process').spawn; var concat = require('concat-stream'); @@ -62,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/require/a.js b/test/require/a.js index 86e0296b..f4d87453 100644 --- a/test/require/a.js +++ b/test/require/a.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../..'); tape.test('module-a', function (t) { diff --git a/test/require/b.js b/test/require/b.js index 808fc9e5..f7fe3b1c 100644 --- a/test/require/b.js +++ b/test/require/b.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../..'); tape.test('module-b', function (t) { diff --git a/test/require/test-a.js b/test/require/test-a.js index 03d5a84a..bcf15ca9 100644 --- a/test/require/test-a.js +++ b/test/require/test-a.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../..'); tape.test('test-a', function (t) { diff --git a/test/require/test-b.js b/test/require/test-b.js index 5069b55b..6cd57bfd 100644 --- a/test/require/test-b.js +++ b/test/require/test-b.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../..'); tape.test('test-b', function (t) { diff --git a/test/skip.js b/test/skip.js index 234c75a9..d0843599 100644 --- a/test/skip.js +++ b/test/skip.js @@ -1,5 +1,6 @@ +'use strict'; + var test = require('../'); -var ran = 0; var concat = require('concat-stream'); var tap = require('tap'); @@ -30,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 1752dcfd..544d3056 100644 --- a/test/skip_explanation.js +++ b/test/skip_explanation.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var test = require('../'); var concat = require('concat-stream'); @@ -72,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 f2e4b4e2..8ae0ee6b 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); @@ -28,10 +30,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' @@ -52,7 +53,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', expected: 'undefined', @@ -175,9 +176,9 @@ tap.test('preserves stack trace for failed assertions', function (tt) { parser.once('assert', function (data) { tt.equal(typeof data.diag.at, 'string'); tt.equal(typeof data.diag.stack, 'string'); - at = data.diag.at || ''; + 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, @@ -193,10 +194,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' @@ -206,7 +206,8 @@ tap.test('preserves stack trace for failed assertions', function (tt) { + ' actual: true\n' + ' stack: |-\n' + ' ' - + stack.replace(/\n/g, '\n ') + '\n' + + stack.replace(/\n/g, '\n ') + + '\n' + ' ...\n' + '\n' + '1..1\n' @@ -215,7 +216,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, @@ -240,9 +241,9 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun parser.once('assert', function (data) { tt.equal(typeof data.diag.at, 'string'); tt.equal(typeof data.diag.stack, 'string'); - at = data.diag.at || ''; + 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, @@ -258,10 +259,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' @@ -271,7 +271,8 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun + ' actual: false\n' + ' stack: |-\n' + ' ' - + stack.replace(/\n/g, '\n ') + '\n' + + stack.replace(/\n/g, '\n ') + + '\n' + ' ...\n' + '\n' + '1..1\n' @@ -280,7 +281,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, diff --git a/test/subcount.js b/test/subcount.js index 8985e6d8..62b94746 100644 --- a/test/subcount.js +++ b/test/subcount.js @@ -1,14 +1,16 @@ +'use strict'; + 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_and_async.js b/test/subtest_and_async.js index 5d922850..a5843e53 100644 --- a/test/subtest_and_async.js +++ b/test/subtest_and_async.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); var asyncFunction = function (callback) { diff --git a/test/subtest_plan.js b/test/subtest_plan.js index e0f906e5..b3063b96 100644 --- a/test/subtest_plan.js +++ b/test/subtest_plan.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); test('parent', function (t) { @@ -7,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 51f16498..f804f8c6 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', @@ -120,14 +120,16 @@ tap.test('teardowns', function (tt) { '# success (promise) teardown: 3' ] : [ '# SKIP success (promise)' - ], [ + ], + [ '', '1..' + ((typeof Promise === 'function' ? 1 : 0) + 10 + v.nonFunctions.length), '# tests ' + ((typeof Promise === 'function' ? 1 : 0) + 10 + v.nonFunctions.length), '# pass ' + ((typeof Promise === 'function' ? 1 : 0) + 5), '# fail ' + (5 + v.nonFunctions.length), '' - ])); + ] + )); })); test('success', function (t) { diff --git a/test/throws.js b/test/throws.js index 5cad0334..a683bfcf 100644 --- a/test/throws.js +++ b/test/throws.js @@ -1,19 +1,18 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; -function fn() { - throw new TypeError('RegExp'); -} - function getNonFunctionMessage(fn) { try { fn(); } catch (e) { return e.message; } + return ''; } var getter = function () { return 'message'; }; @@ -41,7 +40,7 @@ tap.test('failures', function (tt) { ' { [TypeError: ' + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }", ' at: Test. ($TEST/throws.js:$LINE:$COL)', ' stack: |-', - ' TypeError: ' + getNonFunctionMessage(undefined) + '', + String(' TypeError: ' + getNonFunctionMessage(undefined)), ' [... stack stripped ...]', ' at Test. ($TEST/throws.js:$LINE:$COL)', ' [... stack stripped ...]', @@ -55,7 +54,7 @@ tap.test('failures', function (tt) { ' { [TypeError: ' + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }", ' at: Test. ($TEST/throws.js:$LINE:$COL)', ' stack: |-', - ' TypeError: ' + getNonFunctionMessage(null) + '', + String(' TypeError: ' + getNonFunctionMessage(null)), ' [... stack stripped ...]', ' at Test. ($TEST/throws.js:$LINE:$COL)', ' [... stack stripped ...]', @@ -69,7 +68,7 @@ tap.test('failures', function (tt) { ' { [TypeError: ' + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }", ' at: Test. ($TEST/throws.js:$LINE:$COL)', ' stack: |-', - ' TypeError: ' + getNonFunctionMessage(true) + '', + String(' TypeError: ' + getNonFunctionMessage(true)), ' [... stack stripped ...]', ' at Test. ($TEST/throws.js:$LINE:$COL)', ' [... stack stripped ...]', @@ -83,7 +82,7 @@ tap.test('failures', function (tt) { ' { [TypeError: ' + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }", ' at: Test. ($TEST/throws.js:$LINE:$COL)', ' stack: |-', - ' TypeError: ' + getNonFunctionMessage(false) + '', + String(' TypeError: ' + getNonFunctionMessage(false)), ' [... stack stripped ...]', ' at Test. ($TEST/throws.js:$LINE:$COL)', ' [... stack stripped ...]', @@ -97,7 +96,7 @@ tap.test('failures', function (tt) { ' { [TypeError: ' + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }", ' at: Test. ($TEST/throws.js:$LINE:$COL)', ' stack: |-', - ' TypeError: ' + getNonFunctionMessage('abc') + '', + String(' TypeError: ' + getNonFunctionMessage('abc')), ' [... stack stripped ...]', ' at Test. ($TEST/throws.js:$LINE:$COL)', ' [... stack stripped ...]', @@ -111,7 +110,7 @@ tap.test('failures', function (tt) { ' { [TypeError: ' + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }", ' at: Test. ($TEST/throws.js:$LINE:$COL)', ' stack: |-', - ' TypeError: ' + getNonFunctionMessage(/a/g) + '', + String(' TypeError: ' + getNonFunctionMessage(/a/g)), ' [... stack stripped ...]', ' at Test. ($TEST/throws.js:$LINE:$COL)', ' [... stack stripped ...]', @@ -125,7 +124,7 @@ tap.test('failures', function (tt) { ' { [TypeError: ' + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }", ' at: Test. ($TEST/throws.js:$LINE:$COL)', ' stack: |-', - ' TypeError: ' + getNonFunctionMessage([]) + '', + String(' TypeError: ' + getNonFunctionMessage([])), ' [... stack stripped ...]', ' at Test. ($TEST/throws.js:$LINE:$COL)', ' [... stack stripped ...]', @@ -139,7 +138,7 @@ tap.test('failures', function (tt) { ' { [TypeError: ' + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }", ' at: Test. ($TEST/throws.js:$LINE:$COL)', ' stack: |-', - ' TypeError: ' + getNonFunctionMessage({}) + '', + String(' TypeError: ' + getNonFunctionMessage({})), ' [... stack stripped ...]', ' at Test. ($TEST/throws.js:$LINE:$COL)', ' [... stack stripped ...]', @@ -188,38 +187,38 @@ tap.test('failures', function (tt) { test('non functions', function (t) { t.plan(8); - t.throws(); - t.throws(null); - t.throws(true); - t.throws(false); - t.throws('abc'); - t.throws(/a/g); - t.throws([]); - t.throws({}); + t['throws'](); + t['throws'](null); + t['throws'](true); + t['throws'](false); + t['throws']('abc'); + t['throws'](/a/g); + t['throws']([]); + t['throws']({}); }); test('function', function (t) { t.plan(1); - t.throws(function () {}); + t['throws'](function () {}); }); test('custom error messages', function (t) { t.plan(3); t.equal(Object.prototype.propertyIsEnumerable.call(messageGetterError, 'message'), true, '"message" is enumerable'); - t.throws(thrower, "{ custom: 'error', message: 'message' }"); + t['throws'](thrower, "{ custom: 'error', message: 'message' }"); t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same'); }); test('throws null', function (t) { t.plan(1); - t.throws(function () { throw null; }, 'throws null'); + t['throws'](function () { throw null; }, 'throws null'); t.end(); }); test('wrong type of error', function (t) { t.plan(1); var actual = new RangeError('actual!'); - t.throws(function () { throw actual; }, TypeError, 'throws actual'); + t['throws'](function () { throw actual; }, TypeError, 'throws actual'); t.end(); }); }); diff --git a/test/timeout.js b/test/timeout.js index b74b11a1..bf11242d 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -1,3 +1,5 @@ +'use strict'; + var test = require('../'); var ran = 0; diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index 366b5d6f..10a0fe4d 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); diff --git a/test/todo.js b/test/todo.js index 5b9351ee..fe25481a 100644 --- a/test/todo.js +++ b/test/todo.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var tape = require('../'); var concat = require('concat-stream'); diff --git a/test/todo_explanation.js b/test/todo_explanation.js index 225d584f..72c559ed 100644 --- a/test/todo_explanation.js +++ b/test/todo_explanation.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var tape = require('../'); var concat = require('concat-stream'); @@ -5,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); diff --git a/test/todo_single.js b/test/todo_single.js index 0359bcfa..d9da7eaa 100644 --- a/test/todo_single.js +++ b/test/todo_single.js @@ -1,3 +1,5 @@ +'use strict'; + var tap = require('tap'); var tape = require('../'); var concat = require('concat-stream'); diff --git a/test/too_many.js b/test/too_many.js index 6ac3e164..86131d85 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -1,3 +1,5 @@ +'use strict'; + var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); @@ -48,9 +50,9 @@ tap.test('array test', function (tt) { t.plan(3); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -60,19 +62,19 @@ tap.test('array test', function (tt) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/undef.js b/test/undef.js index 5b219d99..42846a29 100644 --- a/test/undef.js +++ b/test/undef.js @@ -1,3 +1,5 @@ +'use strict'; + var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); From af5b2f2225cbef6fb7d22533bc77796096ac5012 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 27 Jul 2021 21:32:22 -0700 Subject: [PATCH 30/30] v4.14.0 - [New] add `.teardown()` on `t` instances (#546) - [New] Include name of test in log when test times out (#524) - [Refactor] avoid reassigning arguments - [Refactor] remove unused line, unneeded var initialization; add missing `new` - [Refactor] remove use of legacy `exports` - [Refactor] Avoid setting message property on primitives; use strict mode to catch this - [Refactor] generalize error message from calling `.end` more than once - [Refactor] use `call-bind/callBound` instead of `function-bind` directly - [readme] improve `t.throws` documentation (#541) - [readme] Another way to create custom reportersA (#556) - [readme] remove long-dead testling-ci badge - [readme] add `tape-describe` to 'other' section (#523) - [readme] remove travis badge; add actions and codecov badges - [eslint] remove useless regex escapes - [eslint] fully enable `@ljharb` eslint config - [meta] do not publish github action workflow files - [meta] add `safe-publish-latest`; use `prepublishOnly` script for npm 7+ - [meta] run `aud` in `posttest` - [Deps] update `glob`, `is-regex`, `object-inspect`, `resolve`, `string.prototype.trim` - [Dev Deps] update `eslint` - [actions] use `node/install` instead of `node/run`; use `codecov` action - [Tests] exclude examples from coverage - [Tests] ensure bin/tape is linted - [Tests] make `stripFullStack` output an array of lines, for better failure messages - [Tests] handle stack differences in node 15 - [Tests] add test case for #519 for test.comment() in createStream/objectMode context --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f1aea39e..87c9881d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.13.3", + "version": "4.14.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape",