-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvitest.config.ts
82 lines (73 loc) · 2.52 KB
/
vitest.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
import { resolve } from 'node:path';
import { type UserConfigFnPromise, type ViteUserConfig, mergeConfig } from 'vitest/config';
import { BaseSequencer, type WorkspaceSpec } from 'vitest/node';
import { folders } from './config/index.js';
import rendererConfig from './vite.config.renderer';
const testsPriority = [
resolve(folders.rendererRoot, 'domains'),
resolve(folders.rendererRoot, 'features'),
resolve(folders.rendererRoot, 'entities'),
resolve(folders.rendererRoot, 'shared'),
// ... other
];
class Seqencer extends BaseSequencer {
async sort(files: WorkspaceSpec[]) {
return files.sort((a, b) => {
const ac = testsPriority.findIndex((dir) => a.moduleId.startsWith(dir));
const bc = testsPriority.findIndex((dir) => b.moduleId.startsWith(dir));
if (ac === -1) return 1;
if (bc === -1) return -1;
return ac - bc;
});
}
}
const config: UserConfigFnPromise = async (options) => {
const base = await rendererConfig(options);
const config: ViteUserConfig = {
cacheDir: resolve(folders.root, 'node_modules/.cache/vitest'),
test: {
root: folders.root,
dir: folders.source,
globals: true,
environmentMatchGlobs: [
// This list should dissapear over time, simple logic tests shouldn't depend on environment.
['src/renderer/shared/lib/hooks/**/*.ts', 'happy-dom'],
['src/renderer/shared/i18n/**/*.ts', 'happy-dom'],
['src/renderer/shared/api/**/*.ts', 'happy-dom'],
['src/renderer/domains/**/*.ts', 'happy-dom'],
['src/renderer/entities/**/*.ts', 'happy-dom'],
['src/renderer/features/**/*.ts', 'happy-dom'],
['src/renderer/widgets/**/*.ts', 'happy-dom'],
['src/renderer/pages/**/*.ts', 'happy-dom'],
['**/*.tsx', 'happy-dom'],
['**/*.ts', 'node'],
],
setupFiles: resolve(folders.root, './vitest.setup.js'),
reporters: ['basic', 'junit'],
outputFile: {
junit: resolve(folders.root, './junit.xml'),
},
sequence: {
sequencer: Seqencer,
},
coverage: {
provider: 'v8',
ignoreEmptyLines: true,
exclude: ['**/node_modules/**'],
reportsDirectory: folders.coverage,
thresholds: {
branches: 25,
functions: 10,
lines: 10,
statements: 10,
},
reporter: 'json-summary',
},
pool: 'forks',
maxConcurrency: 8,
deps: { optimizer: { web: { enabled: true } } },
},
};
return mergeConfig(base, config);
};
export default config;