-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Single test executes the same cy.task() command twice #4146
Comments
Can I ask you to try the same test, but move the URL you are about to visit
to `cypress.json` file (as "baseUrl": "https://google.com") please? I bet
this will solve the problem. Basically, Cypress has to "rewind" the test
when it sees a domain to visit, so it executes the command in front of it
"cy.task" twice. By moving the url to visit to cypress.json you warn
Cypress and it knows how to handle the domain it is about to see, which
removes the rewind.
…On Mon, May 6, 2019 at 7:31 PM ollie-o ***@***.***> wrote:
Current behavior:
Given a test like this:
context("Very bland test", () => {
it("replicates my bug", () => {
cy.task("log", "This should only be logged in the terminal once!");
cy.visit("https://google.com");
});
});
The cy.task() command is executed twice.
Desired behavior:
cy.task() should only be executed once in the above test, but instead it
is executed twice. We can tell because it leaves two logs in the Terminal
window.
Steps to reproduce: (app code and test code)
*Test File*
context("Very bland test", () => {
it("replicates my bug", () => {
cy.task("log", "This should only be logged in the terminal once!");
cy.visit("https://google.com");
});
});
*Plugins File*
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on("task", {
log(message) {
console.log(message);
return null;
}
});
};
*How to run*
./node_modules/.bin/cypress run --spec **/test.spec.js*
*What you will see*
Running: examples/test.spec.js... (1 of 1)
Very bland test
This should only be logged in the terminal once!
This should only be logged in the terminal once!
✓ replicates my bug (908ms)
Versions
Cypress: 3.2.0
Operating System: MacOS Mojave (10.14.4)
Browser: At least Electron. I haven't tested any others.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4146>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAQ4BJQSVTVNC4GFULNO7P3PUC5T7ANCNFSM4HLEFAIQ>
.
--
Dr. Gleb Bahmutov, PhD
Schedule video chat / phone call / meeting with me via
https://calendly.com/bahmutov
gleb.bahmutov@gmail.com @bahmutov <https://twitter.com/@bahmutov>
https://glebbahmutov.com/ https://glebbahmutov.com/blog
https://github.com/bahmutov
|
Thanks for the response @bahmutov! That workaround does cause
It would still be great if you could resolve the core bug though! On a personal level it was quite annoying for me to keep searching for the reason my code was executing twice - I kept searching for the bug in my own code, just to discover that it is a bug in the framework we are using. It would be great to save future users of Cypress from that frustration. |
Thanks for opening! This is a duplicate of this issue: #2777 |
Note: Here is a fork of
cypress-test-tiny
that reproduces the bug: https://github.com/ollie-o/cypress-test-tinyCurrent behavior:
Given a test like this:
The
cy.task()
command is executed twice.Desired behavior:
cy.task()
should only be executed once in the above test, but instead it is executed twice. We can tell because it leaves two logs in the Terminal window.Steps to reproduce: (app code and test code)
Test File
Plugins File
How to run
What you will see
Versions
Cypress: 3.2.0
Operating System: MacOS Mojave (10.14.4)
Browser: At least Electron. I haven't tested any others.
The text was updated successfully, but these errors were encountered: