Skip to content

fix: ensure Cypress.stop fires all end events appropriately #31830

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

Merged
merged 10 commits into from
Jun 5, 2025

Conversation

mschile
Copy link
Contributor

@mschile mschile commented Jun 5, 2025

Additional details

  • Moved our abort logic until after the test:after:run:async event is sent. This will guarantee that the necessary events are received before the run is aborted.

Steps to test

  • Add the following listeners:
  Cypress.on('test:before:after:run:async', async () => {
    await new Promise(resolve => setTimeout(resolve, 20000))
  })
  • Run a test that use Cypress.stop()
  • Verify the Test Replay displays properly

How has the user experience changed?

Test Replay is now available for all tests when Cypress.stop() is used.

PR Tasks

@mschile mschile requested a review from Copilot June 5, 2025 15:43
@mschile mschile self-assigned this Jun 5, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where using Cypress.stop() aborted the run before all expected runner events were fired, ensuring Test Replay works as intended.

  • Updates the runner to emit the final 'end' event and remove listeners after stopping
  • Adds new system tests to verify Cypress.stop() behaves correctly in before, beforeEach, test, afterEach, and after hooks
  • Updates documentation and changelog to reflect the bugfix

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

File Description
system-tests/test/cypress-stop.spec.ts Adds tests to verify proper event firing when Cypress.stop() is invoked
system-tests/projects/cypres-stop/** Provides test fixtures for different hook scenarios using Cypress.stop()
packages/driver/src/cypress/runner.ts Refactors stop handling to ensure runner events are emitted and listeners removed
cli/CHANGELOG.md Documents the bugfix for Cypress.stop() behavior
Comments suppressed due to low confidence (1)

system-tests/projects/cypres-stop/package.json:1

  • [nitpick] The project name 'cypres-stop' might be a typo if the intended name is 'cypress-stop'. If intentional, consider adding a note to avoid potential confusion.
{

@mschile mschile requested a review from ryanthemanuel June 5, 2025 16:00
Copy link

cypress bot commented Jun 5, 2025

cypress    Run #62880

Run Properties:  status check passed Passed #62880  •  git commit e213486633: updates
Project cypress
Branch Review ryanm/fix/attempt-to-fix-Cypress.stop
Run status status check passed Passed #62880
Run duration 19m 23s
Commit git commit e213486633: updates
Committer Matthew Schile
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 9
Tests that did not run due to a developer annotating a test with .skip  Pending 1232
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 32182
View all changes introduced in this branch ↗︎
UI Coverage  45.96%
  Untested elements 189  
  Tested elements 165  
Accessibility  92.74%
  Failed rules  3 critical   9 serious   2 moderate   2 minor
  Failed elements 697  

Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for adding tests to cover all the hook cases.

Copy link
Collaborator

@ryanthemanuel ryanthemanuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job. Glad to get some system tests in there for it!

@mschile mschile merged commit 76eb083 into develop Jun 5, 2025
89 of 91 checks passed
@mschile mschile deleted the ryanm/fix/attempt-to-fix-Cypress.stop branch June 5, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cypress.stop() does not always fire test:after:run:async events
3 participants