Skip to content
File

Blob: src/workerd/api/tests/disable-importable-env-test.js

javascript29 lines
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
4import { env, withEnv } from 'cloudflare:workers';
5 
6// This test runs with the disallow-importable-env flag set, meaning that
7// the env imported from cloudflare:workers exists but is not-populated
8// with the primary environment. Using withEnv, however, would still work.
9 
10import { strictEqual, notDeepStrictEqual } from 'node:assert';
11 
12strictEqual(env.FOO, undefined);
13 
14export const test = {
15 async test(_, argEnv) {
16 strictEqual(env.FOO, undefined);
17 notDeepStrictEqual(argEnv, env);
18 
19 // withEnv still works as expected tho
20 const { env: otherEnv2 } = await withEnv({ BAZ: 1 }, async () => {
21 await scheduler.wait(0);
22 return import('child');
23 });
24 strictEqual(otherEnv2.FOO, undefined);
25 strictEqual(otherEnv2.BAZ, 1);
26 strictEqual(argEnv.BAZ, undefined);
27 },
28};