-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvitest.config.ts
More file actions
67 lines (61 loc) · 2.32 KB
/
vitest.config.ts
File metadata and controls
67 lines (61 loc) · 2.32 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
import { defineConfig } from 'vitest/config';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
/**
* Vitest plugin that resolves #src/ and @gaunt-sloth/ imports to actual
* source files in the workspace packages. This ensures that vi.mock() and
* dynamic imports all resolve to the same module identity.
*
* Packages are scanned in dependency order: core → tools → review → api → assistant.
* The review package has re-export stubs that delegate to core; those are
* detected and skipped so the canonical core module is always used.
*/
function resolveWorkspaceImports() {
return {
name: 'resolve-workspace-imports',
enforce: 'pre' as const,
resolveId(id: string, _importer: string | undefined): any {
// Handle #src/ imports -> find the actual source in packages
if (id.startsWith('#src/')) {
const relative = id.replace('#src/', '').replace(/\.js$/, '.ts');
// Try each package in dependency order
for (const pkg of ['core', 'tools', 'review', 'api', 'assistant']) {
const tsPath = resolve(__dirname, `packages/${pkg}/src/${relative}`);
if (existsSync(tsPath)) {
// Skip re-export stubs (files that just re-export from @gaunt-sloth/)
// by checking if the file is a re-export stub in review
if (pkg === 'review') {
const corePath = resolve(__dirname, `packages/core/src/${relative}`);
if (existsSync(corePath)) {
return corePath;
}
}
return tsPath;
}
}
}
// Handle @gaunt-sloth/X/path.js -> packages/X/src/path.ts
const scopedMatch = id.match(/^@gaunt-sloth\/(core|tools|review|api)\/(.+)\.js$/);
if (scopedMatch) {
const [, pkg, path] = scopedMatch;
const tsPath = resolve(__dirname, `packages/${pkg}/src/${path}.ts`);
if (existsSync(tsPath)) return tsPath;
}
},
};
}
export default defineConfig({
plugins: [resolveWorkspaceImports()],
test: {
include: ['packages/*/spec/**/*.ts'],
environment: 'node',
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
},
globals: true,
testTimeout: 10000,
},
});