Skip to content

Conversation

@astone123
Copy link
Contributor

@astone123 astone123 commented Oct 10, 2025

This PR closes https://github.com/cypress-io/cypress-services/issues/11991

Additional details

There are a few cases where we don't correctly derive the test body invocation details from the stack trace. This PR fixes those scenarios by looking for at eval or at Suite.eval in Chrome stack traces, and lines with anonymous functions in Firefox stack traces. This will allow Cypress Studio and "Open in IDE" features to work in more cases than they did before.

One of these situations is when it has been re-written as itGrep which happens in the @cypress/grep and @bahmutov/cy-grep plugins. This allows us to determine the correct invocation details for the test.

Steps to test

I tested this with the @bahmutov/cy-grep package. Install the package and register it in your support file in accordance with the documentation. Open Cypress Studio by clicking the "edit in studio" button next to a test. Verify that the test content is loaded correctly and you can edit and save the test as expected.

How has the user experience changed?

Users of @bahmutov/cy-grep package can now use Cypress studio as intended

PR Tasks


Note

Normalize test-body invocationDetails by trimming wrapper frames (Chrome/Firefox) and update e2e/unit tests so Open in IDE targets correct file/line/column.

  • Driver:
    • Normalize test-body invocationDetails from stack traces by adding stackWithWrappingLinesRemoved and updating $stackUtils.getInvocationDetails(specWindow, projectRoot, 'test-body').
    • In mocha.ts, pass 'test-body' when populating test.invocationDetails in Suite.prototype.addTest.
  • Unit Tests (packages/driver/test/unit/cypress/stack_utils.spec.ts):
    • Add scenarios verifying correct source mapping for grep/only stacks and fallback when normalization fails.
    • Mock Cypress.isBrowser and adjust project root handling.
  • E2E (App Runner) (packages/app/cypress/e2e/runner/reporter.hooks.cy.ts):
    • Add tests ensuring "open in IDE" sends correct invocation for before hooks, basic test body, .only, and wrapped it.
  • Fixtures:
    • Add system-tests/.../hooks/wrapped-it.cy.js to exercise wrapped it scenario.

Written by Cursor Bugbot for commit 96a9a10. This will update automatically on new commits. Configure here.

@astone123 astone123 self-assigned this Oct 10, 2025
@astone123 astone123 closed this Oct 10, 2025
@cypress
Copy link

cypress bot commented Oct 10, 2025

cypress    Run #67210

Run Properties:  status check passed Passed #67210  •  git commit 96a9a1032a: Merge branch 'develop' into astone123/fix-itgrep-trace
Project cypress
Branch Review astone123/fix-itgrep-trace
Run status status check passed Passed #67210
Run duration 17m 08s
Commit git commit 96a9a1032a: Merge branch 'develop' into astone123/fix-itgrep-trace
Committer Adam Stone-Lord
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 5
Tests that did not run due to a developer annotating a test with .skip  Pending 131
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 5535
View all changes introduced in this branch ↗︎

@astone123
Copy link
Contributor Author

@mschile @mabela416
After looking at fixing this on the cloud side for a bit, I think the best way to handle the grep stack issue is with a solution like this on the app side. We use the invocation details in various places across the app to decide which test to focus in studio mode and other things, so normalizing the stack on the cloud side doesn't fix the issue entirely. Let me know what you think

@astone123 astone123 reopened this Oct 28, 2025
@astone123 astone123 requested a review from mabela416 October 28, 2025 13:07
Copy link
Contributor

@mabela416 mabela416 left a comment

Choose a reason for hiding this comment

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

I tested it locally and it works

}
}

// if the stack includes the 'itGrep' function, remove any lines that include it
Copy link
Contributor

Choose a reason for hiding this comment

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

Likely good to reference what itGrep is and where it is coming from (same with above) https://github.com/cypress-io/cypress/blob/develop/npm/grep/src/register.ts#L77. people who aren't familiar with @cypress/grep will struggle to understand what this means.

The other concern I have is that there could be something legitimate in the stack that has itGrep in it that we want to capture but are omitting it here. Or is this only considered when trying to calculate the row/column in the spec file where the error occurred?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment there. I'm pretty sure this function is specifically used to identify where the test was executed from, so this shouldn't affect anything else. If it does, it'll be limited to use of the grep plugin

@astone123
Copy link
Contributor Author

@mschile I updated this so that it works for tests with .only as well as tests that are nested in suite definitions

@astone123 astone123 changed the title fix: (studio) remove itGrep lines from stack trace when determining invocationDetails fix: normalize test body invocationDetails from stack traces Nov 6, 2025
)
) {
lines.shift()
}
Copy link

Choose a reason for hiding this comment

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

Bug: Fix Chrome stack normalization for Context.eval lines

The Chrome stack normalization logic only checks for lines starting with at eval or at Suite.eval, but test invocation lines can also start with at Context.eval. This causes the function to incorrectly remove valid test invocation lines, potentially returning an empty stack or the wrong line. The condition should also check for at Context.eval to handle all test body invocation patterns.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might be missing something, but from my testing, even if we use context, the stack still contains Suite.eval. So I think this is fine

@astone123 astone123 requested a review from AtofStryker November 7, 2025 15:57
const splitAtAt = line.split('@')

// firefox stacks traces look like:
// functionName@https://aicotravel.com/__cypress/tests?p=cypress/support/e2e.js:444:14
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use a different url besides aicotravel in the docs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops - meant to change that. Will update that to something else

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.

4 participants