|
| 1 | +// Flags: --no-warnings |
| 2 | + |
| 3 | +import '../common/index.mjs'; |
| 4 | +import * as fixtures from '../common/fixtures.mjs'; |
| 5 | +import tmpdir from '../common/tmpdir.js'; |
| 6 | +import assert from 'node:assert'; |
| 7 | +import { writeFileSync } from 'node:fs'; |
| 8 | +import { test, run } from 'node:test'; |
| 9 | + |
| 10 | +const files = [ |
| 11 | + fixtures.path('test-runner', 'execution-ordered-bypass', 'slow.mjs'), |
| 12 | + fixtures.path('test-runner', 'execution-ordered-bypass', 'fast-fail.mjs'), |
| 13 | +]; |
| 14 | + |
| 15 | +test('execution-ordered events bypass FileTest declaration-order buffer', async () => { |
| 16 | + tmpdir.refresh(); |
| 17 | + const goFile = tmpdir.resolve('execution-ordered-go'); |
| 18 | + |
| 19 | + const stream = run({ |
| 20 | + files, |
| 21 | + isolation: 'process', |
| 22 | + concurrency: true, |
| 23 | + env: { ...process.env, NODE_TEST_GO_FILE: goFile }, |
| 24 | + }); |
| 25 | + |
| 26 | + const events = []; |
| 27 | + |
| 28 | + stream.on('test:complete', (data) => { |
| 29 | + if (data.name === 'slow' || data.name === 'fast-fail') { |
| 30 | + events.push(`complete:${data.name}`); |
| 31 | + if (data.name === 'fast-fail') { |
| 32 | + writeFileSync(goFile, ''); |
| 33 | + } |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + stream.on('test:fail', (data) => { |
| 38 | + if (data.name === 'fast-fail') { |
| 39 | + events.push(`fail:${data.name}`); |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + // eslint-disable-next-line no-unused-vars |
| 44 | + for await (const _ of stream); |
| 45 | + |
| 46 | + const completeFast = events.indexOf('complete:fast-fail'); |
| 47 | + const completeSlow = events.indexOf('complete:slow'); |
| 48 | + const failFast = events.indexOf('fail:fast-fail'); |
| 49 | + |
| 50 | + assert.notStrictEqual(completeFast, -1); |
| 51 | + assert.notStrictEqual(completeSlow, -1); |
| 52 | + assert.notStrictEqual(failFast, -1); |
| 53 | + |
| 54 | + assert.ok( |
| 55 | + completeFast < completeSlow, |
| 56 | + `test:complete for fast-fail should arrive before slow; events=${events.join(', ')}`, |
| 57 | + ); |
| 58 | + |
| 59 | + // test:fail is declaration-ordered, so the bypass must not affect it. |
| 60 | + assert.ok( |
| 61 | + failFast > completeSlow, |
| 62 | + `test:fail for fast-fail should arrive after test:complete for slow; events=${events.join(', ')}`, |
| 63 | + ); |
| 64 | +}); |
0 commit comments