Skip to content

Pretty output fails if before hook is run twice #1091

@kduret

Description

@kduret

Current behavior

If the base url is updated and is visited in a before hook, then the hook is run twice

support/e2e.ts

before(() => {
  Cypress.config('baseUrl', 'http://0.0.0.0:4000');

  cy.intercept('/waiting-page', {
    headers: { 'content-type': 'text/html' },
    statusCode: 200
  }).visit('/waiting-page');
});

result :

An error was thrown in your plugins file while executing the handler for the before:spec event.

The error we received was:

Error: Unexpected state in beforeSpecHandler: before-spec (this might be a bug, please report at https://github.com/badeball/cypress-cucumber-preprocessor)
    at createError (/home/kduret/workspace/cypress-cucumber-preprocessor/examples/webpack-ts/node_modules/.pnpm/@[email protected]_pjwvil4ofno6sgsjgd5tdc3zby/node_modules/@badeball/cypress-cucumber-preprocessor/dist/helpers/error.js:9:12)
    at beforeSpecHandler (/home/kduret/workspace/cypress-cucumber-preprocessor/examples/webpack-ts/node_modules/.pnpm/@[email protected]_pjwvil4ofno6sgsjgd5tdc3zby/node_modules/@badeball/cypress-cucumber-preprocessor/dist/plugin-event-handlers.js:189:43)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
 ELIFECYCLE  Command failed with exit code 1.

this seems related to cypress-io/cypress#26300

Desired behavior

Waiting a fix on cypress, handle this case, handle this specific case in event handler
This has already been done for a similar issue : https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/lib/plugin-event-handlers.ts#L446-L450

Test code to reproduce

Issue is reproduced here : https://github.com/kduret/cypress-cucumber-preprocessor/tree/reproduce-twice-before/examples/webpack-ts
I run the test with : pnpm run cypress:run

Versions

  • Cypress version: 13.1.0
  • Preprocessor version: 18.0.5
  • Node version: v18.17.0

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions