Skip to content

Conversation

AtofStryker
Copy link
Contributor

@AtofStryker AtofStryker commented Mar 12, 2025

Additional details

When updating the monorepo to TypeScript 5 last year, I noticed that the error code frames source maps did not seem quite right. We filed #29614 with the intent to fix it. It turns out that inlineSourceMap is what is responsible for this inaccuracy, as it is inlining the transpiled TypeScript into the spec file and not the pure TypeScript source map. To fix this, we are enabling sourceMap to true for all user configs that are using @cypress/webpack-preprocessor (@cypress/webpack-batteries-included-preprocessor gets this via downstream impact as it uses @cypress/webpack-preprocessor) and setting inlineSourceMap to false.

This does NOT fix the custom preprocessor use case, for which we are adding documentation in cypress-io/cypress-documentation#6122 to guide users on how to configure their cypress tsconfig.json.This is mainly due to it being very difficult to hook into the TypeScript API to override defaults. The reason createProgram inside @cypress/webpack-preprocessor was not getting called in TypeScript 5 was because the package is now a true ES Module and exports are no longer modifiable (which is the case with the esbuild implemented specification). I have modified @cypress/webpack-preprocessor to check for the presence of TypeScript 4 to try and patch createProgram, but avoid it for newer versions as we know it will not be successful. I have also improved the logging around @cypress/webpack-preprocessor to help diagnose further issues if needed.

Ideally, we want to find a way to accomplish this in all cases, but for now we are mitigating through the default preprocessor and guiding users on how to configure their source maps. For instance, this doesn't work if the user is on TypeScript 5 and is using babel-loader with the @babel/preset-typescript configuration. The user in this case would need to set sourceMap in their actual config.

On a semi related note, we only pass a subset of options to ts-loader, where we should be sending the full user config. Since this change is fairly disruptive, we will be including it in Cypress 15 with #31282

Steps to test

run the tests in the project with the default @cypress/webpack-batteries-included-preprocessor/@cypress/webpack-preprocessor or run a standalone project with TypeScript configured and have a command fail inside your cypress test. The codeframe should now be much more accurate

How has the user experience changed?

PR Tasks

@AtofStryker AtofStryker force-pushed the fix/source_maps_typescript_wbip branch from 45d60b9 to 4b24b40 Compare March 12, 2025 17:52
@cypress
Copy link

cypress bot commented Mar 12, 2025

cypress    Run #61159

Run Properties:  status check passed Passed #61159  •  git commit 1b0b5eccab: address comments from code review
Project cypress
Branch Review fix/source_maps_typescript_wbip
Run status status check passed Passed #61159
Run duration 18m 41s
Commit git commit 1b0b5eccab: address comments from code review
Committer AtofStryker
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 1233
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 32129
View all changes introduced in this branch ↗︎
UI Coverage  46.44%
  Untested elements 183  
  Tested elements 163  
Accessibility  92.57%
  Failed rules  3 critical   8 serious   2 moderate   2 minor
  Failed elements 883  

@AtofStryker AtofStryker force-pushed the fix/source_maps_typescript_wbip branch from 4b24b40 to b1faca0 Compare March 13, 2025 15:45
@AtofStryker AtofStryker force-pushed the fix/source_maps_typescript_wbip branch 4 times, most recently from bf2e9df to d9da2c8 Compare March 13, 2025 22:23
@AtofStryker AtofStryker self-assigned this Mar 14, 2025
@AtofStryker AtofStryker force-pushed the fix/source_maps_typescript_wbip branch 2 times, most recently from 6c14a81 to bb9cf16 Compare March 14, 2025 20:01
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we aren't doing anything with this until #31282 except feeding the webpack plugin the tsconfig file path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

delegated to @cypress/webpack-preprocessor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any idea if webpack has some type of config utility parsing? This is a bit tedious

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, not that I can find. I was hoping to find a JOI or Zod schema, but wasn't able to find anything obvious

@AtofStryker AtofStryker force-pushed the fix/source_maps_typescript_wbip branch from bb9cf16 to 78e1b34 Compare March 14, 2025 20:28
cli/CHANGELOG.md Outdated

- [`Cypress.stop()`](https://on.cypress.io/cypress-stop) is now available to stop the Cypress App on the current machine while tests are running. This can be useful for stopping test execution upon failures or other predefined conditions. Addresses [#518](https://github.com/cypress-io/cypress/issues/518). Addressed in [#31225](https://github.com/cypress-io/cypress/pull/31225).

**Bugfixes:**
Copy link
Member

Choose a reason for hiding this comment

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

@AtofStryker Need to move this to a new release.

"debug": "^4.3.4",
"domain-browser": "^4.22.0",
"events": "^3.3.0",
"fs-extra": "^9.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, not that I can find. I was hoping to find a JOI or Zod schema, but wasn't able to find anything obvious

}

if (_.isObject(rule.use) && rule.use.loader && rule.use.loader.includes('ts-loader')) {
// it's an Object
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this comment is really that helpful...

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 need to add some better comments in here as to what we are checking for


debug('typescript modified createProgram options %o', options)

// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// @ts-ignore
// @ts-expect-error

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 think I can remove this entirely!

Copy link
Contributor

@mschile mschile left a comment

Choose a reason for hiding this comment

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

Looks good overall! Added a few comments.

@AtofStryker AtofStryker force-pushed the fix/source_maps_typescript_wbip branch from 78e1b34 to 1b0b5ec Compare March 24, 2025 19:05
@AtofStryker AtofStryker merged commit 7bdf1e9 into develop Mar 24, 2025
90 of 91 checks passed
@AtofStryker AtofStryker deleted the fix/source_maps_typescript_wbip branch March 24, 2025 20:34
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 26, 2025

Released in 14.2.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v14.2.1, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Mar 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaled UserInvocationStack is sometimes off for projects using Typescript 5

4 participants