From 558b2c72e847cca46efabcac970b856d59b6e85f Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Thu, 26 Sep 2024 09:52:18 +0200 Subject: [PATCH] test: debug --- test/parallel/test-runner-run.mjs | 72 ++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index 703f11375d7b45..5c26b2402a7d53 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -591,22 +591,46 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { it('should run with different cwd while in watch mode', async () => { const controller = new AbortController(); + let passed = 0; + let failedBeforeAbort = 0; + let failedAferAbort = 0; + let aborted = false; const stream = run({ cwd: fixtures.path('test-runner', 'cwd'), watch: true, signal: controller.signal, }).on('data', function({ type }) { if (type === 'test:watch:drained') { + aborted = true; controller.abort(); } }); - stream.on('test:fail', common.mustNotCall()); - stream.on('test:pass', common.mustCall(1)); + stream.on('test:fail', (data) => { + if (!aborted) { + failedBeforeAbort++; + } else { + failedAferAbort++; + } + }); + stream.on('test:pass', () => { + passed++; + }); + + // eslint-disable-next-line no-unused-vars + for await (const _ of stream); + + assert.strictEqual(failedBeforeAbort, 0); + assert.strictEqual(failedAferAbort, 0); + assert.strictEqual(passed, 1); }); it('should run with different cwd while in watch mode and isolation "none"', async () => { const controller = new AbortController(); + let passed = 0; + let failedBeforeAbort = 0; + let failedAferAbort = 0; + let aborted = false; const stream = run({ cwd: fixtures.path('test-runner', 'cwd'), watch: true, @@ -614,16 +638,36 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { isolation: 'none', }).on('data', function({ type }) { if (type === 'test:watch:drained') { + aborted = true; controller.abort(); } }); - stream.on('test:fail', common.mustNotCall()); - stream.on('test:pass', common.mustCall(1)); + stream.on('test:fail', (data) => { + if (!aborted) { + failedBeforeAbort++; + } else { + failedAferAbort++; + } + }); + stream.on('test:pass', () => { + passed++; + }); + + // eslint-disable-next-line no-unused-vars + for await (const _ of stream); + + assert.strictEqual(failedBeforeAbort, 0); + assert.strictEqual(failedAferAbort, 0); + assert.strictEqual(passed, 1); }); it('should run with different cwd while in watch mode and isolation "process"', async () => { const controller = new AbortController(); + let passed = 0; + let failedBeforeAbort = 0; + let failedAferAbort = 0; + let aborted = false; const stream = run({ cwd: fixtures.path('test-runner', 'cwd'), watch: true, @@ -631,12 +675,28 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { isolation: 'process', }).on('data', function({ type }) { if (type === 'test:watch:drained') { + aborted = true; controller.abort(); } }); - stream.on('test:fail', common.mustNotCall()); - stream.on('test:pass', common.mustCall(1)); + stream.on('test:fail', (data) => { + if (!aborted) { + failedBeforeAbort++; + } else { + failedAferAbort++; + } + }); + stream.on('test:pass', () => { + passed++; + }); + + // eslint-disable-next-line no-unused-vars + for await (const _ of stream); + + assert.strictEqual(failedBeforeAbort, 0); + assert.strictEqual(failedAferAbort, 0); + assert.strictEqual(passed, 1); }); });