-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvitest.config.ts
More file actions
78 lines (69 loc) · 2.48 KB
/
vitest.config.ts
File metadata and controls
78 lines (69 loc) · 2.48 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, Plugin } from "vitest/config";
import { loadTestEnv } from "./tests/test-env.js";
import path from "path";
import fs from "fs";
loadTestEnv();
// Plugin to load .mustache and .md files as raw text (like esbuild's text loader)
function rawTextPlugin(): Plugin {
return {
name: "raw-text",
transform(code, id) {
if (id.endsWith(".mustache") || id.endsWith(".md") || id.endsWith(".log")) {
// We can just use the code that vitest already read from disk
return {
code: `export default ${JSON.stringify(code)};`,
map: null
};
}
}
};
}
function getPackageAliases(): Record<string, string> {
const packagesDir = path.resolve(__dirname, "packages");
const packages = fs.readdirSync(packagesDir, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
const mainAliases: Record<string, string> = {};
const subpathAliases: Record<string, string> = {};
for (const pkg of packages) {
// Main export: @poe-code/<name> -> packages/<name>/src/index.ts
mainAliases[`@poe-code/${pkg}`] = path.resolve(packagesDir, pkg, "src/index.ts");
for (const subpath of ["cli", "mcp", "sdk"]) {
const entryPath = path.resolve(packagesDir, pkg, "src", `${subpath}.ts`);
if (fs.existsSync(entryPath)) {
subpathAliases[`@poe-code/${pkg}/${subpath}`] = entryPath;
}
}
// Check for /testing subpath export
const testingIndexPath = path.resolve(packagesDir, pkg, "src/testing/index.ts");
if (fs.existsSync(testingIndexPath)) {
subpathAliases[`@poe-code/${pkg}/testing`] = testingIndexPath;
}
}
// Subpath aliases must come first for correct resolution
return { ...subpathAliases, ...mainAliases };
}
export default defineConfig({
plugins: [rawTextPlugin()],
resolve: {
// Resolve workspace packages to source for tests (no build required)
alias: getPackageAliases()
},
test: {
globals: true,
environment: "node",
pool: "threads",
include: [
"src/**/*.test.ts", // Collocated unit tests
"tests/helpers/**/*.test.ts", // Test helper tests
"tests/integration/**/*.test.ts", // Integration tests
"packages/**/*.test.ts", // Package tests
"scripts/screenshot.test.ts" // Script tests (explicit)
],
exclude: [
"**/node_modules/**",
"**/*.e2e.test.ts" // E2E tests run separately
],
setupFiles: ["tests/setup.ts"]
}
});