-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
vitest.config.unit.ts
45 lines (42 loc) · 1.45 KB
/
vitest.config.unit.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
import {basename as pathBasename} from 'node:path';
import {readFileSync} from 'node:fs';
import {mergeConfig, defineConfig} from 'vitest/config';
import {globSync} from 'glob';
import baseConfig from './vitest.config.base';
function styleSpecFixtures() {
const virtualModuleId = 'virtual:style-spec/fixtures';
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
const fixtureFiles = globSync('./test/unit/style-spec/fixture/*.input.json').reduce((acc, file) => {
acc[pathBasename(file).replace('.input.json', '')] = readFileSync(file).toString();
return acc;
}, {});
return {
name: 'style-spec-fixtures',
resolveId(id) {
if (id === virtualModuleId) {
return resolvedVirtualModuleId;
}
},
load(id) {
if (id === resolvedVirtualModuleId) {
return `export const fixtures = ${JSON.stringify(fixtureFiles)}`;
}
}
};
}
export default mergeConfig(baseConfig, defineConfig({
test: {
include: ['test/unit/**/*.test.ts'],
setupFiles: ['test/unit/setup.ts'],
reporters: process.env.CI ? [
['html', {outputFile: './test/unit/vitest/index.html'}],
['junit', {outputFile: './test/unit/test-results.xml'}],
['basic']
] : ['basic'],
},
// For msw mock worker
publicDir: 'test/unit/mock-worker',
plugins: [
styleSpecFixtures()
]
}));