Current behavior:
Right now, whenever you start Cypress it will kick off some of the commands twice.
This isn't a problem most of the time as tests should be self contained anyway, but if you are using before hooks (for instance, to login and store cookies, as suggested by the docs) it becomes quite detrimental.
Desired behavior:
Cypress should only run once.
Steps to reproduce:
//__bug.spec.js
describe('Bug?', ()=>{
before(() =>{
cy.task('message', 'I\'m running!');
});
it('Should only log once', () => {
cy.visit('https://www.google.com');
});
});
//index.js
module.exports = (on) => {
on('task', {
message (args) {
console.log(args);
return null;
}
});
};
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 3.1.1 │
│ Browser: Electron 59 (headless) │
│ Specs: 1 found (__bug.spec.js) │
│ Searched: cypress/integration/__bug.spec.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: __bug.spec.js... (1 of 1)
Bug
I'm running!
I'm running!
✓ Should only log once (1159ms)
Note: this isn't exclusive to hooks! The below spec will also print unwanted results:
describe('Bug', ()=>{
it('Should only log once', () => {
cy.task('message', 'I\'m running!');
cy.visit('https://www.google.com');
});
it('Should only log once', () => {
cy.task('message', 'I\'m running!');
cy.visit('https://www.google.com');
});
it('Should only log once', () => {
cy.task('message', 'I\'m running!');
cy.visit('https://www.google.com');
});
it('Should only log once', () => {
cy.task('message', 'I\'m running!');
cy.visit('https://www.google.com');
});
});
Results:
Running: __bug.spec.js... (1 of 1)
Bug
I'm running!
I'm running!
✓ Should only log once (1091ms)
I'm running!
✓ Should only log once (3876ms)
I'm running!
✓ Should only log once (992ms)
I'm running!
✓ Should only log once (1449ms)
If the commands are inverted (i.e., if you visit() before logging) then the results are fine, so maybe Cypress waits for visit then reboots?
Versions
Electron 59 headless
Cypress 3.1.1
macOS High Sierra 10.13.6
Current behavior:
Right now, whenever you start Cypress it will kick off some of the commands twice.
This isn't a problem most of the time as tests should be self contained anyway, but if you are using before hooks (for instance, to login and store cookies, as suggested by the docs) it becomes quite detrimental.
Desired behavior:
Cypress should only run once.
Steps to reproduce:
Note: this isn't exclusive to hooks! The below spec will also print unwanted results:
Results:
If the commands are inverted (i.e., if you visit() before logging) then the results are fine, so maybe Cypress waits for visit then reboots?
Versions
Electron 59 headless
Cypress 3.1.1
macOS High Sierra 10.13.6