-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathvitest.config.mts
121 lines (113 loc) · 3.09 KB
/
vitest.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
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
118
119
120
121
import type { BrowserCommand, BrowserInstanceOption } from 'vitest/node'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import * as util from 'node:util'
import { defineConfig } from 'vitest/config'
const dir = dirname(fileURLToPath(import.meta.url))
const provider = process.env.PROVIDER || 'playwright'
const browser = process.env.BROWSER || (provider === 'playwright' ? 'chromium' : 'chrome')
const myCustomCommand: BrowserCommand<[arg1: string, arg2: string]> = ({ testPath }, arg1, arg2) => {
return { testPath, arg1, arg2 }
}
const stripVTControlCharacters: BrowserCommand<[text: string]> = (_, text) => {
return util.stripVTControlCharacters(text)
}
const devInstances: BrowserInstanceOption[] = [
{ browser },
]
const playwrightInstances: BrowserInstanceOption[] = [
{ browser: 'chromium' },
{ browser: 'firefox' },
{ browser: 'webkit' },
]
const webdriverioInstances: BrowserInstanceOption[] = [
{ browser: 'chrome' },
{ browser: 'firefox' },
]
export default defineConfig({
server: {
headers: {
'x-custom': 'hello',
// Vitest iframe should still be loaded
'X-Frame-Options': 'DENY',
'content-security-policy': 'frame-src https://example.com; frame-ancestors https://example.com',
},
},
optimizeDeps: {
include: ['@vitest/cjs-lib', 'react/jsx-dev-runtime'],
},
test: {
include: ['test/**.test.{ts,js,tsx}'],
includeSource: ['src/*.ts'],
// having a snapshot environment doesn't affect browser tests
snapshotEnvironment: './custom-snapshot-env.ts',
browser: {
enabled: true,
headless: false,
instances: process.env.BROWSER
? devInstances
: provider === 'playwright'
? playwrightInstances
: webdriverioInstances,
provider,
isolate: false,
testerScripts: [
{
content: 'globalThis.__injected = []',
type: 'text/javascript',
},
{
content: '__injected.push(1)',
},
{
id: 'ts.ts',
content: '(__injected as string[]).push(2)',
},
{
src: './injected.ts',
},
{
src: '@vitest/injected-lib',
},
],
orchestratorScripts: [
{
content: 'console.log("Hello, World");globalThis.__injected = []',
type: 'text/javascript',
},
{
content: 'import "./injected.ts"',
},
{
content: 'if(__injected[0] !== 3) throw new Error("injected not working")',
},
],
commands: {
myCustomCommand,
stripVTControlCharacters,
},
},
alias: {
'#src': resolve(dir, './src'),
},
open: false,
diff: './custom-diff-config.ts',
outputFile: {
html: './html/index.html',
json: './browser.json',
},
env: {
BROWSER: browser,
},
},
plugins: [
{
name: 'test-no-transform-ui',
transform(_code, id, _options) {
if (id.includes('/__vitest__/')) {
throw new Error(`Unexpected transform: ${id}`)
}
},
},
],
})