Repository navigation
Expand file tree
/
Copy pathvitest.config.mts
More file actions
117 lines (113 loc) · 3.28 KB
/
Copy pathvitest.config.mts
File metadata and controls
117 lines (113 loc) · 3.28 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { existsSync } from 'node:fs';
import path from 'node:path';
import {
defineConfig,
type Plugin,
type TestProjectConfiguration,
} from 'vitest/config';
interface ProjectOptions {
environment?: 'jsdom' | 'node';
setupFiles?: string[];
testTimeout?: number;
include?: string[];
env?: Record<string, string>;
}
function project(
name: string,
dir: string,
{
environment = 'node',
setupFiles,
testTimeout,
include = ['test/**/*.{spec,test}.?(c|m)[jt]s?(x)'],
env,
}: ProjectOptions = {},
): TestProjectConfiguration {
return {
root: path.resolve(import.meta.dirname, dir),
test: {
name,
globals: true,
environment,
include,
setupFiles,
testTimeout,
env,
},
};
}
/**
* Plain `.js`/`.jsx` test files in `extension/test` import TypeScript sources
* with a `.js` extension. Vite only rewrites `.js` -> `.ts` when the importer
* is itself a TypeScript file, so handle the JS-importer case here.
*/
function resolveTsFromJsImporter(): Plugin {
return {
name: 'resolve-ts-from-js-importer',
enforce: 'pre',
resolveId(source, importer) {
if (!importer || !source.startsWith('.') || !/\.jsx?$/.test(source)) {
return null;
}
if (/\.[cm]?tsx?$/.test(importer)) return null;
const target = path.resolve(path.dirname(importer), source);
if (existsSync(target)) return null;
const base = target.replace(/\.jsx?$/, '');
for (const ext of ['.ts', '.tsx']) {
if (existsSync(base + ext)) return base + ext;
}
return null;
},
};
}
export default defineConfig({
plugins: [resolveTsFromJsImporter()],
test: {
projects: [
project('map2tree', 'packages/map2tree'),
project('react-base16-styling', 'packages/react-base16-styling'),
project('react-json-tree', 'packages/react-json-tree'),
project('core', 'packages/redux-devtools'),
project('app-core', 'packages/redux-devtools-app-core', {
environment: 'jsdom',
setupFiles: ['test/setup.ts'],
}),
project('cli', 'packages/redux-devtools-cli', { testTimeout: 10000 }),
project(
'test-tab',
'packages/redux-devtools-inspector-monitor-test-tab',
{
environment: 'jsdom',
},
),
project(
'trace-tab',
'packages/redux-devtools-inspector-monitor-trace-tab',
{ environment: 'jsdom' },
),
project('instrument', 'packages/redux-devtools-instrument'),
project(
'rtk-query-monitor',
'packages/redux-devtools-rtk-query-monitor',
{
environment: 'jsdom',
},
),
project('serialize', 'packages/redux-devtools-serialize'),
project('ui', 'packages/redux-devtools-ui', { environment: 'jsdom' }),
project('utils', 'packages/redux-devtools-utils'),
project('remote', 'packages/redux-devtools-remote'),
project('extension', 'extension', {
environment: 'jsdom',
setupFiles: ['test/setup.ts'],
include: ['test/app/**/*.spec.?(c|m)[jt]s?(x)'],
testTimeout: 50000,
env: { BABEL_ENV: 'test' },
}),
project('extension-harness', 'extension', {
environment: 'jsdom',
include: ['test-harness/**/*.test.?(c|m)[jt]s?(x)'],
}),
],
},
});