forked from BabylonJS/Babylon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.mts
More file actions
78 lines (71 loc) · 2.82 KB
/
vitest.config.mts
File metadata and controls
78 lines (71 loc) · 2.82 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
72
73
74
75
76
77
78
import { defineConfig } from "vitest/config";
import * as fs from "fs";
import * as path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const compilerOptions = JSON.parse(fs.readFileSync(path.resolve(__dirname, "./tsconfig.json"), "utf8")).compilerOptions;
/**
* Convert tsconfig paths to Vitest resolve aliases
*/
const convertPathsToAliases = () => {
const aliases: Record<string, string> = {};
const paths = compilerOptions.paths;
for (const key in paths) {
// Convert glob patterns to regex-compatible aliases
const aliasKey = key.replace("/*", "");
const aliasValue = path.resolve(__dirname, "packages", paths[key][0].replace("/*", ""));
aliases[aliasKey] = aliasValue;
}
return aliases;
};
const aliases = convertPathsToAliases();
const createProjectConfig = (type: string) => {
const globalSetupLocation = path.resolve(".", `vitest.${type}.setup.ts`);
const setupFileLocation = path.resolve(".", `vitest.${type}.setup.afterEnv.ts`);
const globalSetup = fs.existsSync(globalSetupLocation) ? globalSetupLocation : undefined;
const setupFiles: string[] = [path.resolve(".", "vitest.setup.ts")];
if (fs.existsSync(setupFileLocation)) {
setupFiles.push(setupFileLocation);
}
return {
name: type,
include: [`packages/**/test/${type}/**/*.test.{ts,tsx}`],
exclude: ["**/node_modules/**", "**/packages/*/src/**"],
globals: true,
environment: "node",
// Use child processes (like Jest) instead of worker threads.
// Babylon.js has deep side-effect import chains (shaders, scene
// components) that resolve asynchronously. With the default 'threads'
// pool, pending module resolution can outlive the test and cause
// EnvironmentTeardownError. Forked processes exit cleanly.
pool: "forks",
globalSetup,
setupFiles,
};
};
export default defineConfig({
resolve: {
alias: {
...aliases,
},
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
},
test: {
globals: true,
environment: "node",
reporters: process.env.CI ? ["default", "junit"] : ["default"],
outputFile: process.env.CI ? { junit: "./junit.xml" } : undefined,
projects: [
{
test: createProjectConfig("unit"),
resolve: {
alias: aliases,
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
},
},
// Integration, performance, and interactions tests require a browser
// (Puppeteer/Playwright) and are run separately via Playwright configs.
// They are not included here to avoid "page is not defined" errors.
],
},
});