Skip to content

Commit 2f86247

Browse files
committed
test: add environment mocking for unit tests
1 parent 325409c commit 2f86247

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

vite.config.unit.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ import base from "./vite.config.mjs";
99
export default defineConfig({
1010
...base,
1111
root: "./",
12+
resolve: {
13+
alias: {
14+
"../internal/environment": "/virtual:environment-mock",
15+
},
16+
},
17+
plugins: [
18+
...(base.plugins || []),
19+
{
20+
name: "virtual-environment-mock",
21+
resolveId(id) {
22+
if (id === "/virtual:environment-mock") {
23+
return id;
24+
}
25+
},
26+
load(id) {
27+
if (id === "/virtual:environment-mock") {
28+
// Simple stub - the actual values are mocked when testing
29+
return `
30+
export const THEME = "stub";
31+
export const PACKAGE_SOURCE = "stub";
32+
export const PACKAGE_VERSION = "stub";
33+
export const SYSTEM = "stub";
34+
export const ALWAYS_VISUAL_REFRESH = true;
35+
`;
36+
}
37+
},
38+
},
39+
],
1240
test: {
1341
include: ["./src/**/__tests__/**/*.test.{ts,tsx}"],
1442
environment: "jsdom",

0 commit comments

Comments
 (0)