-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_runner: allow
--import
with no isolation
Co-Authored-By: Colin Ihrig <[email protected]> PR-URL: #54697 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
- Loading branch information
Showing
5 changed files
with
112 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import('node:test').then((test) => { | ||
test.before(() => console.log('before(): global')); | ||
test.beforeEach(() => console.log('beforeEach(): global')); | ||
test.after(() => console.log('after(): global')); | ||
test.afterEach(() => console.log('afterEach(): global')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
'use strict'; | ||
const { before, beforeEach, after, afterEach, test, suite } = require('node:test'); | ||
|
||
function record(data) { | ||
globalThis.GLOBAL_ORDER.push(data); | ||
console.log(data); | ||
} | ||
|
||
before(function() { | ||
GLOBAL_ORDER.push(`before two: ${this.name}`); | ||
record(`before two: ${this.name}`); | ||
}); | ||
|
||
beforeEach(function() { | ||
GLOBAL_ORDER.push(`beforeEach two: ${this.name}`); | ||
record(`beforeEach two: ${this.name}`); | ||
}); | ||
|
||
after(function() { | ||
GLOBAL_ORDER.push(`after two: ${this.name}`); | ||
record(`after two: ${this.name}`); | ||
}); | ||
|
||
afterEach(function() { | ||
GLOBAL_ORDER.push(`afterEach two: ${this.name}`); | ||
record(`afterEach two: ${this.name}`); | ||
}); | ||
|
||
suite('suite two', function() { | ||
GLOBAL_ORDER.push(this.name); | ||
record(this.name); | ||
|
||
before(function() { | ||
GLOBAL_ORDER.push(`before suite two: ${this.name}`); | ||
record(`before suite two: ${this.name}`); | ||
}); | ||
|
||
test('suite two - test', { only: true }, function() { | ||
GLOBAL_ORDER.push(this.name); | ||
record(this.name); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as common from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { test } from 'node:test'; | ||
|
||
const testArguments = [ | ||
'--test', | ||
'--test-reporter=spec', | ||
'--experimental-test-isolation=none', | ||
]; | ||
|
||
const testFiles = [ | ||
fixtures.path('test-runner', 'no-isolation', 'one.test.js'), | ||
fixtures.path('test-runner', 'no-isolation', 'two.test.js'), | ||
]; | ||
|
||
const order = [ | ||
'before(): global', | ||
|
||
'before one: <root>', | ||
'suite one', | ||
|
||
'before two: <root>', | ||
'suite two', | ||
|
||
'beforeEach(): global', | ||
'beforeEach one: suite one - test', | ||
'beforeEach two: suite one - test', | ||
|
||
'suite one - test', | ||
'afterEach(): global', | ||
'afterEach one: suite one - test', | ||
'afterEach two: suite one - test', | ||
|
||
'beforeEach(): global', | ||
'beforeEach one: test one', | ||
'beforeEach two: test one', | ||
'test one', | ||
|
||
'afterEach(): global', | ||
'afterEach one: test one', | ||
'afterEach two: test one', | ||
|
||
'before suite two: suite two', | ||
'beforeEach(): global', | ||
'beforeEach one: suite two - test', | ||
'beforeEach two: suite two - test', | ||
|
||
'suite two - test', | ||
'afterEach(): global', | ||
'afterEach one: suite two - test', | ||
'afterEach two: suite two - test', | ||
|
||
'after(): global', | ||
'after one: <root>', | ||
'after two: <root>', | ||
]; | ||
|
||
test('Using --require to define global hooks works', async (t) => { | ||
const spawned = await common.spawnPromisified(process.execPath, [ | ||
...testArguments, | ||
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.js'), | ||
...testFiles, | ||
]); | ||
|
||
t.assert.ok(spawned.stdout.includes(order.join('\n'))); | ||
}); | ||
|
||
test('Using --import to define global hooks works', async (t) => { | ||
const spawned = await common.spawnPromisified(process.execPath, [ | ||
...testArguments, | ||
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.js'), | ||
...testFiles, | ||
]); | ||
|
||
t.assert.ok(spawned.stdout.includes(order.join('\n'))); | ||
}); |