Skip to content

Commit

Permalink
handle missing envvars more carefully in test mock
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Nov 13, 2024
1 parent accd344 commit 1c3e6d7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/javascript/annotate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}

Expand Down

0 comments on commit 1c3e6d7

Please sign in to comment.