|
| 1 | +import assert from "node:assert"; |
| 2 | +import { isProcessEnvPopulated } from "../process-env"; |
| 3 | + |
| 4 | +describe("isProcessEnvPopulated", () => { |
| 5 | + test("default", () => { |
| 6 | + expect(isProcessEnvPopulated(undefined, ["nodejs_compat"])).toBe(false); |
| 7 | + }); |
| 8 | + |
| 9 | + test("future date", () => { |
| 10 | + expect(isProcessEnvPopulated("2026-01-01", ["nodejs_compat"])).toBe(true); |
| 11 | + }); |
| 12 | + |
| 13 | + test("old date", () => { |
| 14 | + expect(isProcessEnvPopulated("2000-01-01", ["nodejs_compat"])).toBe(false); |
| 15 | + }); |
| 16 | + |
| 17 | + test("switch date", () => { |
| 18 | + expect(isProcessEnvPopulated("2025-04-01", ["nodejs_compat"])).toBe(true); |
| 19 | + }); |
| 20 | + |
| 21 | + test("old date, but with flag", () => { |
| 22 | + expect( |
| 23 | + isProcessEnvPopulated("2000-01-01", [ |
| 24 | + "nodejs_compat", |
| 25 | + "nodejs_compat_populate_process_env", |
| 26 | + ]) |
| 27 | + ).toBe(true); |
| 28 | + }); |
| 29 | + |
| 30 | + test("old date, with disable flag", () => { |
| 31 | + expect( |
| 32 | + isProcessEnvPopulated("2000-01-01", [ |
| 33 | + "nodejs_compat", |
| 34 | + "nodejs_compat_do_not_populate_process_env", |
| 35 | + ]) |
| 36 | + ).toBe(false); |
| 37 | + }); |
| 38 | + |
| 39 | + test("future date, but with disable flag", () => { |
| 40 | + expect( |
| 41 | + isProcessEnvPopulated("2026-01-01", [ |
| 42 | + "nodejs_compat", |
| 43 | + "nodejs_compat_do_not_populate_process_env", |
| 44 | + ]) |
| 45 | + ).toBe(false); |
| 46 | + }); |
| 47 | + |
| 48 | + test("future date, with enable flag", () => { |
| 49 | + expect( |
| 50 | + isProcessEnvPopulated("2026-01-01", [ |
| 51 | + "nodejs_compat", |
| 52 | + "nodejs_compat_populate_process_env", |
| 53 | + ]) |
| 54 | + ).toBe(true); |
| 55 | + }); |
| 56 | + |
| 57 | + test("future date without nodejs_compat", () => { |
| 58 | + expect(isProcessEnvPopulated("2026-01-01")).toBe(false); |
| 59 | + }); |
| 60 | + |
| 61 | + test("future date, with enable flag but without nodejs_compat", () => { |
| 62 | + expect( |
| 63 | + isProcessEnvPopulated("2026-01-01", [ |
| 64 | + "nodejs_compat_populate_process_env", |
| 65 | + ]) |
| 66 | + ).toBe(false); |
| 67 | + }); |
| 68 | + |
| 69 | + test("errors with disable and enable flags specified", () => { |
| 70 | + try { |
| 71 | + isProcessEnvPopulated("2024-01-01", [ |
| 72 | + "nodejs_compat_populate_process_env", |
| 73 | + "nodejs_compat_do_not_populate_process_env", |
| 74 | + ]); |
| 75 | + assert(false, "Unreachable"); |
| 76 | + } catch (e) { |
| 77 | + expect(e).toMatchInlineSnapshot( |
| 78 | + `[Error: Can't both enable and disable a flag]` |
| 79 | + ); |
| 80 | + } |
| 81 | + }); |
| 82 | +}); |
0 commit comments