import { expect } from "@std/expect"; type ShellEnvGlobals = typeof globalThis & Record; function importFreshEnvModule() { return import( new URL(`../src/lib/env.ts?case=${crypto.randomUUID()}`, import.meta.url) .href ); } function withPatchedGlobals( globals: Record, fn: () => Promise, ): Promise { const env = globalThis as ShellEnvGlobals; const original = Object.fromEntries( Object.keys(globals).map((key) => [key, env[key]]), ); for (const [key, value] of Object.entries(globals)) { env[key] = value; } return fn().finally(() => { for (const [key, value] of Object.entries(original)) { env[key] = value; } }); } Deno.test({ name: "shell env reads the modern experimental globals", permissions: { read: true }, async fn() { const mod = await withPatchedGlobals({ $API_URL: "http://shell.test/", $EXPERIMENTAL_MODERN_CELL_REP: "true", $EXPERIMENTAL_PERSISTENT_SCHEDULER_STATE: "true", }, importFreshEnvModule); expect(mod.EXPERIMENTAL).toEqual({ modernCellRep: true, persistentSchedulerState: true, }); }, });