Skip to content

Commit 2851a03

Browse files
committed
test: use fixture for isolation=none coverage runner script
1 parent 90b9f27 commit 2851a03

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { run } from 'node:test';
2+
import { join } from 'node:path';
3+
4+
const stream = run({
5+
files: [join(import.meta.dirname, 'tests', 'foo.test.mjs')],
6+
coverage: true,
7+
isolation: 'none',
8+
cwd: import.meta.dirname,
9+
});
10+
stream.on('test:fail', () => process.exit(10));
11+
let summary;
12+
stream.on('test:coverage', (event) => { summary = event.summary; });
13+
for await (const _ of stream);
14+
if (!summary || summary.files.length === 0) process.exit(11);
15+
const hasSrc = summary.files.some((f) => f.path.endsWith('foo.mjs') && !f.path.endsWith('foo.test.mjs'));
16+
const hasTest = summary.files.some((f) => f.path.endsWith('foo.test.mjs'));
17+
if (!hasSrc) process.exit(12);
18+
if (hasTest) process.exit(13);

test/parallel/test-runner-coverage-isolation-none-api.mjs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as common from '../common/index.mjs';
22
import { before, describe, it, run } from 'node:test';
33
import assert from 'node:assert';
44
import { spawnSync } from 'node:child_process';
5-
import { cp, writeFile } from 'node:fs/promises';
5+
import { cp } from 'node:fs/promises';
66
import { join, sep } from 'node:path';
77
import tmpdir from '../common/tmpdir.js';
88
import fixtures from '../common/fixtures.js';
@@ -58,30 +58,9 @@ describe('run() coverage with isolation: none', skipIfNoInspector, () => {
5858
}
5959

6060
it('is idempotent when --experimental-test-coverage is also passed', async () => {
61-
const runnerPath = join(tmpdir.path, 'runner.mjs');
62-
await writeFile(runnerPath, `\
63-
import { run } from 'node:test';
64-
import { join } from 'node:path';
65-
66-
const stream = run({
67-
files: [join(import.meta.dirname, 'tests', 'foo.test.mjs')],
68-
coverage: true,
69-
isolation: 'none',
70-
cwd: import.meta.dirname,
71-
});
72-
stream.on('test:fail', () => process.exit(10));
73-
let summary;
74-
stream.on('test:coverage', (event) => { summary = event.summary; });
75-
for await (const _ of stream);
76-
if (!summary || summary.files.length === 0) process.exit(11);
77-
const hasSrc = summary.files.some((f) => f.path.endsWith('foo.mjs') && !f.path.endsWith('foo.test.mjs'));
78-
const hasTest = summary.files.some((f) => f.path.endsWith('foo.test.mjs'));
79-
if (!hasSrc) process.exit(12);
80-
if (hasTest) process.exit(13);
81-
`);
8261
const result = spawnSync(process.execPath, [
8362
'--experimental-test-coverage',
84-
runnerPath,
63+
join(tmpdir.path, 'runner.mjs'),
8564
], { cwd: tmpdir.path });
8665
assert.strictEqual(
8766
result.status,

0 commit comments

Comments
 (0)