-
Notifications
You must be signed in to change notification settings - Fork 5
/
vitest.config.ts
37 lines (34 loc) · 1.22 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
import type { Plugin } from 'vite';
import { configDefaults, defineConfig } from 'vitest/config';
const m = (minutes: number): number => minutes * 60 * 1000;
/**
* On older Node.js (Node.js less than 14.17, or Node.js less than 15.3), Vitest does not convert file paths with extension ".js" to ".ts".
* This tiny plugin fixes that.
*/
const fixTSImport: Plugin = {
name: 'vite-fix-typescript-js-imports',
async resolveId(source, importer, options) {
// Check if the importer is TypeScript file
if (!/\.[cm]?ts$/.test(importer ?? '')) return;
// Check if the file extension is ".js"
const match = /^([^\0]*\.[cm]?)js$/.exec(source);
if (typeof match?.[1] !== 'string') return;
// Replace the file extension ".js" with ".ts" and resolve the new path
return await this.resolve(`${match[1]}ts`, importer, {
...options,
skipSelf: true,
});
},
};
export default defineConfig({
plugins: [fixTSImport],
test: {
include: ['test/**/*.ts'],
exclude: [...configDefaults.exclude, '**/helpers/**'],
deps: {
inline: ['vitest-mock-process'],
},
testTimeout: m(5),
hookTimeout: m(5),
},
});