-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
52 lines (49 loc) · 1.48 KB
/
vitest.config.ts
File metadata and controls
52 lines (49 loc) · 1.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
import { builtinModules } from 'module';
import { defineConfig, type Plugin } from 'vitest/config';
/**
* Vite plugin that resolves bare Node.js built-in imports (e.g. 'fs', 'path')
* to their 'node:' prefixed form so Vite doesn't try to resolve them as packages.
*/
function nodeBuiltinsPlugin(): Plugin {
const builtins = new Set(builtinModules);
return {
name: 'resolve-node-builtins',
enforce: 'pre',
resolveId(source) {
if (builtins.has(source)) {
return { id: `node:${source}`, external: true };
}
},
};
}
/**
* Stub for the virtual:npm-timeline module used by the playground.
* At build time, a Vite plugin fetches npm registry data; in tests, we provide empty data.
*/
function npmTimelineStub(): Plugin {
return {
name: 'npm-timeline-stub',
enforce: 'pre',
resolveId(id) {
if (id === 'virtual:npm-timeline') return '\0virtual:npm-timeline';
},
load(id) {
if (id === '\0virtual:npm-timeline') return 'export default {};';
},
};
}
export default defineConfig({
plugins: [nodeBuiltinsPlugin(), npmTimelineStub()],
test: {
globals: true,
environment: 'happy-dom',
include: ['packages/**/*.test.ts'],
exclude: ['**/node_modules/**', '**/dist/**'],
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'json-summary', 'html'],
include: ['packages/*/src/**/*.ts'],
exclude: ['packages/*/src/**/*.test.ts', 'packages/*/src/**/index.ts', '**/node_modules/**'],
},
},
});