-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvite.config.ts
53 lines (44 loc) · 1.59 KB
/
vite.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import fs from 'fs'
import { resolve } from 'path'
import GithubActionsReporter from 'vitest-github-actions-reporter'
import { defineConfig } from 'vitest/config'
// Workaround for determining the aliases
// Taken from https://github.com/nuxt/framework/discussions/5379#discussioncomment-2942984
const nuxtTsConfig = fs.readFileSync('./.nuxt/tsconfig.json').toString()
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const tsConfigFormated = JSON.parse(
nuxtTsConfig.replace(
/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
(m, g) => (g ? '' : m)
)
)
const r = (p: string) => resolve(__dirname, p)
export const alias: Record<string, string> = {}
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
Object.entries(tsConfigFormated.compilerOptions.paths).forEach(
([key, value]) => {
// @ts-expect-error: value is an array
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
alias[key] = r(value[0])
}
)
export default defineConfig({
test: {
alias,
// Provide global API
// https://vitest.dev/config/#globals
globals: true,
// Run before each test file
// https://vitest.dev/config/#setupfiles
setupFiles: ['test/global.setup.ts'],
// Code coverage
// https://vitest.dev/config/#coverage and https://vitest.dev/guide/coverage.html
coverage: {
reporter: ['json', 'text'],
},
// Create annotations when tests fail in GitHub Actions
reporters: process.env.GITHUB_ACTIONS
? ['default', new GithubActionsReporter()]
: 'default',
},
})