File
Blob: src/workerd/api/node/tests/async_hooks-nodejs-test.js
| 1 | // Copyright (c) 2025 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | import async_hooks from 'node:async_hooks'; |
| 5 | import { ok, deepStrictEqual, strictEqual } from 'node:assert'; |
| 6 | |
| 7 | export const testErrorMethodNotImplemented = { |
| 8 | async test() { |
| 9 | deepStrictEqual(async_hooks.executionAsyncId(), 0); |
| 10 | deepStrictEqual(async_hooks.triggerAsyncId(), 0); |
| 11 | deepStrictEqual(async_hooks.executionAsyncResource(), Object.create(null)); |
| 12 | ok(async_hooks.createHook({})); |
| 13 | }, |
| 14 | }; |
| 15 | |
| 16 | export const asyncLocalStorageOptions = { |
| 17 | test() { |
| 18 | const als = new async_hooks.AsyncLocalStorage({ |
| 19 | defaultValue: 1, |
| 20 | name: 'foo', |
| 21 | }); |
| 22 | strictEqual(als.name, 'foo'); |
| 23 | strictEqual(als.getStore(), 1); |
| 24 | strictEqual( |
| 25 | als.run(2, () => als.getStore()), |
| 26 | 2 |
| 27 | ); |
| 28 | strictEqual(als.getStore(), 1); |
| 29 | }, |
| 30 | }; |