|
| 1 | +import * as common from '../common/index.mjs'; |
| 2 | +import * as fixtures from '../common/fixtures.mjs'; |
| 3 | +import { test } from 'node:test'; |
| 4 | + |
| 5 | +const testArguments = [ |
| 6 | + '--test', |
| 7 | + '--experimental-test-isolation=none', |
| 8 | +]; |
| 9 | + |
| 10 | +const testFiles = [ |
| 11 | + fixtures.path('test-runner', 'no-isolation', 'one.test.js'), |
| 12 | + fixtures.path('test-runner', 'no-isolation', 'two.test.js'), |
| 13 | +]; |
| 14 | + |
| 15 | +const order = [ |
| 16 | + 'before(): global', |
| 17 | + |
| 18 | + 'before one: <root>', |
| 19 | + 'suite one', |
| 20 | + |
| 21 | + 'before two: <root>', |
| 22 | + 'suite two', |
| 23 | + |
| 24 | + 'beforeEach(): global', |
| 25 | + 'beforeEach one: suite one - test', |
| 26 | + 'beforeEach two: suite one - test', |
| 27 | + |
| 28 | + 'suite one - test', |
| 29 | + 'afterEach(): global', |
| 30 | + 'afterEach one: suite one - test', |
| 31 | + 'afterEach two: suite one - test', |
| 32 | + |
| 33 | + 'beforeEach(): global', |
| 34 | + 'beforeEach one: test one', |
| 35 | + 'beforeEach two: test one', |
| 36 | + 'test one', |
| 37 | + |
| 38 | + 'afterEach(): global', |
| 39 | + 'afterEach one: test one', |
| 40 | + 'afterEach two: test one', |
| 41 | + |
| 42 | + 'before suite two: suite two', |
| 43 | + 'beforeEach(): global', |
| 44 | + 'beforeEach one: suite two - test', |
| 45 | + 'beforeEach two: suite two - test', |
| 46 | + |
| 47 | + 'suite two - test', |
| 48 | + 'afterEach(): global', |
| 49 | + 'afterEach one: suite two - test', |
| 50 | + 'afterEach two: suite two - test', |
| 51 | + |
| 52 | + 'after(): global', |
| 53 | + 'after one: <root>', |
| 54 | + 'after two: <root>', |
| 55 | +]; |
| 56 | + |
| 57 | +test('Using --require to define global hooks works', async (t) => { |
| 58 | + const spawned = await common.spawnPromisified(process.execPath, [ |
| 59 | + ...testArguments, |
| 60 | + '--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.js'), |
| 61 | + ...testFiles, |
| 62 | + ]); |
| 63 | + |
| 64 | + t.assert.ok(spawned.stdout.includes(order.join('\n'))); |
| 65 | +}); |
| 66 | + |
| 67 | +test('Using --import to define global hooks works', async (t) => { |
| 68 | + const spawned = await common.spawnPromisified(process.execPath, [ |
| 69 | + ...testArguments, |
| 70 | + '--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.js'), |
| 71 | + ...testFiles, |
| 72 | + ]); |
| 73 | + |
| 74 | + t.assert.ok(spawned.stdout.includes(order.join('\n'))); |
| 75 | +}); |
0 commit comments