Skip to content

Conversation

@ryanthemanuel
Copy link
Collaborator

@ryanthemanuel ryanthemanuel commented Oct 24, 2025

Additional details

Current Cypress code that determines absolute paths assumes that source maps are relative to the project root. This is not true. Users can have a webpack configuration that specifies a new root via the context property. To allow for this, we determine the new root. We do this by treating the spec file as an anchor point since we know it's absolute path. We can then look at the source maps and determine what "relative" is for that spec file. From this, we then calculate what the root is.

Steps to test

How has the user experience changed?

PR Tasks


Note

Determine and propagate a source map project root to resolve correct absolute file paths and IDE opening, and add targeted sourcemap tests and configs across runners.

  • Core/Driver (sourcemaps):
    • Add source_map_utils APIs to extract source maps, set/get projectRoot via spec anchor, and compute getBaseDirectory.
    • Use source map project root in cypress.ts, script_utils, stack_utils, mocha, origin and sessions commands to enhance stacks, invocation details, and file resolution.
    • Expose Cypress.areSourceMapsAvailable and Cypress.sourceMapProjectRoot.
    • Move custom protocol stripping to utils.stripCustomProtocol and update callers.
  • Reporter/Verification:
    • Pass filePath through createVerify and verifyIdeOpen to assert correct absolute path and IDE open behavior.
  • Tests:
    • Add/expand sourcemap E2E/CT tests (Vite and Webpack dev servers) to verify file path display and open:file events; scaffold specs under src/.
    • Add system tests with new .mjs configs (enabled/disabled and updated sourcemap root) and a new fixture project runner-e2e-specs-new-sourcemap-root.
  • Misc:
    • Update changelog with bugfix entry; tweak CI workflow branch filter.

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

@ryanthemanuel ryanthemanuel self-assigned this Oct 24, 2025
cursor[bot]

This comment was marked as outdated.

@cypress
Copy link

cypress bot commented Oct 24, 2025

cypress    Run #66974

Run Properties:  status check failed Failed #66974  •  git commit 69f79b0c96: fix build
Project cypress
Branch Review ryanm/fix/issue-with-sourcemaps
Run status status check failed Failed #66974
Run duration 21m 23s
Commit git commit 69f79b0c96: fix build
Committer Ryan Manuel
View all properties for this run ↗︎

Test results
Tests that failed  Failures 2
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 28
Tests that did not run due to a failure in a mocha hook  Skipped 1
Tests that passed  Passing 792
View all changes introduced in this branch ↗︎
UI Coverage  61.84%
  Untested elements 27  
  Tested elements 47  
Accessibility  99%
  Failed rules  0 critical   3 serious   1 moderate   0 minor
  Failed elements 18  

Tests for review

Failed  cypress\e2e\runner\retries.experimentalRetries.mochaEvents.cy.ts • 1 failed test • app-e2e

View Output

Test Artifacts
... > does not try to serialize error with err.actual as DOM node Test Replay Screenshots
Failed  cypress\e2e\runs.cy.ts • 1 failed test • app-e2e

View Output

Test Artifacts
... > displays each run with correct information Test Replay Screenshots
Flakiness  cypress\e2e\choose-a-browser.cy.ts • 1 flaky test • launchpad-e2e

View Output

Test Artifacts
Choose a browser page > System Browsers Detected > launches when --browser is passed alone through the command line Test Replay Screenshots

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@ryanthemanuel
Copy link
Collaborator Author

ryanthemanuel commented Oct 27, 2025

Bug: Bug

The source map project root is set too late. The mocha patches (in patchSuiteAddTest, patchSuiteAddSuite, and patchSuiteHooks) call getInvocationDetails() which depends on sourceMapProjectRoot being set. However, sourceMapProjectRoot is only set after runScripts() completes, which happens after the spec file is evaluated. During spec file evaluation, when describe() and it() are called, they trigger the patched mocha functions before sourceMapProjectRoot is initialized.

The correct order should be:

  1. Set sourceMapProjectRoot before evaluating the spec
  2. Then evaluate the spec (which calls describe/it)

Currently the order is:

  1. Apply mocha patches (with empty sourceMapProjectRoot)
  2. Load scripts and extract source maps
  3. Evaluate spec file (describe/it calls use empty sourceMapProjectRoot)
  4. Set sourceMapProjectRoot in .then() callback (too late)

packages/driver/src/cypress.ts#L435-L454

}))
})
.then(() => {
this.cy.initialize(this.$autIframe)
this.onSpecReady()
})
}
if (this.waitForStudio) {
// when running studio, wait until it's initialized before running
this.waitForStudio(run)
} else {
run()
}
}
maybeEmitCypressInCypress (...args: unknown[]) {
// emit an event if we are running a Cypress in Cypress E2E Test.
// used to assert the runner (mocha) is emitting the expected
// events/payload.

Fix in Cursor Fix in Web

This took a surgical approach. We:

  1. Patch mocha. This reads the source map root at execution time not at patch time
  2. Load the scripts and their corresponding sourcemaps
  3. Update the source map root path
  4. Run the scripts which then reads the root as described in step 1

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

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.

Open in IDE does not work when preprocessor uses a different root directory than the project root

3 participants