Skip to content
File

Blob: src/workerd/api/tests/als-only-test.js

javascript26 lines
1// Copyright (c) 2024 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
4import { AsyncLocalStorage } from 'node:async_hooks';
5 
6export const customthenable = {
7 // Test to ensure that async context is propagated into custom thenables.
8 async test() {
9 // This should just work
10 const als = new AsyncLocalStorage();
11 if (!(als instanceof AsyncLocalStorage)) {
12 throw new Error('Expected an instance of AsyncLocalStorage');
13 }
14 
15 // This should not
16 try {
17 await import('node:assert');
18 throw new Error('Expected an error to be thrown');
19 } catch (err) {
20 if (err.message !== 'No such module "node:assert".') {
21 throw err;
22 }
23 }
24 },
25};