-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathcypress.config.js
More file actions
96 lines (88 loc) · 2.82 KB
/
cypress.config.js
File metadata and controls
96 lines (88 loc) · 2.82 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// Include any other plugin code...
const http = require('http');
let server = null;
let responseDelay = 0;
let requests = [];
on('task', {
startServer() {
return new Promise((resolve) => {
requests = [];
server = http.createServer((req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.writeHead(204);
return res.end();
}
let body = '';
req.on('data', chunk => { body += chunk; });
req.on('end', () => {
requests.push({ method: req.method, url: req.url, headers: req.headers, body });
let payload = { result: 'Success' };
if (req.url && req.url.indexOf('/o/sdk/content') !== -1) {
payload = {
html: 'http://test/_external/content?id=111&uid=tester&app_id=222',
geo: {
l: {
x: 282,
y: 56,
w: 303,
h: 300
},
p: {
x: 62,
y: 325.5,
w: 288,
h: 216
}
}
};
}
setTimeout(() => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(payload));
}, responseDelay);
});
});
server.listen(9000, () => {
console.log('Test server running on http://localhost:9000');
resolve(null);
});
});
},
stopServer() {
return new Promise((resolve) => {
if (server) {
server.close(() => {
requests = [];
console.log('Test server stopped');
resolve(null);
});
} else {
resolve(null);
}
});
},
setResponseDelay(ms) {
responseDelay = ms;
return null;
},
getRequests() {
return requests;
},
clearRequests() {
requests = [];
return null;
},
});
// IMPORTANT: Return the config object with any changed environment variables
return config;
},
},
userAgent: "abcd",
});