Skip to content

Commit

Permalink
test_runner: pass abortSignal to test files
Browse files Browse the repository at this point in the history
PR-URL: #50630
Fixes: #50583
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
MoLow authored and UlisesGascon committed Dec 11, 2023
1 parent 2589a5a commit 2c72ed8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/runner.js
Expand Up @@ -361,7 +361,7 @@ class FileTest extends Test {

function runTestFile(path, filesWatcher, opts) {
const watchMode = filesWatcher != null;
const subtest = opts.root.createSubtest(FileTest, path, async (t) => {
const subtest = opts.root.createSubtest(FileTest, path, { __proto__: null, signal: opts.signal }, async (t) => {
const args = getRunArgs(path, opts);
const stdio = ['pipe', 'pipe', 'pipe'];
const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8' };
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-runner-run.mjs
Expand Up @@ -184,6 +184,17 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
});

describe('AbortSignal', () => {
it('should accept a signal', async () => {
const stream = run({ signal: AbortSignal.timeout(50), files: [
fixtures.path('test-runner', 'never_ending_sync.js'),
fixtures.path('test-runner', 'never_ending_async.js'),
] });
stream.on('test:fail', common.mustCall(2));
stream.on('test:pass', common.mustNotCall());
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});

it('should stop watch mode when abortSignal aborts', async () => {
const controller = new AbortController();
const result = await run({
Expand Down

0 comments on commit 2c72ed8

Please sign in to comment.