mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test_runner: allow --import
with no isolation
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com> PR-URL: https://github.com/nodejs/node/pull/54697 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
parent
a202666399
commit
5c8d0ebf30
@ -34,6 +34,7 @@ const { spawn } = require('child_process');
|
|||||||
const { finished } = require('internal/streams/end-of-stream');
|
const { finished } = require('internal/streams/end-of-stream');
|
||||||
const { resolve } = require('path');
|
const { resolve } = require('path');
|
||||||
const { DefaultDeserializer, DefaultSerializer } = require('v8');
|
const { DefaultDeserializer, DefaultSerializer } = require('v8');
|
||||||
|
const { getOptionValue } = require('internal/options');
|
||||||
const { Interface } = require('internal/readline/interface');
|
const { Interface } = require('internal/readline/interface');
|
||||||
const { deserializeError } = require('internal/error_serdes');
|
const { deserializeError } = require('internal/error_serdes');
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
@ -697,6 +698,11 @@ function run(options = kEmptyObject) {
|
|||||||
|
|
||||||
root.harness.bootstrapPromise = promise;
|
root.harness.bootstrapPromise = promise;
|
||||||
|
|
||||||
|
const userImports = getOptionValue('--import');
|
||||||
|
for (let i = 0; i < userImports.length; i++) {
|
||||||
|
await cascadedLoader.import(userImports[i], parentURL, kEmptyObject);
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < testFiles.length; ++i) {
|
for (let i = 0; i < testFiles.length; ++i) {
|
||||||
const testFile = testFiles[i];
|
const testFile = testFiles[i];
|
||||||
const fileURL = pathToFileURL(testFile);
|
const fileURL = pathToFileURL(testFile);
|
||||||
|
6
test/fixtures/test-runner/no-isolation/global-hooks.js
vendored
Normal file
6
test/fixtures/test-runner/no-isolation/global-hooks.js
vendored
Normal file
@ -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'));
|
||||||
|
});
|
@ -3,30 +3,35 @@ const { before, beforeEach, after, afterEach, test, suite } = require('node:test
|
|||||||
|
|
||||||
globalThis.GLOBAL_ORDER = [];
|
globalThis.GLOBAL_ORDER = [];
|
||||||
|
|
||||||
|
function record(data) {
|
||||||
|
globalThis.GLOBAL_ORDER.push(data);
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
GLOBAL_ORDER.push(`before one: ${this.name}`);
|
record(`before one: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
GLOBAL_ORDER.push(`beforeEach one: ${this.name}`);
|
record(`beforeEach one: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function() {
|
after(function() {
|
||||||
GLOBAL_ORDER.push(`after one: ${this.name}`);
|
record(`after one: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
GLOBAL_ORDER.push(`afterEach one: ${this.name}`);
|
record(`afterEach one: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('suite one', function() {
|
suite('suite one', function() {
|
||||||
GLOBAL_ORDER.push(this.name);
|
record(this.name);
|
||||||
|
|
||||||
test('suite one - test', { only: true }, function() {
|
test('suite one - test', { only: true }, function() {
|
||||||
GLOBAL_ORDER.push(this.name);
|
record(this.name);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test one', function() {
|
test('test one', function() {
|
||||||
GLOBAL_ORDER.push(this.name);
|
record(this.name);
|
||||||
});
|
});
|
||||||
|
@ -1,30 +1,35 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const { before, beforeEach, after, afterEach, test, suite } = require('node:test');
|
const { before, beforeEach, after, afterEach, test, suite } = require('node:test');
|
||||||
|
|
||||||
|
function record(data) {
|
||||||
|
globalThis.GLOBAL_ORDER.push(data);
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
GLOBAL_ORDER.push(`before two: ${this.name}`);
|
record(`before two: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
GLOBAL_ORDER.push(`beforeEach two: ${this.name}`);
|
record(`beforeEach two: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function() {
|
after(function() {
|
||||||
GLOBAL_ORDER.push(`after two: ${this.name}`);
|
record(`after two: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
GLOBAL_ORDER.push(`afterEach two: ${this.name}`);
|
record(`afterEach two: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('suite two', function() {
|
suite('suite two', function() {
|
||||||
GLOBAL_ORDER.push(this.name);
|
record(this.name);
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
GLOBAL_ORDER.push(`before suite two: ${this.name}`);
|
record(`before suite two: ${this.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('suite two - test', { only: true }, function() {
|
test('suite two - test', { only: true }, function() {
|
||||||
GLOBAL_ORDER.push(this.name);
|
record(this.name);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
75
test/parallel/test-runner-no-isolation-hooks.mjs
Normal file
75
test/parallel/test-runner-no-isolation-hooks.mjs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import * as common from '../common/index.mjs';
|
||||||
|
import * as fixtures from '../common/fixtures.mjs';
|
||||||
|
import { test } from 'node:test';
|
||||||
|
|
||||||
|
const testArguments = [
|
||||||
|
'--test',
|
||||||
|
'--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')));
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user