-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] added a way to parse env strings
- Loading branch information
1 parent
effe060
commit 3046519
Showing
2 changed files
with
177 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { parseEnvString } from "main/helpers/env.helpers"; | ||
|
||
describe("Test parseEnvString", () => { | ||
|
||
it("Empty", () => { | ||
const envVars = parseEnvString(""); | ||
expect(envVars).toEqual({}); | ||
}); | ||
|
||
it("Single test; no quotes", () => { | ||
const envString = "HELLO=World!"; | ||
const envVars = parseEnvString(envString); | ||
expect(envVars).toEqual({ | ||
HELLO: "World!", | ||
}); | ||
}); | ||
|
||
it("Single test; single quotes", () => { | ||
const envString = "SINGLE_QOUTE='Single quote with spaces'"; | ||
const envVars = parseEnvString(envString); | ||
expect(envVars).toEqual({ | ||
SINGLE_QOUTE: "Single quote with spaces", | ||
}); | ||
}); | ||
|
||
it("Single test; double quotes", () => { | ||
const envString = 'DOUBLE_QOUTE="Some random quote."'; | ||
const envVars = parseEnvString(envString); | ||
expect(envVars).toEqual({ | ||
DOUBLE_QOUTE: "Some random quote.", | ||
}); | ||
}); | ||
|
||
it("Single test; empty value", () => { | ||
const envString = "EMPTY="; | ||
const envVars = parseEnvString(envString); | ||
expect(envVars).toEqual({ | ||
EMPTY: "", | ||
}); | ||
}); | ||
|
||
it("Multiple test; combined", () => { | ||
const envString = `HELLO=World! DOUBLE_QUOTE="Two Words" SINGLE_QUOTE='' EMPTY=` | ||
const envVars = parseEnvString(envString); | ||
expect(envVars).toEqual(expect.objectContaining({ | ||
HELLO: "World!", | ||
DOUBLE_QUOTE: "Two Words", | ||
SINGLE_QUOTE: "", | ||
EMPTY: "" | ||
})); | ||
}); | ||
|
||
it("Key with numbers and lower case", () => { | ||
const envString = "H3ll0=world"; | ||
const envVars = parseEnvString(envString); | ||
expect(envVars).toEqual({ | ||
H3ll0: "world", | ||
}); | ||
}); | ||
|
||
}); |
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