This repository was archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcypress.config.ts
More file actions
79 lines (71 loc) · 2.05 KB
/
cypress.config.ts
File metadata and controls
79 lines (71 loc) · 2.05 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
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
import path from "node:path"
import { defineConfig } from "cypress"
import { getLocal } from "mockttp"
import type { Mockttp } from "mockttp"
import { API_DEFAULT_PORT } from "./tools/api"
import type { Handlers } from "./cypress/fixtures/handler"
const UPLOADS_FIXTURES_DIRECTORY = path.join(
process.cwd(),
"cypress",
"fixtures",
"uploads",
)
let server: Mockttp | null = null
export default defineConfig({
fixturesFolder: false,
video: false,
screenshotOnRunFailure: false,
e2e: {
baseUrl: "http://127.0.0.1:3000",
supportFile: false,
setupNodeEvents(on, config) {
on("task", {
async startMockServer(handlers: Handlers): Promise<null> {
server = getLocal({ cors: true })
await server.start(API_DEFAULT_PORT)
for (const handler of handlers) {
const { isFile = false, statusCode, body } = handler.response
let requestBuilder = server.forGet(handler.url)
switch (handler.method) {
case "GET":
requestBuilder = server.forGet(handler.url)
break
case "POST":
requestBuilder = server.forPost(handler.url)
break
case "PUT":
requestBuilder = server.forPut(handler.url)
break
case "DELETE":
requestBuilder = server.forDelete(handler.url)
break
}
if (isFile) {
await requestBuilder.thenFromFile(
statusCode,
path.join(UPLOADS_FIXTURES_DIRECTORY, ...body),
)
} else {
await requestBuilder.thenJson(statusCode, body)
}
}
return null
},
async stopMockServer(): Promise<null> {
if (server != null) {
await server.stop()
server = null
}
return null
},
})
return config
},
},
component: {
devServer: {
framework: "next",
bundler: "webpack",
},
},
})