-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.js
49 lines (42 loc) · 1.39 KB
/
commands.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function zip(lists) {
return lists[0].map((_, i) => lists.map(array => array[i]));
}
function addCommands() {
Cypress.Commands.add("resetWsMessages", () => {
cy.request("DELETE", "http://localhost:3000/__cypress/messages");
});
Cypress.Commands.add("overrideWsOptions", options => {
cy.request({
method: "POST",
url: "http://localhost:3000/__cypress/options",
body: options,
);
});
Cypress.Commands.add("expectWsMessages", (expected, options) => {
const sleepTime = 250;
const maxInvocations = ((options && options.timeout) || 2500) / sleepTime;
function waitForMessages(invocation) {
if (invocation > 10) {
throw "Giving up waiting after 2.5s";
}
return cy.wait(sleepTime).then(() => {
return cy.request("GET", 'http://localhost:3000/__cypress/messages')
.its("body")
.then(body => {
if (body.length < expected.length) {
return waitForMessages(invocation + 1);
}
else {
return body;
}
});
});
}
waitForMessages(0).then(actual => {
cy.expect(actual.map(JSON.stringify)).to.include.members(expected.map(JSON.stringify));
});
});
}
module.exports = {
addCommands,
};