forked from Lilly-Protocol/lily-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.test.ts
More file actions
48 lines (42 loc) · 1.38 KB
/
Copy pathenv.test.ts
File metadata and controls
48 lines (42 loc) · 1.38 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
import { afterEach, describe, expect, it, vi } from "vitest";
import { parsePublicEnv } from "./env";
describe("public environment configuration", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("returns normalized typed URLs", () => {
expect(
parsePublicEnv({
NEXT_PUBLIC_SITE_URL: "https://lily.example/",
NEXT_PUBLIC_API_BASE_URL: "https://api.lily.example/",
}),
).toEqual({
siteUrl: "https://lily.example",
apiBaseUrl: "https://api.lily.example",
});
});
it("fails with setup guidance when a required value is missing", () => {
expect(() =>
parsePublicEnv({
NEXT_PUBLIC_SITE_URL: undefined,
NEXT_PUBLIC_API_BASE_URL: "https://api.lily.example",
}),
).toThrow(
"Missing required environment variable NEXT_PUBLIC_SITE_URL. Copy .env.example to .env.local and set it.",
);
});
it("rejects relative and non-http URLs", () => {
expect(() =>
parsePublicEnv({
NEXT_PUBLIC_SITE_URL: "/relative",
NEXT_PUBLIC_API_BASE_URL: "https://api.lily.example",
}),
).toThrow("NEXT_PUBLIC_SITE_URL must be an absolute http(s) URL");
expect(() =>
parsePublicEnv({
NEXT_PUBLIC_SITE_URL: "https://lily.example",
NEXT_PUBLIC_API_BASE_URL: "file:///tmp/lily",
}),
).toThrow("NEXT_PUBLIC_API_BASE_URL must use http or https");
});
});