-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
vitest.workspace.typescript.mts
52 lines (47 loc) · 2.01 KB
/
vitest.workspace.typescript.mts
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 { readdirSync } from 'node:fs';
import { defineWorkspace } from 'vitest/config';
import type { UserProjectConfigExport } from 'vitest/config';
export default defineWorkspace(
/**
* If you need to test multiple typescript configurations (like misc) simply create a file named tsconfig.{customName}.json
* and this script will automatically create a new workspace named with the dirName followed by `customName`
*/
readdirSync('./test/typescript', { withFileTypes: true })
.filter((dir) => dir.isDirectory())
.reduce<UserProjectConfigExport[]>((workspaces, dir) => {
const dirPath = `test/typescript/${dir.name}` as const;
const tsConfigFiles = readdirSync(dirPath).filter(
// Do not include temporary vitest tsconfig files
(it) => it.startsWith('tsconfig.') && it.endsWith('.json') && !it.includes('vitest-temp'),
);
tsConfigFiles.forEach((tsConfigFileName) => {
const workspaceName =
tsConfigFileName === 'tsconfig.json'
? `typescript-${dir.name}`
: `${dir.name}-${tsConfigFileName.split('.')[1]}`;
workspaces.push({
test: {
dir: `./${dirPath}`,
name: workspaceName,
alias: {
/**
* From `vitest` >= 2 imports are resolved even if we are running only typecheck tests.
* This will result in:
* ```text
* Error: Failed to resolve entry for package "react-i18next". The package may have incorrect main/module/exports specified in its package.json.
* ```
* To avoid a useless build process before running these tests an empty alias to `react-i18next` is added.
*/
'react-i18next': '',
},
typecheck: {
enabled: true,
include: [`**/${dirPath}/*.test.{ts,tsx}`],
tsconfig: `./${dirPath}/${tsConfigFileName}`,
},
},
});
});
return workspaces;
}, []),
);