-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcypress.config.js
More file actions
43 lines (38 loc) · 1.12 KB
/
cypress.config.js
File metadata and controls
43 lines (38 loc) · 1.12 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
import { defineConfig } from 'cypress';
import fs from 'fs';
import http from 'http';
export default defineConfig({
e2e: {
supportFile: false,
setupNodeEvents(on, config) {
let lastEmail = {}
const getBody = (request) => {
return new Promise((resolve) => {
const bodyParts = [];
let body;
request.on('data', (chunk) => {
bodyParts.push(chunk);
}).on('end', () => {
body = Buffer.concat(bodyParts).toString();
resolve(body)
});
});
}
const requestListener = async function (req, res) {
const json = JSON.parse(await getBody(req));
lastEmail[json.To] = json;
res.writeHead(200);
res.end();
};
const server = http.createServer(requestListener);
server.listen('7777', 'localhost', () => {
console.log(`Server is running on http://localhost:7777`);
});
on('task', {
async getLastEmail(userEmail) {
return new Promise(resolve => setTimeout(() => resolve(lastEmail[userEmail] || null), 1000));
}
})
}
}
})