-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcypress-node-events.js
35 lines (33 loc) · 1.13 KB
/
cypress-node-events.js
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
const fetch = require('node-fetch');
const waitOn = require('wait-on');
function nodeEvents(on) {
on('task', {
jambox: {
// Configure Jambox with a dynamic config during a test
config: async (jamboxConfig) => {
// When running the service with yarn dev nodemon will restart the server
// when src/** folders are changed so it's nicer to just wait for half a
// second before sending the config request
await waitOn({ resources: [`http://localhost:9000`], timeout: 1500 });
return fetch(`http://localhost:9000/api/config`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(jamboxConfig),
});
},
reset: async () => {
await waitOn({ resources: [`http://localhost:9000`], timeout: 1500 });
return fetch(`http://localhost:9000/api/reset`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ cwd: process.cwd() }),
});
},
},
});
}
module.exports = nodeEvents;