Skip to content
New issue

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

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

Already on GitHub? # to your account

GUI and CLI Treat Top-Level beforeEach Differently #7313

Closed
CodingItWrong opened this issue May 12, 2020 · 2 comments
Closed

GUI and CLI Treat Top-Level beforeEach Differently #7313

CodingItWrong opened this issue May 12, 2020 · 2 comments
Labels
type: duplicate This issue or pull request already exists

Comments

@CodingItWrong
Copy link

CodingItWrong commented May 12, 2020

Current behavior:

  • I have a test suite that has one test file with a top-level beforeEach block
  • When I "Run all specs" in the GUI, the beforeEach block is run before every test file. As a result, the other test file was written to rely on the beforeEach block, and so it passes when run as part of the whole suite in the GUI:

Screen Shot 2020-05-12 at 11 42 07 AM

  • But when running this suite in the CLI, the beforeEach block is only run for the test file it's in. As a result, the other test file fails, even though it succeeded in the GUI:

Screen Shot 2020-05-12 at 11 42 35 AM

Desired behavior:

  • Running full test suite from the GUI or CLI should treat beforeEach blocks in the same way
  • Note that I don't desire the beforeEach block to behave one way or the other: whether it fails or succeeds consistently across the GUI and CLI is fine. A top-level beforeEach block is not recommended by Mocha. The desires is for consistency on this behavior across GUI and CLI.

Test code to reproduce

https://github.com/CodingItWrong/cypress-persistent-stub - instructions in readme

Versions

  • Cypress 4.5.0 (also seen in 4.2.0 in production project)
  • macOS 10.15.4
  • Node 12.16.2
@jennifer-shehane
Copy link
Member

Yes, this is a known limitation of 'Runs all specs'. In the future we will change it to behave the same as cypress run, so recommend that you update your test code accordingly.

Duplicate of #1586

@jennifer-shehane jennifer-shehane added the type: duplicate This issue or pull request already exists label May 14, 2020
@bahmutov
Copy link
Contributor

Just a note: I have wrote a blog post about it https://glebbahmutov.com/blog/run-all-specs/ and will add a note to our documentation

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants