diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5ba593b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: Test +on: + push: + branches: + - master + pull_request: +jobs: + nodejs: + name: Node.js + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + node-version: [^10, ^12, ^14] + os: [ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm install --no-audit + - run: npm test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7d69d74..0000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: node_js -node_js: - - '8' - - '6' - - '4' diff --git a/index.js b/index.js index 2ddde2a..d72da2a 100644 --- a/index.js +++ b/index.js @@ -1,29 +1,27 @@ 'use strict'; -const serializeErr = require('serialize-error'); +const {serializeError} = require('serialize-error'); const indentString = require('indent-string'); const stripAnsi = require('strip-ansi'); const arrify = require('arrify'); const yaml = require('js-yaml'); -const serializeError = err => { - const obj = serializeErr(err); - obj.at = obj.stack +const serializeErrorForTap = err => { + const object = serializeError(err); + object.at = object.stack .split('\n') .slice(1, 2) .map(line => line.replace(/at/, '').trim()) .shift(); - - delete obj.stack; - - return obj; + delete object.stack; + return object; }; exports.start = () => 'TAP version 13'; exports.test = (title, options) => { - const error = options.error; - let passed = options.passed; + const {error} = options; + let {passed} = options; let directive = ''; if (!error) { @@ -37,21 +35,20 @@ exports.test = (title, options) => { } const comment = arrify(options.comment) - .map(line => indentString(line, 4).replace(/^ {4}/, ' * ')) + .map(line => indentString(line, 4).replace(/^ {4}/gm, '# ')) .join('\n'); const output = [ - `# ${stripAnsi(title)}`, - `${passed ? 'ok' : 'not ok'} ${options.index} - ${title} ${directive}`.trim(), + `${passed ? 'ok' : 'not ok'} ${options.index} - ${stripAnsi(title)} ${directive}`.trim(), comment ]; if (error) { - const obj = error instanceof Error ? serializeError(error) : error; + const object = error instanceof Error ? serializeErrorForTap(error) : error; output.push([ ' ---', - indentString(yaml.safeDump(obj).trim(), 4), + indentString(yaml.safeDump(object).trim(), 4), ' ...' ].join('\n')); } diff --git a/package.json b/package.json index 1ff375a..cc307f9 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "github.com/vadimdemedes" }, "engines": { - "node": ">=4" + "node": ">=10" }, "scripts": { "test": "xo && ava" @@ -24,28 +24,28 @@ "output" ], "dependencies": { - "arrify": "^1.0.1", - "indent-string": "^3.2.0", - "js-yaml": "^3.10.0", - "serialize-error": "^2.1.0", - "strip-ansi": "^4.0.0" + "arrify": "^2.0.1", + "indent-string": "^4.0.0", + "js-yaml": "^3.14.0", + "serialize-error": "^7.0.1", + "strip-ansi": "^6.0.0" }, "devDependencies": { - "ava": "^0.20.0", + "ava": "^3.14.0", "ctrlc-exit": "^1.0.0", - "execa": "^0.8.0", + "execa": "^5.0.0", "faucet": "^0.0.1", - "p-each-series": "^1.0.0", - "tap-dot": "^1.0.5", + "p-each-series": "^2.2.0", + "tap-dot": "^2.0.0", "tap-json": "^1.0.0", - "tap-min": "^1.2.2", + "tap-min": "^2.0.0", "tap-nyan": "^1.1.0", - "tap-out": "^2.0.0", + "tap-out": "^3.0.0", "tap-pessimist": "^1.0.1", - "tap-spec": "^4.1.1", + "tap-spec": "^5.0.0", "tap-summary": "^4.0.0", "wait-for-enter": "^1.0.0", - "xo": "^0.18.2" + "xo": "^0.36.1" }, "ava": { "serial": true diff --git a/scripts/check.js b/scripts/check.js index 97e5713..2c0a12b 100644 --- a/scripts/check.js +++ b/scripts/check.js @@ -4,21 +4,22 @@ const waitForEnter = require('wait-for-enter'); const eachSeries = require('p-each-series'); const ctrlcExit = require('ctrlc-exit'); const execa = require('execa'); +const path = require('path'); ctrlcExit(); -const exec = cmd => { - return execa.shell(cmd) - .catch(err => err) - .then(result => result.stdout); +const exec = async cmd => { + const {stdout} = await execa.command(cmd, {reject: false, shell: true}) + return stdout; }; -const fixtures = fs.readdirSync(`${__dirname}/../test/fixtures`); +const fixturePath = path.join(__dirname, '..', 'test', 'fixtures'); + +const fixtures = fs.readdirSync(fixturePath); const reporter = process.argv[2]; eachSeries(fixtures, async fixture => { - const fixturePath = `${__dirname}/../test/fixtures/${fixture}`; - const reporterPath = `${__dirname}/../node_modules/.bin/${reporter}`; + const reporterPath = path.join(__dirname, '..', 'node_modules', '.bin', reporter); const stdout = await exec(`node ${fixturePath} | ${reporterPath}`); console.log(fixture); console.log(stdout); diff --git a/test/snapshots/test.js.md b/test/snapshots/test.js.md index 6dbbc63..5b4f7a7 100644 --- a/test/snapshots/test.js.md +++ b/test/snapshots/test.js.md @@ -2,244 +2,146 @@ The actual snapshot is saved in `test.js.snap`. -Generated by [AVA](https://ava.li). +Generated by [AVA](https://avajs.dev). -## faucet - fail +## tap-spec - fail-without-error > Snapshot 1 - `␍ - # fail␊ - ␍ - not ok 1 fail␊ - ⨯ fail ---␊ + `␊ + ` + +## tap-spec - fail + +> Snapshot 1 + + `␊ + ✖ fail␊ + -------␊ actual: 1␊ expected: 2␊ - operator: ===␊ + operator: '==='␊ name: Error␊ message: error␊ at: 'fn (test.js:1:2)'␊ - ...␊ - ␊ - ␍ - # tests 1␊ - ␍ - tests 1␍ - # pass 0␊ - ␍ - pass 0␍ - # fail 1␊ - ⨯ fail 1` - -## faucet - fail-without-error - -> Snapshot 1 - - `␍ - # fail␊ - ␍ - not ok 1 fail␊ - ⨯ fail ␊ - ␍ - # tests 1␊ - ␍ - tests 1␍ - # pass 0␊ - ␍ - pass 0␍ - # fail 1␊ - ⨯ fail 1` + ␊ + ␊ + ` -## faucet - mixed +## tap-spec - mixed > Snapshot 1 - `␍ - # passing␊ - ␍ - ok 1 passing␍ - ✓ passing␍ - # fail␊ - ␍ - not ok 2 fail␊ - ⨯ fail ---␊ + ` ✔ passing␊ + ␊ + ✖ fail␊ + -------␊ actual: 1␊ expected: 2␊ - operator: ===␊ + operator: '==='␊ name: Error␊ message: error␊ at: 'fn (test.js:1:2)'␊ - ...␊ - ␍ - # pass with comment␊ - ␍ - ok 3 pass with comment␍ - ✓ pass with comment␍ - # pass with comment␊ - ␍ - ok 4 pass with comment␍ - ✓ pass with comment␍ - # skip␊ - ␍ - ok 5 skip # SKIP␍ - ✓ skip␍ - # todo␊ - ␍ - not ok 6 todo # TODO␊ - ⨯ todo ␊ - ␍ - # tests 5␊ - ␍ - tests 5␍ - # pass 3␊ - ␍ - pass 3␍ - # skip 1␊ - ␍ - ✓ skip 1␍ - # fail 2␊ - ⨯ fail 2` - -## faucet - pass - -> Snapshot 1 - - `␍ - # passing␊ - ␍ - ok 1 passing␍ - ✓ passing␍ - # tests 1␊ - ␍ - tests 1␍ - # pass 1␊ - ✓ pass 1` + ␊ + ✔ pass with comment␊ + ␊ + Hello␊ + ␊ + ✔ pass with comment␊ + ␊ + Hello␊ + ␊ + ␊ + Bonjour␊ + ␊ + - skip␊ + ␊ + ` -## faucet - pass-fail +## tap-spec - pass-fail > Snapshot 1 - `␍ - # passing␊ - ␍ - ok 1 passing␍ - ✓ passing␍ - # fail␊ - ␍ - not ok 2 fail␊ - ⨯ fail ---␊ + ` ✔ passing␊ + ␊ + ✖ fail␊ + -------␊ actual: 1␊ expected: 2␊ - operator: ===␊ + operator: '==='␊ name: Error␊ message: error␊ at: 'fn (test.js:1:2)'␊ - ...␊ - ␊ - ␍ - # tests 2␊ - ␍ - tests 2␍ - # pass 1␊ - ␍ - pass 1␍ - # fail 1␊ - ⨯ fail 1` + ␊ + ␊ + ` -## faucet - pass-with-multiple-comments +## tap-spec - pass-with-multiple-comments > Snapshot 1 - `␍ - # pass with comment␊ - ␍ - ok 1 pass with comment␍ - ✓ pass with comment␍ - # tests 1␊ - ␍ - tests 1␍ - # pass 1␊ - ✓ pass 1` + ` ✔ pass with comment␊ + ␊ + Hello␊ + ␊ + ␊ + Bonjour␊ + ␊ + ␊ + ␊ + total: 1␊ + passing: 1␊ + duration: ␊ + ␊ + ` -## faucet - pass-with-single-comment +## tap-spec - pass-with-single-comment > Snapshot 1 - `␍ - # pass with comment␊ - ␍ - ok 1 pass with comment␍ - ✓ pass with comment␍ - # tests 1␊ - ␍ - tests 1␍ - # pass 1␊ - ✓ pass 1` + ` ✔ pass with comment␊ + ␊ + Hello␊ + ␊ + ␊ + ␊ + total: 1␊ + passing: 1␊ + duration: ␊ + ␊ + ` -## faucet - skip +## tap-spec - pass > Snapshot 1 - `␍ - # skip␊ - ␍ - ok 1 skip # SKIP␍ - ✓ skip␍ - # tests 1␊ - ␍ - tests 1␍ - # pass 0␊ - ␍ - pass 0␍ - # skip 1␊ - ✓ skip 1` + ` ✔ passing␊ + ␊ + ␊ + total: 1␊ + passing: 1␊ + duration: ␊ + ␊ + ` -## faucet - todo +## tap-spec - skip > Snapshot 1 - `␍ - # todo␊ - ␍ - not ok 1 todo # TODO␊ - ⨯ todo ␊ - ␍ - # tests 0␊ - ␍ - tests 0␍ - # pass 0␊ - ␍ - pass 0␍ - # fail 1␊ - ⨯ fail 1` + ` - skip␊ + ␊ + ␊ + total: 1␊ + passing: 1␊ + duration: ␊ + ␊ + ` -## tap-dot - fail +## tap-spec - todo > Snapshot 1 `␊ - x ␊ - ␊ - ␊ - ---␊ - actual: 1␊ - expected: 2␊ - operator: ===␊ - name: Error␊ - message: error␊ - at: 'fn (test.js:1:2)'␊ - ...␊ - ␊ - ␊ - ␊ - 1 tests␊ - 0 passed␊ - 1 failed ␊ - ␊ - Failed Tests: There was 1 failure␊ - ␊ - x fail␊ - ␊ ` ## tap-dot - fail-without-error @@ -251,65 +153,39 @@ Generated by [AVA](https://ava.li). ␊ ␊ ---␊ - undefined␊ - ...␊ - ␊ - ␊ - ␊ - 1 tests␊ - 0 passed␊ - 1 failed ␊ - ␊ - Failed Tests: There was 1 failure␊ - ␊ - x fail␊ - ␊ - ` + undefined` -## tap-dot - mixed +## tap-dot - fail > Snapshot 1 `␊ - .x...x ␊ + x ␊ ␊ ␊ ---␊ actual: 1␊ expected: 2␊ - operator: ===␊ + operator: '==='␊ name: Error␊ message: error␊ - at: 'fn (test.js:1:2)'␊ - ...␊ - ---␊ - undefined␊ - ...␊ - ␊ - ␊ - ␊ - 6 tests␊ - 4 passed␊ - 2 failed ␊ - ␊ - Failed Tests: There were 2 failures␊ - ␊ - x fail␊ - x todo # TODO␊ - ␊ - ` + at: 'fn (test.js:1:2)'` -## tap-dot - pass +## tap-dot - mixed > Snapshot 1 `␊ - . ␊ + .x...x ␊ ␊ - 1 tests␊ - 1 passed␊ - ␊ - Pass!` + ␊ + ---␊ + actual: 1␊ + expected: 2␊ + operator: '==='␊ + name: Error␊ + message: error␊ + at: 'fn (test.js:1:2)'` ## tap-dot - pass-fail @@ -322,25 +198,24 @@ Generated by [AVA](https://ava.li). ---␊ actual: 1␊ expected: 2␊ - operator: ===␊ + operator: '==='␊ name: Error␊ message: error␊ - at: 'fn (test.js:1:2)'␊ - ...␊ - ␊ - ␊ + at: 'fn (test.js:1:2)'` + +## tap-dot - pass-with-multiple-comments + +> Snapshot 1 + + `␊ + . ␊ ␊ 2 tests␊ 1 passed␊ - 1 failed ␊ - ␊ - Failed Tests: There was 1 failure␊ - ␊ - x fail␊ ␊ - ` + Pass!` -## tap-dot - pass-with-multiple-comments +## tap-dot - pass-with-single-comment > Snapshot 1 @@ -352,14 +227,14 @@ Generated by [AVA](https://ava.li). ␊ Pass!` -## tap-dot - pass-with-single-comment +## tap-dot - pass > Snapshot 1 `␊ . ␊ ␊ - 1 tests␊ + 0 tests␊ 1 passed␊ ␊ Pass!` @@ -371,7 +246,7 @@ Generated by [AVA](https://ava.li). `␊ . ␊ ␊ - 1 tests␊ + 0 tests␊ 1 passed␊ ␊ Pass!` @@ -385,164 +260,9 @@ Generated by [AVA](https://ava.li). ␊ ␊ ---␊ - undefined␊ - ...␊ - ␊ - ␊ - ␊ - 1 tests␊ - 0 passed␊ - 1 failed ␊ - ␊ - Failed Tests: There was 1 failure␊ - ␊ - x todo # TODO␊ - ␊ - ` - -## tap-json - fail - -> Snapshot 1 - - '{"stats":{"asserts":1,"passes":0,"failures":1},"asserts":[{"number":1,"comment":"fail","name":"fail","ok":false,"extra":{"actual":"1","expected":"2","operator":"==="}}]}' - -## tap-json - fail-without-error - -> Snapshot 1 - - '{"stats":{"asserts":1,"passes":0,"failures":1},"asserts":[{"number":1,"comment":"fail","name":"fail","ok":false,"extra":{}}]}' - -## tap-json - mixed - -> Snapshot 1 - - '{"stats":{"asserts":6,"passes":4,"failures":2},"asserts":[{"number":1,"comment":"passing","name":"passing","ok":true,"extra":{}},{"number":2,"comment":"fail","name":"fail","ok":false,"extra":{"actual":"1","expected":"2","operator":"==="}},{"number":3,"comment":"pass with comment","name":"pass with comment","ok":true,"extra":{}},{"number":4,"comment":"pass with comment","name":"pass with comment","ok":true,"extra":{}},{"number":5,"comment":"skip","name":"skip # SKIP","ok":true,"extra":{}},{"number":6,"comment":"todo","name":"todo # TODO","ok":false,"extra":{}}]}' - -## tap-json - pass - -> Snapshot 1 - - '{"stats":{"asserts":1,"passes":1,"failures":0},"asserts":[{"number":1,"comment":"passing","name":"passing","ok":true,"extra":{}}]}' - -## tap-json - pass-fail - -> Snapshot 1 - - '{"stats":{"asserts":2,"passes":1,"failures":1},"asserts":[{"number":1,"comment":"passing","name":"passing","ok":true,"extra":{}},{"number":2,"comment":"fail","name":"fail","ok":false,"extra":{"actual":"1","expected":"2","operator":"==="}}]}' - -## tap-json - pass-with-multiple-comments - -> Snapshot 1 - - '{"stats":{"asserts":1,"passes":1,"failures":0},"asserts":[{"number":1,"comment":"pass with comment","name":"pass with comment","ok":true,"extra":{}}]}' - -## tap-json - pass-with-single-comment - -> Snapshot 1 - - '{"stats":{"asserts":1,"passes":1,"failures":0},"asserts":[{"number":1,"comment":"pass with comment","name":"pass with comment","ok":true,"extra":{}}]}' - -## tap-json - skip - -> Snapshot 1 - - '{"stats":{"asserts":1,"passes":1,"failures":0},"asserts":[{"number":1,"comment":"skip","name":"skip # SKIP","ok":true,"extra":{}}]}' - -## tap-json - todo - -> Snapshot 1 - - '{"stats":{"asserts":1,"passes":0,"failures":1},"asserts":[{"number":1,"comment":"todo","name":"todo # TODO","ok":false,"extra":{}}]}' - -## tap-min - fail - -> Snapshot 1 - - `␊ - fail␊ - operator: ===␊ - expected: 2␊ - actual: 1␊ - ␊ - 1 test complete ()␊ - ` - -## tap-min - fail-without-error - -> Snapshot 1 - - `␊ - fail␊ - ␊ - 1 test complete ()␊ - ` - -## tap-min - mixed - -> Snapshot 1 - - `␊ - fail␊ - operator: ===␊ - expected: 2␊ - actual: 1␊ - ␊ - todo␊ - ␊ - 6 tests complete ()␊ - ` - -## tap-min - pass - -> Snapshot 1 - - `␊ - 1 test complete ()` - -## tap-min - pass-fail - -> Snapshot 1 - - `␊ - fail␊ - operator: ===␊ - expected: 2␊ - actual: 1␊ - ␊ - 2 tests complete ()␊ - ` - -## tap-min - pass-with-multiple-comments - -> Snapshot 1 - - `␊ - 1 test complete ()` - -## tap-min - pass-with-single-comment - -> Snapshot 1 - - `␊ - 1 test complete ()` - -## tap-min - skip - -> Snapshot 1 - - `␊ - 1 test complete ()` + undefined` -## tap-min - todo - -> Snapshot 1 - - `␊ - todo␊ - ␊ - 1 test complete ()` - -## tap-nyan - fail +## tap-nyan - fail-without-error > Snapshot 1 @@ -564,10 +284,9 @@ Generated by [AVA](https://ava.li). ␊ Failed Tests: There was 1 failure␊ ␊ - ✗ # fail␊ - : fail` + ✗ : fail` -## tap-nyan - fail-without-error +## tap-nyan - fail > Snapshot 1 @@ -589,8 +308,7 @@ Generated by [AVA](https://ava.li). ␊ Failed Tests: There was 1 failure␊ ␊ - ✗ # fail␊ - : fail` + ✗ : fail` ## tap-nyan - mixed @@ -674,12 +392,11 @@ Generated by [AVA](https://ava.li). ␊ Failed Tests: There were 2 failures␊ ␊ - ✗ # fail␊ - : fail␊ - ✗ # todo␊ + ✗ : fail␊ + ✗ # Bonjour␊ : todo` -## tap-nyan - pass +## tap-nyan - pass-fail > Snapshot 1 @@ -695,13 +412,27 @@ Generated by [AVA](https://ava.li). _| /\\_/\\ ␊ ^|__( ^ .^) ␊  "" "" ␊ +  1␊ + 1␊ + 0␊ + ␊ + -_␊ + -_␊ + -_␊ + -_␊ + _,------,␊ + _| /\\_/\\ ␊ + ~|_( x .x) ␊ +  "" "" ␊ ␊ ␊ ␊ ␊ - Pass!` + Failed Tests: There was 1 failure␊ + ␊ + ✗ : fail` -## tap-nyan - pass-fail +## tap-nyan - pass-with-multiple-comments > Snapshot 1 @@ -717,28 +448,13 @@ Generated by [AVA](https://ava.li). _| /\\_/\\ ␊ ^|__( ^ .^) ␊  "" "" ␊ -  1␊ - 1␊ - 0␊ - ␊ - -_␊ - -_␊ - -_␊ - -_␊ - _,------,␊ - _| /\\_/\\ ␊ - ~|_( x .x) ␊ -  "" "" ␊ ␊ ␊ ␊ ␊ - Failed Tests: There was 1 failure␊ - ␊ - ✗ # fail␊ - : fail` + Pass!` -## tap-nyan - pass-with-multiple-comments +## tap-nyan - pass-with-single-comment > Snapshot 1 @@ -760,7 +476,7 @@ Generated by [AVA](https://ava.li). ␊ Pass!` -## tap-nyan - pass-with-single-comment +## tap-nyan - pass > Snapshot 1 @@ -826,360 +542,275 @@ Generated by [AVA](https://ava.li). ␊ Failed Tests: There was 1 failure␊ ␊ - ✗ # todo␊ - : todo` + ✗ : todo` -## tap-pessimist - fail +## tap-min - fail-without-error > Snapshot 1 - '' + `␊ + fail␊ + ␊ + 1 test complete ()` -## tap-pessimist - fail-without-error +## tap-min - fail > Snapshot 1 - '' + `␊ + fail␊ + at: 'fn (test.js:1:2)'␊ + operator: ===␊ + expected: 2␊ + actual: 1␊ + ␊ + undefined␊ + ␊ + ␊ + 1 test complete ()` -## tap-pessimist - mixed +## tap-min - mixed > Snapshot 1 - '' + `␊ + fail␊ + at: 'fn (test.js:1:2)'␊ + operator: ===␊ + expected: 2␊ + actual: 1␊ + ␊ + undefined␊ + ␊ + ␊ + todo␊ + ␊ + 6 tests complete ()` -## tap-pessimist - pass +## tap-min - pass-fail > Snapshot 1 - '' + `␊ + fail␊ + at: 'fn (test.js:1:2)'␊ + operator: ===␊ + expected: 2␊ + actual: 1␊ + ␊ + undefined␊ + ␊ + ␊ + 2 tests complete ()` -## tap-pessimist - pass-fail +## tap-min - pass-with-multiple-comments > Snapshot 1 - '' + `␊ + 1 test complete ()` -## tap-pessimist - pass-with-multiple-comments +## tap-min - pass-with-single-comment > Snapshot 1 - '' + `␊ + 1 test complete ()` -## tap-pessimist - pass-with-single-comment +## tap-min - pass > Snapshot 1 - '' + `␊ + 1 test complete ()` -## tap-pessimist - skip +## tap-min - skip > Snapshot 1 - '' + `␊ + 1 test complete ()` -## tap-pessimist - todo +## tap-min - todo > Snapshot 1 - '' + `␊ + todo␊ + ␊ + 1 test complete ()` -## tap-spec - fail +## faucet - fail-without-error > Snapshot 1 - `␊ - fail␊ - ␊ - ␊ - ✖ fail␊ - -------␊ - actual: 1␊ - expected: 2␊ - operator: ===␊ - name: Error␊ - message: error␊ - at: 'fn (test.js:1:2)'␊ - ␊ - ␊ - ␊ - ␊ - Failed Tests: There was 1 failure␊ - ␊ - fail␊ - ␊ - ✖ fail␊ - ␊ - ␊ - total: 1␊ - passing: 0␊ - failing: 1␊ - duration: ␊ - ␊ - ␊ - ` + `⨯ fail␊ + ␍ + # tests 1␊ + ␍ + tests 1␍ + # pass 0␊ + ␍ + pass 0␍ + # fail 1␊ + ⨯ fail 1` -## tap-spec - fail-without-error +## faucet - fail > Snapshot 1 - `␊ - fail␊ - ␊ - ␊ - ␊ - ␊ - Failed Tests: There was 1 failure␊ - ␊ - fail␊ - ␊ - ✖ fail␊ - ␊ - ␊ - total: 1␊ - passing: 0␊ - failing: 1␊ - duration: ␊ - ␊ - ` + `⨯ fail␊ + ␍ + # tests 1␊ + ␍ + tests 1␍ + # pass 0␊ + ␍ + pass 0␍ + # fail 1␊ + ⨯ fail 1` -## tap-spec - mixed +## faucet - mixed > Snapshot 1 - `␊ - passing␊ - ␊ - ✔ passing␊ - ␊ - fail␊ - ␊ - ␊ - ✖ fail␊ - -------␊ - actual: 1␊ - expected: 2␊ - operator: ===␊ - name: Error␊ - message: error␊ - at: 'fn (test.js:1:2)'␊ - ␊ - ␊ - pass with comment␊ - ␊ - ✔ pass with comment␊ - * Hello␊ - ␊ - pass with comment␊ - ␊ - ✔ pass with comment␊ - * Hello␊ - * Bonjour␊ - ␊ - skip␊ - ␊ - ✔ skip # SKIP␊ - ␊ - todo␊ - ␊ - ␊ - ␊ - ␊ - Failed Tests: There were 2 failures␊ - ␊ - fail␊ - ␊ - ✖ fail␊ - ␊ - ␊ - todo␊ - ␊ - ✖ todo # TODO␊ - ␊ - ␊ - total: 6␊ - passing: 4␊ - failing: 2␊ - duration: ␊ - ␊ - ␊ - ` + `✓ passing␊ + ⨯ fail␊ + ✓ pass with comment␊ + ␍ + # Hello␊ + ␍ + ok 4 pass with comment␍ + ✓ Hello␍ + # Hello␊ + ␍ + ✓ Hello␍ + # Bonjour␊ + ␍ + ok 5 skip # SKIP␍ + not ok 6 todo # TODO␊ + ⨯ Bonjour ␊ + ␍ + # tests 5␊ + ␍ + tests 5␍ + # pass 3␊ + ␍ + pass 3␍ + # skip 1␊ + ␍ + ✓ skip 1␍ + # fail 2␊ + ⨯ fail 2` -## tap-spec - pass +## faucet - pass-fail > Snapshot 1 - `␊ - passing␊ - ␊ - ✔ passing␊ - ␊ - ␊ - total: 1␊ - passing: 1␊ - duration: ␊ - ␊ - ` + `✓ passing␊ + ⨯ fail␊ + ␍ + # tests 2␊ + ␍ + tests 2␍ + # pass 1␊ + ␍ + pass 1␍ + # fail 1␊ + ⨯ fail 1` -## tap-spec - pass-fail +## faucet - pass-with-multiple-comments > Snapshot 1 - `␊ - passing␊ - ␊ - ✔ passing␊ - ␊ - fail␊ - ␊ - ␊ - ✖ fail␊ - -------␊ - actual: 1␊ - expected: 2␊ - operator: ===␊ - name: Error␊ - message: error␊ - at: 'fn (test.js:1:2)'␊ - ␊ - ␊ - ␊ - ␊ - Failed Tests: There was 1 failure␊ - ␊ - fail␊ - ␊ - ✖ fail␊ - ␊ - ␊ - total: 2␊ - passing: 1␊ - failing: 1␊ - duration: ␊ - ␊ - ␊ - ` + `✓ pass with comment␊ + ␍ + # Hello␊ + ␍ + ✓ Hello␍ + # Bonjour␊ + ␍ + ✓ Bonjour␍ + # tests 1␊ + ␍ + tests 1␍ + # pass 1␊ + ✓ pass 1` -## tap-spec - pass-with-multiple-comments +## faucet - pass-with-single-comment > Snapshot 1 - `␊ - pass with comment␊ - ␊ - ✔ pass with comment␊ - * Hello␊ - * Bonjour␊ - ␊ - ␊ - total: 1␊ - passing: 1␊ - duration: ␊ - ␊ - ` + `✓ pass with comment␊ + ␍ + # Hello␊ + ␍ + ✓ Hello␍ + # tests 1␊ + ␍ + tests 1␍ + # pass 1␊ + ✓ pass 1` -## tap-spec - pass-with-single-comment +## faucet - pass > Snapshot 1 - `␊ - pass with comment␊ - ␊ - ✔ pass with comment␊ - * Hello␊ - ␊ - ␊ - total: 1␊ - passing: 1␊ - duration: ␊ - ␊ - ` + `✓ passing␊ + ␍ + # tests 1␊ + ␍ + tests 1␍ + # pass 1␊ + ✓ pass 1` -## tap-spec - skip +## faucet - skip > Snapshot 1 - `␊ - skip␊ - ␊ - ✔ skip # SKIP␊ - ␊ - ␊ - total: 1␊ - passing: 1␊ - duration: ␊ - ␊ - ` + `✓ skip # SKIP␊ + ␍ + # tests 1␊ + ␍ + tests 1␍ + # pass 0␊ + ␍ + pass 0␍ + # skip 1␊ + ✓ skip 1` -## tap-spec - todo +## faucet - todo > Snapshot 1 - `␊ - todo␊ - ␊ - ␊ - ␊ - ␊ - Failed Tests: There was 1 failure␊ - ␊ - todo␊ - ␊ - ✖ todo # TODO␊ - ␊ - ␊ - total: 1␊ - passing: 0␊ - failing: 1␊ - duration: ␊ - ␊ - ` + `⨯ todo # TODO␊ + ␍ + # tests 0␊ + ␍ + tests 0␍ + # pass 0␊ + ␍ + pass 0␍ + # fail 1␊ + ⨯ fail 1` -## tap-summary - fail +## tap-summary - fail-without-error > Snapshot 1 `␊ # Tests␊ ␊ - # fail [pass: 0, fail: 0, duration: ]# fail [pass: 0, fail: 1, duration: ]✖ fail [pass: 0, fail: 1, duration: ]␊ - ␊ - # Summary␊ - ␊ - duration: ␊ - planned: 1␊ - assertions: 1␊ - pass: 0␊ - fail: 1␊ - ␊ - # Fails␊ - ␊ - ## fail␊ -  ✖ fail␊ -  actual: 1␊ - expected: 2␊ - operator: ===␊ - name: Error␊ - message: error␊ - at: 'fn (test.js:1:2)'␊ - ␊ - ` + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 0, fail: 1, duration: ]✖ unnamed test [pass: 0, fail: 1, duration: ]` -## tap-summary - fail-without-error +## tap-summary - fail > Snapshot 1 `␊ # Tests␊ ␊ - # fail [pass: 0, fail: 0, duration: ]# fail [pass: 0, fail: 1, duration: ]✖ fail [pass: 0, fail: 1, duration: ]␊ - ␊ - # Summary␊ - ␊ - duration: ␊ - planned: 1␊ - assertions: 1␊ - pass: 0␊ - fail: 1` + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 0, fail: 1, duration: ]✖ unnamed test [pass: 0, fail: 1, duration: ]` ## tap-summary - mixed @@ -1188,78 +819,49 @@ Generated by [AVA](https://ava.li). `␊ # Tests␊ ␊ - # passing [pass: 0, fail: 0, duration: ]# passing [pass: 1, fail: 0, duration: ]✔ passing [pass: 1, fail: 0, duration: ]␊ - # fail [pass: 0, fail: 0, duration: ]# fail [pass: 0, fail: 1, duration: ]✖ fail [pass: 0, fail: 1, duration: ]␊ - # pass with comment [pass: 0, fail: 0, duration: ]# pass with comment [pass: 1, fail: 0, duration: ]✔ pass with comment [pass: 1, fail: 0, duration: ]␊ - # pass with comment [pass: 0, fail: 0, duration: ]# pass with comment [pass: 1, fail: 0, duration: ]✔ pass with comment [pass: 1, fail: 0, duration: ]␊ - # skip [pass: 0, fail: 0, duration: ]# skip [pass: 1, fail: 0, duration: ]✔ skip [pass: 1, fail: 0, duration: ]␊ - # todo [pass: 0, fail: 0, duration: ]# todo [pass: 0, fail: 1, duration: ]✖ todo [pass: 0, fail: 1, duration: ]␊ - ␊ - # Summary␊ - ␊ - duration: ␊ - planned: 6␊ - assertions: 6␊ - pass: 4␊ - fail: 2` + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 1, fail: 0, duration: ]# unnamed test [pass: 1, fail: 1, duration: ]# unnamed test [pass: 2, fail: 1, duration: ]✖ unnamed test [pass: 2, fail: 1, duration: ]␊ + # Hello [pass: 0, fail: 0, duration: ]# Hello [pass: 1, fail: 0, duration: ]✔ Hello [pass: 1, fail: 0, duration: ]␊ + # Hello [pass: 0, fail: 0, duration: ]✔ Hello [pass: 0, fail: 0, duration: ]␊ + # Bonjour [pass: 0, fail: 0, duration: ]# Bonjour [pass: 1, fail: 0, duration: ]# Bonjour [pass: 1, fail: 1, duration: ]✖ Bonjour [pass: 1, fail: 1, duration: ]` -## tap-summary - pass +## tap-summary - pass-fail > Snapshot 1 `␊ # Tests␊ ␊ - # passing [pass: 0, fail: 0, duration: ]# passing [pass: 1, fail: 0, duration: ]✔ passing [pass: 1, fail: 0, duration: ]␊ - ␊ - # Summary␊ - ␊ - duration: ␊ - planned: 1␊ - assertions: 1␊ - pass: 1␊ - fail: 0␊ - ` + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 1, fail: 0, duration: ]# unnamed test [pass: 1, fail: 1, duration: ]✖ unnamed test [pass: 1, fail: 1, duration: ]` -## tap-summary - pass-fail +## tap-summary - pass-with-multiple-comments > Snapshot 1 `␊ # Tests␊ ␊ - # passing [pass: 0, fail: 0, duration: ]# passing [pass: 1, fail: 0, duration: ]✔ passing [pass: 1, fail: 0, duration: ]␊ - # fail [pass: 0, fail: 0, duration: ]# fail [pass: 0, fail: 1, duration: ]✖ fail [pass: 0, fail: 1, duration: ]␊ + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 1, fail: 0, duration: ]✔ unnamed test [pass: 1, fail: 0, duration: ]␊ + # Hello [pass: 0, fail: 0, duration: ]✔ Hello [pass: 0, fail: 0, duration: ]␊ + # Bonjour [pass: 0, fail: 0, duration: ]✔ Bonjour [pass: 0, fail: 0, duration: ]␊ ␊ # Summary␊ ␊ duration: ␊ - planned: 2␊ - assertions: 2␊ + planned: 1␊ + assertions: 1␊ pass: 1␊ - fail: 1␊ - ␊ - # Fails␊ - ␊ - ## fail␊ -  ✖ fail␊ -  actual: 1␊ - expected: 2␊ - operator: ===␊ - name: Error␊ - message: error␊ - at: 'fn (test.js:1:2)'␊ - ␊ + fail: 0␊ ` -## tap-summary - pass-with-multiple-comments +## tap-summary - pass-with-single-comment > Snapshot 1 `␊ # Tests␊ ␊ - # pass with comment [pass: 0, fail: 0, duration: ]# pass with comment [pass: 1, fail: 0, duration: ]✔ pass with comment [pass: 1, fail: 0, duration: ]␊ + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 1, fail: 0, duration: ]✔ unnamed test [pass: 1, fail: 0, duration: ]␊ + # Hello [pass: 0, fail: 0, duration: ]✔ Hello [pass: 0, fail: 0, duration: ]␊ ␊ # Summary␊ ␊ @@ -1268,22 +870,16 @@ Generated by [AVA](https://ava.li). assertions: 1␊ pass: 1␊ fail: 0␊ - ␊ - # Comments␊ - ␊ - ## pass with comment␊ - * Hello␊ - * Bonjour␊ ` -## tap-summary - pass-with-single-comment +## tap-summary - pass > Snapshot 1 `␊ # Tests␊ ␊ - # pass with comment [pass: 0, fail: 0, duration: ]# pass with comment [pass: 1, fail: 0, duration: ]✔ pass with comment [pass: 1, fail: 0, duration: ]␊ + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 1, fail: 0, duration: ]✔ unnamed test [pass: 1, fail: 0, duration: ]␊ ␊ # Summary␊ ␊ @@ -1292,11 +888,6 @@ Generated by [AVA](https://ava.li). assertions: 1␊ pass: 1␊ fail: 0␊ - ␊ - # Comments␊ - ␊ - ## pass with comment␊ - * Hello␊ ` ## tap-summary - skip @@ -1306,7 +897,7 @@ Generated by [AVA](https://ava.li). `␊ # Tests␊ ␊ - # skip [pass: 0, fail: 0, duration: ]# skip [pass: 1, fail: 0, duration: ]✔ skip [pass: 1, fail: 0, duration: ]␊ + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 1, fail: 0, duration: ]✔ unnamed test [pass: 1, fail: 0, duration: ]␊ ␊ # Summary␊ ␊ @@ -1324,12 +915,112 @@ Generated by [AVA](https://ava.li). `␊ # Tests␊ ␊ - # todo [pass: 0, fail: 0, duration: ]# todo [pass: 0, fail: 1, duration: ]✖ todo [pass: 0, fail: 1, duration: ]␊ - ␊ - # Summary␊ - ␊ - duration: ␊ - planned: 1␊ - assertions: 1␊ - pass: 0␊ - fail: 1` + # unnamed test [pass: 0, fail: 0, duration: ]# unnamed test [pass: 0, fail: 1, duration: ]✖ unnamed test [pass: 0, fail: 1, duration: ]` + +## tap-pessimist - fail-without-error + +> Snapshot 1 + + '' + +## tap-pessimist - fail + +> Snapshot 1 + + '' + +## tap-pessimist - mixed + +> Snapshot 1 + + '' + +## tap-pessimist - pass-fail + +> Snapshot 1 + + '' + +## tap-pessimist - pass-with-multiple-comments + +> Snapshot 1 + + '' + +## tap-pessimist - pass-with-single-comment + +> Snapshot 1 + + '' + +## tap-pessimist - pass + +> Snapshot 1 + + '' + +## tap-pessimist - skip + +> Snapshot 1 + + '' + +## tap-pessimist - todo + +> Snapshot 1 + + '' + +## tap-json - fail-without-error + +> Snapshot 1 + + '{"stats":{"asserts":1,"passes":0,"failures":1},"asserts":[{"number":1,"comment":null,"name":"fail","ok":false,"extra":{}}]}' + +## tap-json - fail + +> Snapshot 1 + + '{"stats":{"asserts":1,"passes":0,"failures":1},"asserts":[{"number":1,"comment":null,"name":"fail","ok":false,"extra":{"actual":"1","expected":"2","operator":"\'===\'"}}]}' + +## tap-json - mixed + +> Snapshot 1 + + '{"stats":{"asserts":6,"passes":4,"failures":2},"asserts":[{"number":1,"comment":null,"name":"passing","ok":true,"extra":{}},{"number":2,"comment":null,"name":"fail","ok":false,"extra":{"actual":"1","expected":"2","operator":"\'===\'"}},{"number":3,"comment":null,"name":"pass with comment","ok":true,"extra":{}},{"number":4,"comment":"Hello","name":"pass with comment","ok":true,"extra":{}},{"number":5,"comment":"Bonjour","name":"skip # SKIP","ok":true,"extra":{}},{"number":6,"comment":"Bonjour","name":"todo # TODO","ok":false,"extra":{}}]}' + +## tap-json - pass-fail + +> Snapshot 1 + + '{"stats":{"asserts":2,"passes":1,"failures":1},"asserts":[{"number":1,"comment":null,"name":"passing","ok":true,"extra":{}},{"number":2,"comment":null,"name":"fail","ok":false,"extra":{"actual":"1","expected":"2","operator":"\'===\'"}}]}' + +## tap-json - pass-with-multiple-comments + +> Snapshot 1 + + '{"stats":{"asserts":1,"passes":1,"failures":0},"asserts":[{"number":1,"comment":null,"name":"pass with comment","ok":true,"extra":{}}]}' + +## tap-json - pass-with-single-comment + +> Snapshot 1 + + '{"stats":{"asserts":1,"passes":1,"failures":0},"asserts":[{"number":1,"comment":null,"name":"pass with comment","ok":true,"extra":{}}]}' + +## tap-json - pass + +> Snapshot 1 + + '{"stats":{"asserts":1,"passes":1,"failures":0},"asserts":[{"number":1,"comment":null,"name":"passing","ok":true,"extra":{}}]}' + +## tap-json - skip + +> Snapshot 1 + + '{"stats":{"asserts":1,"passes":1,"failures":0},"asserts":[{"number":1,"comment":null,"name":"skip # SKIP","ok":true,"extra":{}}]}' + +## tap-json - todo + +> Snapshot 1 + + '{"stats":{"asserts":1,"passes":0,"failures":1},"asserts":[{"number":1,"comment":null,"name":"todo # TODO","ok":false,"extra":{}}]}' diff --git a/test/snapshots/test.js.snap b/test/snapshots/test.js.snap index fd8303e..14b7147 100644 Binary files a/test/snapshots/test.js.snap and b/test/snapshots/test.js.snap differ diff --git a/test/test.js b/test/test.js index 493ce3c..7e0a16b 100644 --- a/test/test.js +++ b/test/test.js @@ -1,11 +1,11 @@ -import fs from 'fs'; -import execa from 'execa'; -import test from 'ava'; +const fs = require('fs'); +const execa = require('execa'); +const test = require('ava'); +const path = require('path'); -const exec = cmd => { - return execa.shell(cmd) - .catch(err => err) - .then(result => result.stdout); +const exec = async cmd => { + const {stdout} = await execa.command(cmd, {reject: false, shell: true}) + return stdout; }; const reporters = [ @@ -19,19 +19,20 @@ const reporters = [ 'tap-json' ]; -const fixtures = fs.readdirSync(`${__dirname}/fixtures`); +const fixtures = fs.readdirSync(path.join(__dirname, 'fixtures')); reporters.forEach(reporter => { fixtures.forEach(fixture => { - const path = `${__dirname}/fixtures/${fixture}`; + const fixturePath = path.join(__dirname, 'fixtures', fixture); const name = fixture.replace('.js', ''); test(`${reporter} - ${name}`, async t => { - let stdout = await exec(`node ${path} | ${__dirname}/../node_modules/.bin/${reporter}`); + const reporterBinPath = path.join(__dirname, '..', 'node_modules', '.bin', reporter); + let stdout = await exec(`node ${fixturePath} | ${reporterBinPath}`); // Strip duration from output, because it's dynamic and breaking snapshots if (reporter === 'tap-spec' || reporter === 'tap-summary' || reporter === 'tap-min') { - stdout = stdout.replace(/([0-9]+)ms/g, ''); + stdout = stdout.replace(/(\d+)ms/g, ''); } t.snapshot(stdout);