-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathvitest.config.js
More file actions
52 lines (50 loc) · 1.24 KB
/
vitest.config.js
File metadata and controls
52 lines (50 loc) · 1.24 KB
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 {defineConfig} from 'vitest/config'
function checker(request, response, next) {
if (request.method === 'POST' && request.url === '/ok') {
response.setHeader('content-type', 'text/html')
response.writeHead(200)
response.end('<b>Hello</b> world!')
return
} else if (request.method === 'POST' && request.url === '/server-error') {
response.writeHead(500)
response.end('{"message": "Server error!"}')
return
} else if (request.method === 'GET' && request.url === '/ok?query=hello') {
response.writeHead(200)
response.end('<b>Hello</b> world!')
return
} else if (request.method === 'GET' && request.url === '/ok?a=b&query=hello') {
response.writeHead(200)
response.end('<b>Hello</b> world!')
return
}
next()
}
export default defineConfig({
test: {
browser: {
enabled: true,
name: 'chromium',
provider: 'playwright',
headless: true
}
},
preview: {
port: 9876
},
server: {
port: 9876,
middlewareMode: false
},
plugins: [
{
name: 'test-server-middleware',
configureServer(server) {
server.middlewares.use(checker)
},
configurePreviewServer(server) {
server.middlewares.use(checker)
}
}
]
})