-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
vitest-make-config.mts
47 lines (41 loc) · 1.29 KB
/
vitest-make-config.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
/// <reference types="vitest" />
import babel from "@vitejs/plugin-react"
import tsconfigPaths from "vite-plugin-tsconfig-paths"
import { createRequire } from "node:module"
import { dirname, join } from "node:path"
import { fileURLToPath } from "node:url"
import { defineConfig } from "vitest/config"
const require = createRequire(import.meta.url)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const babelConfig = require("./.babel.mjs.json")
export function makeTestConfig(
directory: string,
testPath: string | Array<string> = "./test/*.ts",
tsConfigFileName: string = "tsconfig.test.json"
) {
return defineConfig({
plugins: [
babel({ babel: babelConfig }),
tsconfigPaths({
tsConfigPath: join(directory, tsConfigFileName)
})
],
test: {
watch: process.env.WATCH === "true",
include: Array.isArray(testPath) ? testPath : [testPath],
exclude: [
"**/test/type-level/*",
"**/test/helpers/*",
"**/test/fixtures/*"
],
globals: true
}
})
}
export function makeTestConfigFromImportMetaUrl(
url: string,
testPath: string | Array<string> = "./test/*.ts",
tsConfigFileName: string = "tsconfig.test.json"
) {
return makeTestConfig(dirname(fileURLToPath(url)), testPath, tsConfigFileName)
}