Skip to content

Commit 4e93338

Browse files
committed
test: use sync file in test-runner-output
1 parent a32f885 commit 4e93338

File tree

5 files changed

+65
-25
lines changed

5 files changed

+65
-25
lines changed

test/fixtures/test-runner/bailout/parallel-output/long-running-test.test.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import { writeFile } from 'node:fs/promises';
12
import { describe, it } from 'node:test';
3+
import { setTimeout } from 'node:timers/promises';
4+
5+
const testSyncPath = process.env.__TEST_SYNC_PATH__;
6+
const testSyncFile = process.env.__TEST_SYNC_FILE__;
27

38
describe('long-running-test', async () => {
49
it('first', async (t) => {
5-
t.assert.ok(true, 'First test passed');
6-
});
10+
// Create a file to signal that the second test has started
11+
writeFile(`${testSyncPath}/${testSyncFile}`, 'file content');
712

8-
it('second', async () => {
913
while (true) {
1014
// a long running test
11-
await new Promise((resolve) => setTimeout(resolve, 2500));
15+
await setTimeout(5000);
1216
}
1317
throw new Error('Second test should not run');
1418
});

test/fixtures/test-runner/bailout/parallel-output/test-with-setup.test.mjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
import { describe, it, before } from 'node:test';
1+
import { existsSync } from 'node:fs';
2+
import { describe, it } from 'node:test';
3+
4+
const testSyncPath = process.env.__TEST_SYNC_PATH__;
5+
const testSyncFile = process.env.__TEST_SYNC_FILE__;
26

37
describe('test-with-setup', { concurrency: false }, () => {
4-
before(async () => {
5-
// Give some time to the concurrent test to start
6-
await new Promise((resolve) => setTimeout(resolve, 2500));
8+
it('awaits second test to start running before passing', async (t) => {
9+
// Wait for the second test to run and create the file
10+
await t.waitFor(
11+
() => {
12+
const exist = existsSync(`${testSyncPath}/${testSyncFile}`);
13+
if (!exist) {
14+
throw new Error('Second file does not exist yet');
15+
}
16+
},
17+
{
18+
interval: 1000,
19+
timeout: 60_000,
20+
},
21+
);
722
});
823

924
it('first', async () => {

test/fixtures/test-runner/output/bail-concurrent-spec.snapshot

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
▶ long-running-test
2-
✔ first (*ms)
1+
▶ long-running-test.test.mjs
32
▶ test-with-setup
3+
✔ awaits second test to start running before passing (*ms)
44
✖ first (*ms)
55
Error: First test failed
6+
*
7+
*
8+
*
69
*
710
*
811
*
@@ -11,11 +14,11 @@
1114
*
1215

1316
✖ Bail out!
14-
ℹ tests 3
17+
ℹ tests 4
1518
ℹ suites 1
1619
ℹ pass 1
1720
ℹ fail 1
18-
ℹ cancelled 1
21+
ℹ cancelled 2
1922
ℹ skipped 0
2023
ℹ todo 0
2124
ℹ duration_ms *
@@ -25,6 +28,9 @@
2528
*
2629
✖ first (*ms)
2730
Error: First test failed
31+
*
32+
*
33+
*
2834
*
2935
*
3036
*
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
TAP version 13
2-
# Subtest: long-running-test
3-
# Subtest: first
4-
ok 1 - first
2+
# Subtest: long-running-test.test.mjs
3+
# Subtest: test-with-setup
4+
# Subtest: awaits second test to start running before passing
5+
ok 1 - awaits second test to start running before passing
56
---
67
duration_ms: *
78
type: 'test'
89
...
9-
# Subtest: test-with-setup
1010
# Subtest: first
11-
not ok 1 - first
11+
not ok 2 - first
1212
---
1313
duration_ms: *
1414
type: 'test'
@@ -17,6 +17,9 @@ TAP version 13
1717
error: 'First test failed'
1818
code: 'ERR_TEST_FAILURE'
1919
stack: |-
20+
*
21+
*
22+
*
2023
*
2124
*
2225
*
@@ -25,14 +28,14 @@ TAP version 13
2528
*
2629
...
2730
# Subtest: second
28-
1..2
31+
1..3
2932
Bail out!
30-
1..1
31-
# tests 3
33+
1..2
34+
# tests 4
3235
# suites 1
3336
# pass 1
3437
# fail 1
35-
# cancelled 1
38+
# cancelled 2
3639
# skipped 0
3740
# todo 0
3841
# duration_ms *

test/parallel/test-runner-output.mjs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { describe, it } from 'node:test';
55
import { hostname } from 'node:os';
66
import { chdir, cwd } from 'node:process';
77
import { fileURLToPath } from 'node:url';
8+
import tmpdir from '../common/tmpdir.js';
9+
10+
tmpdir.refresh();
811

912
const skipForceColors =
1013
process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' ||
@@ -298,20 +301,29 @@ const tests = [
298301
{
299302
name: 'test-runner/output/bail-concurrent-spec.mjs',
300303
transform: specTransform,
304+
env: {
305+
__TEST_SYNC_PATH__: tmpdir.path,
306+
__TEST_SYNC_FILE__: 'bail-concurrent-spec'
307+
},
301308
},
302309
{
303310
name: 'test-runner/output/bail-sequential-spec.js',
304311
transform: specTransform,
305312
},
306-
{ name: 'test-runner/output/bail-concurrent-tap.mjs' },
307-
313+
{
314+
name: 'test-runner/output/bail-concurrent-tap.mjs',
315+
env: {
316+
__TEST_SYNC_PATH__: tmpdir.path,
317+
__TEST_SYNC_FILE__: 'bail-concurrent-tap'
318+
},
319+
},
308320
{ name: 'test-runner/output/bail-sequential-tap.js' },
309321
]
310322
.filter(Boolean)
311-
.map(({ flags, name, tty, transform }) => ({
323+
.map(({ flags, name, tty, transform, env }) => ({
312324
name,
313325
fn: common.mustCall(async () => {
314-
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty, flags });
326+
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty, flags, env });
315327
}),
316328
}));
317329

0 commit comments

Comments
 (0)