Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Jun 14, 2022
1 parent 6ba42fc commit fcd4f72
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 1 deletion.
13 changes: 13 additions & 0 deletions test/fixtures/test-runner/index.test.tap
Original file line number Diff line number Diff line change
@@ -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:
13 changes: 13 additions & 0 deletions test/fixtures/test-runner/nested.test.cli.tap
Original file line number Diff line number Diff line change
@@ -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:
12 changes: 12 additions & 0 deletions test/fixtures/test-runner/nested.test.js
Original file line number Diff line number Diff line change
@@ -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', () => {});
});
41 changes: 41 additions & 0 deletions test/fixtures/test-runner/nested.test.tap
Original file line number Diff line number Diff line change
@@ -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:
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test/fixtures/test-runner/search-files/test/random.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');

test('this should pass');
2 changes: 1 addition & 1 deletion test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 35 additions & 0 deletions test/parallel/test-runner-tap-protocol.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit fcd4f72

Please sign in to comment.