From 1c3e6d727e4834f767017f6ab1785ad4abc6ec29 Mon Sep 17 00:00:00 2001 From: Michael Cooper Date: Wed, 13 Nov 2024 12:05:08 -0800 Subject: [PATCH] handle missing envvars more carefully in test mock --- test/javascript/annotate-test.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/javascript/annotate-test.ts b/test/javascript/annotate-test.ts index aee2ae7f7..7e78a8da7 100644 --- a/test/javascript/annotate-test.ts +++ b/test/javascript/annotate-test.ts @@ -5,14 +5,24 @@ import {transpileModule} from "../../src/javascript/transpile.js"; import {fromJsDelivrPath, rewriteNpmImports} from "../../src/npm.js"; import {relativePath} from "../../src/path.js"; -export function mockAnnotateFileEnv(value = true) { +const ANNOTATE_FILES_ENV = "OBSERVABLE_ANNOTATE_FILES"; + +export function mockAnnotateFileEnv(value: boolean) { let annotateFileEnvBefore: string | undefined; before(() => { - annotateFileEnvBefore = process.env["OBSERVABLE_ANNOTATE_FILES"]; - process.env["OBSERVABLE_ANNOTATE_FILES"] = JSON.stringify(value); + annotateFileEnvBefore = process.env[ANNOTATE_FILES_ENV]; + if (value === undefined) { + delete process.env[ANNOTATE_FILES_ENV]; + } else { + process.env[ANNOTATE_FILES_ENV] = JSON.stringify(value); + } }); after(() => { - process.env["OBSERVABLE_ANNOTATE_FILES"] = annotateFileEnvBefore; + if (annotateFileEnvBefore === undefined) { + delete process.env[ANNOTATE_FILES_ENV]; + } else { + process.env[ANNOTATE_FILES_ENV] = annotateFileEnvBefore; + } }); }