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

[PluginEvents] Cypress fires the 'before:spec' event twice #26300

Open
elaichenkov opened this issue Mar 30, 2023 · 3 comments
Open

[PluginEvents] Cypress fires the 'before:spec' event twice #26300

elaichenkov opened this issue Mar 30, 2023 · 3 comments
Assignees
Labels
E2E Issue related to end-to-end testing pkg/app This is due to an issue in the packages/app directory Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug v10.8.0 🐛 Issue present since 10.8.0

Comments

@elaichenkov
Copy link

Current behavior

Cypress fires before:spec event twice.

npx cypress run
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        12.9.0                                                                         │
  │ Browser:        Electron 106 (headless)                                                        │
  │ Node Version:   v16.15.0 (/Users/ylaichenkov/.nvm/versions/node/v16.15.0/bin/node)             │
  │ Specs:          1 found (todo.cy.js)                                                           │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  │ Experiments:    experimentalInteractiveRunEvents=true                                          │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  todo.cy.js                                                                      (1 of 1)

--------> Running "before:spec" event <----------



  example to-do app

--------> Running "before:spec" event <----------

    ✓ displays two todo items by default (643ms)


  1 passing (3s)


  (Results)

Screenshot 2023-03-30 at 11 05 51

Desired behavior

Cypress fires all events only once

Test code to reproduce

// example.cy.js

describe('example to-do app', () => {
  it('opens todo app', () => {
    cy.visit('https://example.cypress.io/todo')
  })
})
// cypress.config.js
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('before:spec', () => console.log('\n--------> Running "before:spec" event <----------\n'));
    },
  },
})

Cypress Version

12.9.0

Node version

v16.15.0

Operating System

macOS Version 13.2.1

Debug Logs

No response

Other

No response

@emilyrohrbough
Copy link
Member

I was able to reproduce this behavior and this is not correct behavior. Thank you for the straight-forward reproduction. I actually noticed this same behavior this week.

Issue: The reason you are seeing it log 2x is without a baseUrl set and your first cy.visit() changes top, (or if you do have baseUrl set but your visit is to a different domain), Cypress is reloading on the page.

Expected Behavior: When Cypress is reloaded mid-test, it should not re-trigger the before:spec lifecycle event.

@emilyrohrbough emilyrohrbough added type: bug pkg/app This is due to an issue in the packages/app directory routed-to-e2e labels Mar 30, 2023
@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@mschile mschile added the v10.8.0 🐛 Issue present since 10.8.0 label Apr 28, 2023
@mschile
Copy link
Contributor

mschile commented Apr 28, 2023

This appears to have been introduced in v10.8.0, possibly with this commit.

@badeball
Copy link
Contributor

It is true that with v10.7.0, the before:spec isn't emitted twice, but task-handlers are. IE. the test is re-run for all practical purposes and non-idemponent task handlers must track state somehow. It also means that #26613 isn't strictly a duplicate of this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing pkg/app This is due to an issue in the packages/app directory Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug v10.8.0 🐛 Issue present since 10.8.0
Projects
None yet
Development

No branches or pull requests

5 participants