Files
node/test/parallel/test-runner-no-async-hooks.js
Matteo Collina 6698675526 test_runner: use AsyncLocalStorage instead of async_hooks
Track the test that owns the current async context with an
AsyncLocalStorage instead of a createHook() init/destroy map.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66795
Refs: https://github.com/nodejs/node/pull/61030
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-10-20 14:00:22 +00:00

23 lines
718 B
JavaScript

// Flags: --expose-internals
'use strict';
// The test runner tracks which test owns the current async context with
// AsyncLocalStorage, so it must not install any async_hooks.
const common = require('../common');
const assert = require('assert');
const { setTimeout } = require('timers/promises');
const { enabledHooksExist } = require('internal/async_hooks');
const { test } = require('node:test');
test('no async hooks are enabled', common.mustCall(async (t) => {
assert.strictEqual(enabledHooksExist(), false);
await t.test('subtest', common.mustCall(async () => {
await setTimeout(1);
assert.strictEqual(enabledHooksExist(), false);
}));
assert.strictEqual(enabledHooksExist(), false);
}));