mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00
test: fix dangling promise in test_runner no isolation test setup
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
PR-URL: https://github.com/nodejs/node/pull/57595 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
This commit is contained in:
parent
35188cd677
commit
5a2614fd03
6
test/fixtures/test-runner/no-isolation/global-hooks.cjs
vendored
Normal file
6
test/fixtures/test-runner/no-isolation/global-hooks.cjs
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
const test = require('node: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'));
|
@ -1,6 +0,0 @@
|
||||
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'));
|
||||
});
|
6
test/fixtures/test-runner/no-isolation/global-hooks.mjs
vendored
Normal file
6
test/fixtures/test-runner/no-isolation/global-hooks.mjs
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import test from 'node: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'));
|
68
test/known_issues/test-runner-no-isolation-hooks.mjs
Normal file
68
test/known_issues/test-runner-no-isolation-hooks.mjs
Normal file
@ -0,0 +1,68 @@
|
||||
import * as common from '../common/index.mjs';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
import { test } from 'node:test';
|
||||
|
||||
const testArguments = [
|
||||
'--test',
|
||||
'--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',
|
||||
|
||||
'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>',
|
||||
].join('\n');
|
||||
|
||||
/**
|
||||
* TODO: The `--require` flag is processed in `loadPreloadModules` (process/pre_execution.js) BEFORE
|
||||
* the root test is created by the test runner. This causes a global `before` hook to register (and
|
||||
* run) but then the root test-case is created, causing the "subsequent" hooks to get lost. This
|
||||
* behaviour (CJS route only) is different from the ESM route, where test runner explicitly handles
|
||||
* `--import` in `root.runInAsyncScope` (test_runner/runner.js).
|
||||
* @see https://github.com/nodejs/node/pull/57595#issuecomment-2770724492
|
||||
* @see https://github.com/nodejs/node/issues/57728
|
||||
* Moved from test/parallel/test-runner-no-isolation-hooks.mjs
|
||||
*/
|
||||
test('use --require to define global hooks', async (t) => {
|
||||
const { stdout } = await common.spawnPromisified(process.execPath, [
|
||||
...testArguments,
|
||||
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.cjs'),
|
||||
...testFiles,
|
||||
]);
|
||||
|
||||
const testHookOutput = stdout.split('\n▶')[0];
|
||||
|
||||
t.assert.equal(testHookOutput, order);
|
||||
});
|
@ -43,24 +43,28 @@ const order = [
|
||||
'after(): global',
|
||||
'after one: <root>',
|
||||
'after two: <root>',
|
||||
];
|
||||
].join('\n');
|
||||
|
||||
test('Using --require to define global hooks works', async (t) => {
|
||||
const spawned = await common.spawnPromisified(process.execPath, [
|
||||
test('use --import (CJS) to define global hooks', async (t) => {
|
||||
const { stdout } = await common.spawnPromisified(process.execPath, [
|
||||
...testArguments,
|
||||
'--require', fixtures.path('test-runner', 'no-isolation', 'global-hooks.js'),
|
||||
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.cjs'),
|
||||
...testFiles,
|
||||
]);
|
||||
|
||||
t.assert.ok(spawned.stdout.includes(order.join('\n')));
|
||||
const testHookOutput = stdout.split('\n▶')[0];
|
||||
|
||||
t.assert.equal(testHookOutput, order);
|
||||
});
|
||||
|
||||
test('Using --import to define global hooks works', async (t) => {
|
||||
const spawned = await common.spawnPromisified(process.execPath, [
|
||||
test('use --import (ESM) to define global hooks', async (t) => {
|
||||
const { stdout } = await common.spawnPromisified(process.execPath, [
|
||||
...testArguments,
|
||||
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.js'),
|
||||
'--import', fixtures.fileURL('test-runner', 'no-isolation', 'global-hooks.mjs'),
|
||||
...testFiles,
|
||||
]);
|
||||
|
||||
t.assert.ok(spawned.stdout.includes(order.join('\n')));
|
||||
const testHookOutput = stdout.split('\n▶')[0];
|
||||
|
||||
t.assert.equal(testHookOutput, order);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user