cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Stacktrace for errors in Cypress command log does not match the file when using Typescript

Open amenk opened this issue 1 year ago • 16 comments

Current behavior

  1. Execute cypress run,
  2. Test fails
  3. click the line in the backtrace (in PHPStorm)
  4. code does ot match

Line numbers of stack trace don't match the code in cypress 12.8

Basically the same like in

https://github.com/cypress-io/cypress/issues/7715

Desired behavior

The line numbers match the code

Test code to reproduce

Cypress Version

12.8.0

Node version

16.17.0

Operating System

Ubuntu 22.04

Debug Logs

No response

Other

No response

amenk avatar May 04 '23 12:05 amenk

@amenk Thanks for the reporting the issue. Can you please try on the latest version of Cypress to see if you can still reproduce this? Also, can you please provide a reproducible example of the issue you're encountering. Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

warrensplayer avatar May 08 '23 19:05 warrensplayer

@warrensplayer Thanks, we tried 12.11.0 as well - same issue - on different machines. Will try to cook up a smaller example.

amenk avatar May 09 '23 13:05 amenk

@amenk Would you like to correct the typo in your issue title? "ot" => "not"

MikeMcC399 avatar May 09 '23 13:05 MikeMcC399

Thanks @amenk, https://github.com/cypress-io/cypress-test-tiny might be useful to make the repro. It seems like there could be many variables at play. A quick test for me showed normal behavior when clicking through from a failing test - got to the correct line and character in the file in VS Code.

Screenshot 2023-05-10 at 11 15 26 AM

marktnoonan avatar May 10 '23 15:05 marktnoonan

okay, thanks. By the way: In our case even the built-in code view on the left sometimes did not match the error.

Will try to provide better info soon.

amenk avatar May 10 '23 15:05 amenk

I observe something else: Our code does not have ";" at the end, the cypress code has - so there is some transpilling happening there, I guess? Is this maybe messing up the line numbers?

image

amenk avatar May 11 '23 15:05 amenk

Yeah this is interesting, happy to take a closer look if we can reproduce - otherwise it will be very difficult to track down and verify that we have fixed something.

marktnoonan avatar May 15 '23 16:05 marktnoonan

Hello,

I'm facing the same bug, but I'm using Typescript. I made a repro based on the tiny cypress project.

https://github.com/Breek/cypress-test-tiny

2 commits:

  • add Typescript
  • create failing test to show the bug

It goes to line 25, but shoud go to 32 for the failing test.

Happy to help, Cheers Jérémy

jchatard avatar May 16 '23 07:05 jchatard

Screenshot to help. Capture_d’écran_2023-05-16_à_09_47_20-2

jchatard avatar May 16 '23 07:05 jchatard

Cool, we use a mix of TS and JS files by the way.

amenk avatar May 16 '23 08:05 amenk

Thanks for the repro @jchatard and the screenshot :), I confirmed with the repro provided that simply changing the extension in the Cypress test from .cy.ts to .cy.js "fixes" this.

Looks like a longstanding bug, I confirmed it all the way back in 9.7.0. Routing to the team to check it out further.

marktnoonan avatar May 18 '23 15:05 marktnoonan

Actually worth noting that typescript was not a part of your screenshots @amenk, I see a js file there. Can you confirm does js vs ts for the test make any difference to you?

marktnoonan avatar May 18 '23 15:05 marktnoonan

@marktnoonan Good point. I have a single .ts file (besides cypress.config.ts) in the project (support/index.d.ts) which was not part of the stacktrace. Still, renaming this file to index.d.js does not fix the line numbers.

amenk avatar May 18 '23 17:05 amenk

I also have a problem with the stack trace. The printed line numbers do not match the line numbers in the source files:

Test error: image

commands.ts code snippet: image

Note that the stack trace shows the compiled javascript, for example var productPriceFormatted = productPrice + '.00' instead of const productPriceFormatted: string = productPrice + '.00';

Our project uses pure TypeScript for Cypress, e.g.:

  • cypress.config.ts
  • support/commands.ts
  • support/e2e.ts
  • tests/10_login.cy.ts

And so on. I tried many different settings in tsconfig.json to get the source maps working correctly, but to no avail.

I use: Cypress 13.3.2 Node 16.20.0 Ubuntu 23.04

BillyTom avatar Oct 31 '23 09:10 BillyTom

Are there any plans to fix this, please?

aholland avatar May 08 '24 03:05 aholland

Same problem

spatiumstas avatar Jul 18 '24 16:07 spatiumstas