-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trs/falsy-config-vars'
- Loading branch information
Showing
2 changed files
with
82 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {fromEnvOrConfig} from "../src/config.js"; | ||
|
||
const env = process.env; | ||
|
||
/* Isolate process.env for each test so changes don't leak across tests. | ||
*/ | ||
beforeEach(() => { | ||
process.env = { ...env }; | ||
}); | ||
|
||
/* Reset process.env overrides. | ||
*/ | ||
afterEach(() => { | ||
process.env = env; | ||
}); | ||
|
||
describe("configurable vs. missing values", () => { | ||
test("boolean false is a configurable value", () => { | ||
process.env.TEST_VAR = "false"; | ||
expect(fromEnvOrConfig("TEST_VAR", true)).toBe(false); | ||
}); | ||
|
||
test("numeric 0 is a configurable value", () => { | ||
process.env.TEST_VAR = "0"; | ||
expect(fromEnvOrConfig("TEST_VAR", 42)).toBe(0); | ||
}); | ||
|
||
test("null is a missing value", async () => { | ||
process.env.TEST_VAR = "null"; | ||
expect(fromEnvOrConfig("TEST_VAR", "default")).toBe("default"); | ||
}); | ||
|
||
test("empty string is a missing value", async () => { | ||
process.env.TEST_VAR = ""; | ||
expect(fromEnvOrConfig("TEST_VAR", "default")).toBe("default"); | ||
}); | ||
}); |