-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
85 lines (69 loc) · 2.08 KB
/
vite.config.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import removeAttr from "react-remove-attr";
import path from "node:path";
import react from "@vitejs/plugin-react-swc";
import { loadEnv } from "vite";
import checker from "vite-plugin-checker";
import { defineConfig } from "vitest/config";
export default defineConfig(({ mode }) => {
process.env.NODE_ENV = mode; // Make sure NODE_ENV matches mode when building
const inProdMode = mode === "production";
// expose .env vars to server environment (only VITE_ prefixed vars)
const env = loadEnv(mode, process.cwd(), "");
Object.keys(env).forEach((key) => {
if (key.startsWith("VITE_")) {
process.env[key] = env[key];
}
});
return {
plugins: [
checker({
typescript: true,
}),
inProdMode &&
removeAttr({
extensions: ["tsx"],
attributes: ["data-testid"],
}),
react(),
],
build: {
sourcemap: !inProdMode,
reportCompressedSize: false,
},
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
"#": path.resolve(__dirname, "test"),
},
},
test: {
globals: true,
environment: "jsdom",
environmentOptions: {
url: "http://localhost",
},
include: ["**/*.test.js", "**/*.test.ts", "**/*.test.jsx", "**/*.test.tsx"],
exclude: ["**/node_modules/**"],
setupFiles: path.resolve(__dirname, "vitest.setup.ts"),
reporters: ["default", "json", "vitest-sonar-reporter"],
outputFile: {
json: "reports/test-report/test-report.json",
html: "reports/test-report/test-report.html",
"vitest-sonar-reporter": "reports/vite-sonar/sonar-report.xml",
},
coverage: {
provider: "v8",
include: ["src/**/*"],
exclude: ["src/main.tsx", "src/mock-server/**/*", "*.test.*", "*/__mocks__/*"],
reporter: ["text", "html", "lcov"],
reportsDirectory: "reports/vite-coverage",
enabled: false,
},
clearMocks: true,
mockReset: true,
restoreMocks: true,
unstubGlobals: true,
unstubEnvs: true,
},
};
});