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