Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky Cypress tests #265

Merged
merged 4 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
mmacai marked this conversation as resolved.
Show resolved Hide resolved
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)
mmacai marked this conversation as resolved.
Show resolved Hide resolved
});

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