-
Notifications
You must be signed in to change notification settings - Fork 754
Expand file tree
/
Copy pathinline_env_vars_test.ts
More file actions
71 lines (62 loc) · 1.87 KB
/
Copy pathinline_env_vars_test.ts
File metadata and controls
71 lines (62 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { expect } from "@std/expect/expect";
import * as babel from "@babel/core";
import { inlineEnvVarsPlugin } from "./inline_env_vars.ts";
import { usingEnv } from "../../../tests/test_utils.ts";
function runTest(options: { input: string; expected: string; mode?: string }) {
const res = babel.transformSync(options.input, {
filename: "foo.js",
babelrc: false,
plugins: [inlineEnvVarsPlugin(options.mode ?? "development")],
});
const output = res?.code ?? "";
expect(output).toEqual(options.expected);
}
Deno.test("env vars - inline NODE_ENV", () => {
using _ = usingEnv("NODE_ENV", "foobar");
runTest({
input: `() => process.env.NODE_ENV`,
expected: `() => "foobar";`,
});
});
Deno.test("env vars - inline NODE_ENV mode", () => {
runTest({
input: `() => process.env.NODE_ENV`,
expected: `() => "asdf";`,
mode: "asdf",
});
});
Deno.test("env vars - inline custom process.env.*", () => {
using _ = usingEnv("FRESH_PUBLIC_FOO", "a");
runTest({
input: `() => process.env.FRESH_PUBLIC_FOO`,
expected: `() => "a";`,
});
});
Deno.test("env vars - inline Deno.env.get()", () => {
using _ = usingEnv("FRESH_PUBLIC_FOO", "b");
runTest({
input: `() => Deno.env.get("FRESH_PUBLIC_FOO")`,
expected: `() => "b";`,
});
});
Deno.test("env vars - inline Deno.env.get(NODE_ENV)", () => {
using _ = usingEnv("NODE_ENV", "c");
runTest({
input: `() => Deno.env.get("NODE_ENV")`,
expected: `() => "c";`,
});
});
Deno.test("env vars - inline Deno.env.get(NODE_ENV) mode", () => {
runTest({
input: `() => Deno.env.get("NODE_ENV")`,
expected: `() => "test";`,
mode: "test",
});
});
Deno.test("env vars - inline const _ = Deno.env.get()", () => {
using _ = usingEnv("FRESH_PUBLIC_FOO", "test");
runTest({
input: `const deno = Deno.env.get("FRESH_PUBLIC_FOO");`,
expected: `const deno = "test";`,
});
});