Skip to content

Commit

Permalink
Fix flaky Cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Azer0s committed Sep 24, 2019
1 parent e4bc9f6 commit a2cb254
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions examples/tests/cypress/integration/channels.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Channels', () => {
cy.subscribe('mike', 'my.public.event');
// "foo":"bar" due to way how Cypress handles escaping of curly braces
cy.sendEvent('my.public.event', '"foo":"bar"');
cy.assertReceivedEvents('event-log', '(.*my.public.event)(.*"foo":"bar")');
cy.assertReceivedEventLog('event-log', '(.*my.public.event)(.*"foo":"bar")');
cy.disconnect();
});

Expand All @@ -16,11 +16,11 @@ describe('Channels', () => {
cy.subscribe('mike', 'message');
// "name":"mike","foo":"bar" due to way how Cypress handles escaping of curly braces
cy.sendEvent('message', '"name":"mike","foo":"bar"');
cy.assertReceivedEvents('event-log', 'message', '"name":"mike","foo":"bar"');
cy.assertReceivedEventLog('event-log', '"name":"mike","foo":"bar"');
// send constrained event for different user - John
cy.sendEvent('message', '"name":"john","foo":"bar"');
// Mike shouldn't receive any new event
cy.wait(2000).assertReceivedEvents(
cy.assertReceivedEventLog(
'event-log',
'(.*message)(.*"name":"mike","foo":"bar")'
);
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/cypress/integration/subscriptions-jwt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Subscriptions with JWT auth', () => {
cy.setAndVerifyInput('greeting', 'hello');
cy.setAndVerifyInput('name', 'mike');
cy.submit();
cy.wait(2000).assertReceivedEvents('eventList', '"name":"john","greeting":"hello"');
cy.assertReceivedEvents('eventList', '"name":"john","greeting":"hello"');
});

it(`Creates ${type} subscriptions based on JWT in connection call and applies constraints`, () => {
Expand All @@ -30,7 +30,7 @@ describe('Subscriptions with JWT auth', () => {
cy.setAndVerifyInput('greeting', 'hello');
cy.setAndVerifyInput('name', 'mike');
cy.submit();
cy.wait(2000).assertReceivedEvents(
cy.assertReceivedEvents(
'eventList',
'"name":"john.doe","greeting":"hello"'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Subscriptions with no auth', () => {
cy.setAndVerifyInput('greeting', 'hello');
cy.setAndVerifyInput('name', 'mike');
cy.submit();
cy.wait(2000).assertReceivedEvents('eventList', '"name":"john","greeting":"hello"');
cy.assertReceivedEvents('eventList', '"name":"john","greeting":"hello"');
});
});
});
10 changes: 9 additions & 1 deletion examples/tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ Cypress.Commands.add('sendEvent', (eventType, message) => {

Cypress.Commands.add('assertReceivedEvents', (element, message) => {
// assert number and content of received events
cy.get(`#${element}`)
cy.get(`#${element} > li`, {timeout: 30000})
.should('be.visible')
.first()
.contains(message)
});

Cypress.Commands.add('assertReceivedEventLog', (element, message) => {
// assert number and content of received events
cy.get(`#${element}`, {timeout: 30000})
.should('have.length', 1)
.first()
.contains(new RegExp(message, 'g'));
Expand Down

0 comments on commit a2cb254

Please sign in to comment.