|
| 1 | +// Flags: --no-warnings |
| 2 | + |
| 3 | +import '../common/index.mjs'; |
| 4 | +import * as fixtures from '../common/fixtures.mjs'; |
| 5 | +import assert from 'node:assert'; |
| 6 | +import { test, run } from 'node:test'; |
| 7 | + |
| 8 | +const files = [ |
| 9 | + fixtures.path('test-runner', 'execution-ordered-bypass', 'slow.mjs'), |
| 10 | + fixtures.path('test-runner', 'execution-ordered-bypass', 'fast-fail.mjs'), |
| 11 | +]; |
| 12 | + |
| 13 | +test('execution-ordered events bypass FileTest declaration-order buffer', async () => { |
| 14 | + // Concurrency must be a number so the runner does not collapse it to 1 on |
| 15 | + // single-core CI runners (where `concurrency: true` resolves to |
| 16 | + // `availableParallelism() - 1`). Without two slots the runner spawns the |
| 17 | + // files sequentially and fast-fail never starts while slow is sleeping. |
| 18 | + const stream = run({ |
| 19 | + files, |
| 20 | + isolation: 'process', |
| 21 | + concurrency: 2, |
| 22 | + }); |
| 23 | + |
| 24 | + const events = []; |
| 25 | + |
| 26 | + stream.on('test:complete', (data) => { |
| 27 | + if (data.name === 'slow' || data.name === 'fast-fail') { |
| 28 | + events.push(`complete:${data.name}`); |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + stream.on('test:fail', (data) => { |
| 33 | + if (data.name === 'fast-fail') { |
| 34 | + events.push(`fail:${data.name}`); |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + // eslint-disable-next-line no-unused-vars |
| 39 | + for await (const _ of stream); |
| 40 | + |
| 41 | + const completeFast = events.indexOf('complete:fast-fail'); |
| 42 | + const completeSlow = events.indexOf('complete:slow'); |
| 43 | + const failFast = events.indexOf('fail:fast-fail'); |
| 44 | + |
| 45 | + assert.notStrictEqual(completeFast, -1); |
| 46 | + assert.notStrictEqual(completeSlow, -1); |
| 47 | + assert.notStrictEqual(failFast, -1); |
| 48 | + |
| 49 | + assert.ok( |
| 50 | + completeFast < completeSlow, |
| 51 | + `test:complete for fast-fail should arrive before slow; events=${events.join(', ')}`, |
| 52 | + ); |
| 53 | + |
| 54 | + // test:fail is declaration-ordered, so the bypass must not affect it. |
| 55 | + assert.ok( |
| 56 | + failFast > completeSlow, |
| 57 | + `test:fail for fast-fail should arrive after test:complete for slow; events=${events.join(', ')}`, |
| 58 | + ); |
| 59 | +}); |
0 commit comments