From fcd4f7205f5bb8c6c486fb0b9898ceb74acc78bf Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 14 Jun 2022 12:02:32 +0300 Subject: [PATCH] add tests --- test/fixtures/test-runner/index.test.tap | 13 ++++++ test/fixtures/test-runner/nested.test.cli.tap | 13 ++++++ test/fixtures/test-runner/nested.test.js | 12 ++++++ test/fixtures/test-runner/nested.test.tap | 41 +++++++++++++++++++ .../test-runner/{ => search-files}/index.js | 0 .../random.cjs => search-files/index.test.js} | 0 .../node_modules/test-nm.js | 0 .../{ => search-files}/random.test.mjs | 0 .../{ => search-files}/subdir/subdir_test.js | 0 .../test-runner/search-files/test/random.cjs | 4 ++ test/parallel/test-runner-cli.js | 2 +- test/parallel/test-runner-tap-protocol.js | 35 ++++++++++++++++ 12 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/index.test.tap create mode 100644 test/fixtures/test-runner/nested.test.cli.tap create mode 100644 test/fixtures/test-runner/nested.test.js create mode 100644 test/fixtures/test-runner/nested.test.tap rename test/fixtures/test-runner/{ => search-files}/index.js (100%) rename test/fixtures/test-runner/{test/random.cjs => search-files/index.test.js} (100%) rename test/fixtures/test-runner/{ => search-files}/node_modules/test-nm.js (100%) rename test/fixtures/test-runner/{ => search-files}/random.test.mjs (100%) rename test/fixtures/test-runner/{ => search-files}/subdir/subdir_test.js (100%) create mode 100644 test/fixtures/test-runner/search-files/test/random.cjs create mode 100644 test/parallel/test-runner-tap-protocol.js diff --git a/test/fixtures/test-runner/index.test.tap b/test/fixtures/test-runner/index.test.tap new file mode 100644 index 00000000000000..e1a0f6a14ea80e --- /dev/null +++ b/test/fixtures/test-runner/index.test.tap @@ -0,0 +1,13 @@ +TAP version 13 +# Subtest: this should pass +ok 1 - this should pass + --- + duration_ms: + ... +1..1 +# tests 1 +# pass 1 +# fail 0 +# skipped 0 +# todo 0 +# duration_ms: diff --git a/test/fixtures/test-runner/nested.test.cli.tap b/test/fixtures/test-runner/nested.test.cli.tap new file mode 100644 index 00000000000000..408706ec4748f4 --- /dev/null +++ b/test/fixtures/test-runner/nested.test.cli.tap @@ -0,0 +1,13 @@ +TAP version 13 +# Subtest: $FILE_PATH +ok 1 - $FILE_PATH + --- + duration_ms: + ... +1..1 +# tests 1 +# pass 1 +# fail 0 +# skipped 0 +# todo 0 +# duration_ms: diff --git a/test/fixtures/test-runner/nested.test.js b/test/fixtures/test-runner/nested.test.js new file mode 100644 index 00000000000000..05edea12ffc896 --- /dev/null +++ b/test/fixtures/test-runner/nested.test.js @@ -0,0 +1,12 @@ +'use strict'; +const test = require('node:test'); + +test('level 1', async (t) => { + await t.test('level 2.1', async (t) => { + await t.test('level 3', () => {}); + }); + await t.test('level 2.2', async (t) => { + await t.test('level 3', () => {}); + }); + await t.test('level 2.4', () => {}); +}); diff --git a/test/fixtures/test-runner/nested.test.tap b/test/fixtures/test-runner/nested.test.tap new file mode 100644 index 00000000000000..8da20ee1733b61 --- /dev/null +++ b/test/fixtures/test-runner/nested.test.tap @@ -0,0 +1,41 @@ +TAP version 13 +# Subtest: level 1 + # Subtest: level 2.1 + # Subtest: level 3 + ok 1 - level 3 + --- + duration_ms: + ... + 1..1 + ok 1 - level 2.1 + --- + duration_ms: + ... + # Subtest: level 2.2 + # Subtest: level 3 + ok 1 - level 3 + --- + duration_ms: + ... + 1..1 + ok 2 - level 2.2 + --- + duration_ms: + ... + # Subtest: level 2.4 + ok 3 - level 2.4 + --- + duration_ms: + ... + 1..3 +ok 1 - level 1 + --- + duration_ms: + ... +1..1 +# tests 1 +# pass 1 +# fail 0 +# skipped 0 +# todo 0 +# duration_ms: diff --git a/test/fixtures/test-runner/index.js b/test/fixtures/test-runner/search-files/index.js similarity index 100% rename from test/fixtures/test-runner/index.js rename to test/fixtures/test-runner/search-files/index.js diff --git a/test/fixtures/test-runner/test/random.cjs b/test/fixtures/test-runner/search-files/index.test.js similarity index 100% rename from test/fixtures/test-runner/test/random.cjs rename to test/fixtures/test-runner/search-files/index.test.js diff --git a/test/fixtures/test-runner/node_modules/test-nm.js b/test/fixtures/test-runner/search-files/node_modules/test-nm.js similarity index 100% rename from test/fixtures/test-runner/node_modules/test-nm.js rename to test/fixtures/test-runner/search-files/node_modules/test-nm.js diff --git a/test/fixtures/test-runner/random.test.mjs b/test/fixtures/test-runner/search-files/random.test.mjs similarity index 100% rename from test/fixtures/test-runner/random.test.mjs rename to test/fixtures/test-runner/search-files/random.test.mjs diff --git a/test/fixtures/test-runner/subdir/subdir_test.js b/test/fixtures/test-runner/search-files/subdir/subdir_test.js similarity index 100% rename from test/fixtures/test-runner/subdir/subdir_test.js rename to test/fixtures/test-runner/search-files/subdir/subdir_test.js diff --git a/test/fixtures/test-runner/search-files/test/random.cjs b/test/fixtures/test-runner/search-files/test/random.cjs new file mode 100644 index 00000000000000..2a722c504b9fa5 --- /dev/null +++ b/test/fixtures/test-runner/search-files/test/random.cjs @@ -0,0 +1,4 @@ +'use strict'; +const test = require('node:test'); + +test('this should pass'); diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 7bd95372a2d68b..00dfa0155fcc98 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -4,7 +4,7 @@ const assert = require('assert'); const { spawnSync } = require('child_process'); const { join } = require('path'); const fixtures = require('../common/fixtures'); -const testFixtures = fixtures.path('test-runner'); +const testFixtures = fixtures.path('test-runner/search-files'); { // File not found. diff --git a/test/parallel/test-runner-tap-protocol.js b/test/parallel/test-runner-tap-protocol.js new file mode 100644 index 00000000000000..236b1bb001c284 --- /dev/null +++ b/test/parallel/test-runner-tap-protocol.js @@ -0,0 +1,35 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const { spawnSync } = require('child_process'); +const fixtures = require('../common/fixtures'); + +function removeDuration(str) { + return str.replace(/duration_ms:? .+/g, 'duration_ms: '); +} + +{ + // sanity + const child = spawnSync(process.execPath, [fixtures.path('test-runner/index.test.js')]); + const stdout = removeDuration(child.stdout.toString()); + const expected = fixtures.readSync('test-runner/index.test.tap').toString(); + + assert.strictEqual(stdout, expected); +} +{ + // nested tests + const child = spawnSync(process.execPath, [fixtures.path('test-runner/nested.test.js')]); + const stdout = removeDuration(child.stdout.toString()); + const expected = fixtures.readSync('test-runner/nested.test.tap').toString(); + + assert.strictEqual(stdout, expected); +} +{ + // using test runner cli + const file = fixtures.path('test-runner/nested.test.js'); + const child = spawnSync(process.execPath, ['--test', fixtures.path('test-runner/nested.test.js')]); + const stdout = removeDuration(child.stdout.toString()); + const expected = fixtures.readSync('test-runner/nested.test.cli.tap').toString().replace(/\$FILE_PATH/g, file); + + assert.strictEqual(stdout, expected); +} \ No newline at end of file