11import '../common/index.mjs';
22import { before, describe, it } from 'node:test';
33import assert from 'node:assert';
4- import { spawnSync } from 'node:child_process';
54import { cp } from 'node:fs/promises';
65import tmpdir from '../common/tmpdir.js';
76import fixtures from '../common/fixtures.js';
7+ import { spawnSyncAndAssert } from '../common/child_process.js';
88const skipIfNoInspector = {
99 skip: !process.features.inspector ? 'inspector disabled' : false
1010};
@@ -57,14 +57,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
5757 '--test-reporter=tap',
5858 '--no-experimental-strip-types',
5959 ];
60- const result = spawnSync (process.execPath, args, {
60+ spawnSyncAndAssert (process.execPath, args, {
6161 env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
6262 cwd: tmpdir.path
63+ }, {
64+ stderr: '',
65+ stdout: new RegExp(RegExp.escape(report)),
6366 });
64-
65- assert.strictEqual(result.stderr.toString(), '');
66- assert(result.stdout.toString().includes(report));
67- assert.strictEqual(result.status, 0);
6867 });
6968
7069 it('should exclude test files from coverage by default', async () => {
@@ -74,14 +73,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
7473 '--experimental-test-coverage',
7574 '--test-reporter=tap',
7675 ];
77- const result = spawnSync (process.execPath, args, {
76+ spawnSyncAndAssert (process.execPath, args, {
7877 env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
7978 cwd: tmpdir.path
79+ }, {
80+ stderr: '',
81+ stdout: assertDefaultExclusions,
8082 });
81-
82- assert.strictEqual(result.stderr.toString(), '');
83- assertDefaultExclusions(result.stdout.toString());
84- assert.strictEqual(result.status, 0);
8583 });
8684
8785 it('should exclude ts test files', async () => {
@@ -91,14 +89,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
9189 '--disable-warning=ExperimentalWarning',
9290 '--test-reporter=tap',
9391 ];
94- const result = spawnSync (process.execPath, args, {
92+ spawnSyncAndAssert (process.execPath, args, {
9593 env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
9694 cwd: tmpdir.path
95+ }, {
96+ stderr: '',
97+ stdout: assertDefaultExclusions,
9798 });
98-
99- assert.strictEqual(result.stderr.toString(), '');
100- assertDefaultExclusions(result.stdout.toString());
101- assert.strictEqual(result.status, 0);
10299 });
103100
104101 it('should exclude dotfile test files from coverage by default', async () => {
@@ -109,14 +106,15 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
109106 '--test-reporter=tap',
110107 'test/.dotfile.cjs',
111108 ];
112- const result = spawnSync (process.execPath, args, {
109+ spawnSyncAndAssert (process.execPath, args, {
113110 env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
114111 cwd: tmpdir.path
112+ }, {
113+ stderr: '',
114+ stdout(output) {
115+ assertDefaultExclusions(output);
116+ assert.doesNotMatch(output, /#\s+\.dotfile\.cjs\s+\|/);
117+ },
115118 });
116-
117- assert.strictEqual(result.stderr.toString(), '');
118- assertDefaultExclusions(result.stdout.toString());
119- assert.doesNotMatch(result.stdout.toString(), /#\s+\.dotfile\.cjs\s+\|/);
120- assert.strictEqual(result.status, 0);
121119 });
122120});
0 commit comments