vscode-jest: v4 migration failed to debug tests correctly

Environment

  1. vscode-jest version: v4.0
  2. node -v: v14.15.
  3. npm -v: 6.14.10
  4. npm ls jest: 26.6.3
  5. your vscode-jest settings if customized:
  "jest.pathToJest": "./node_modules/.bin/jest",
  "jest.debugCodeLens.showWhenTestStateIn": ["fail", "unknown", "pass", "skip"]
  1. Operating system: Windows 10

Prerequisite

  • are you able to run jest test from the command line? Yes
  • how do you run your tests from the command line? npm run test (which just invokes jest)

Steps to Reproduce

In a NodeJS express Typescript project, using v3.2.0, without a modified launch.json, and with the following vscode-jest settings:

  "jest.pathToJest": "./node_modules/.bin/jest",
  "jest.debugCodeLens.showWhenTestStateIn": ["fail", "unknown", "pass", "skip"]

and the following jest.config.js:

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  testPathIgnorePatterns: ['node_modules/', 'build/', '__tests__/utils/*'],
  rootDir: 'src',
  moduleDirectories: ['node_modules', 'src'],
  collectCoverageFrom: ['**/*.{ts,tsx}', '!**/node_modules/**', '!**/vendor/**'],
}

worked. I could debug, the auto run/watch worked perfectly. After today’s update to v4.0.0, I couldn’t debug anymore and the Code Lens stopped working, and after about 20 minutes of messing with it to update to new settings, i gave up and reverted to v3.2.0 so I could continue working.

before: image

after: image

Relevant Debug Info

No error/warning output in the relevant output windows

Expected Behavior

A smooth migration between v3.2.0 settings and v4.0.0 settings

Actual Behavior

No migration happened, and debugging wouldn’t work anymore

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 63 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@Agalin turns out the it.each will not work for windows because the bug fix ( (facebook/jest#10413) merged with jest@26.5 is only for non-windows systems. The windows fix (facebook/jest#10871) will only be available in jest@27… I don’t know how I could have missed this post, but that is what it stated…

I will update the release note and migration guide, maybe think about a workaround to help windows users with parameterized tests…

thanks for bringing this to our attention!

@mil7 ohhh sorry I used as double click will follow steps and let u know.

one more try: vscode-jest-4.0.2-rc.2.vsix.zip

appreciate it if you can try it and let us know if it works

I can check it tomorrow in the afternoon especially that I’m mostly using "jest.autoRun": "off" and Run Related Tests.

BTW could it be mapped by default to something else? ctrl+t is by default bound to Go to Symbol in Workspace (on macOS it’s Transpose letters). I’m currently using ctrl+alt+t as it’s free on both Windows and macOS (option for Mac of course). Not sure if ctrl->command conversion for macOS is automatic or manual. If manual then there would be no conflicts as ctrl+option+t is unused (while command+option+t is in use). Note that there might be better shortcuts available. VSCode seems to avoid ctrl+alt+letter shortcuts - probably due to it messing with some keyboard layouts where ctrl+alt is equal to AltGr (right alt) and can be used to type diacritics.

  1. Doesn’t work.
  2. Works.
  3. Works (irrelevant due to 2).
  4. Works.
  5. Works (irrelevant due to 4).

Also can confirm that dots should be escaped as well. It’s very rare to have files named in a way that would lead to issues but still possible. Should just pass the whole path through regexp escape of some kind as other special characters would lead to issues as well. For example if you for some reason have both Component.test.js and ComponentsTestsIJS.test.js then both will be selected. I can imagine naming like this being used for some test result viewer… Just escaping dots with \ fixes this case. It gets even worse if for some bizarre reason you have other regex-specific characters. I don’t think that it would be possible to select a test with $ or ^ in it. BTW fix for this part (regexp escape) would also fix the main issue (incorrectly escaped \) as it currently generates a regexp string with every \<character> being interpreted as a part of regexp’s special syntax.

So just put the file path through some regexp escape function and it should work.

@connectdotz Same issue here. I tried manually running it with the escaped file separators and the test was found correctly, with either case drive letter. Forward slashes also work.

 23:26:03 ❯ node '.\node_modules\jest\bin\jest' '--runInBand' '--config' './jest.json' 'e:\src\boolean.transform.spec.ts' '--testNamePattern' 'ToBoolean should transform true to true'
No tests found, exiting with code 1
 23:29:36 ❯ node '.\node_modules\jest\bin\jest' '--runInBand' '--config' './jest.json' 'e:\\src\\boolean.transform.spec.ts' '--testNamePattern' 'ToBoolean should transform true to true'
 FAIL  src/boolean.transform.spec.ts

Appears to be working in both WSL and vanilla Windows 10. 🎉 Thanks for the fast turnaround!

It works!

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10


From: ConnectDotz @.> Sent: Tuesday, May 11, 2021 2:28:12 PM To: jest-community/vscode-jest @.> Cc: Sean Ferguson @.>; Comment @.> Subject: Re: [jest-community/vscode-jest] v4 migration failed to debug tests correctly (#694)

ok, made some code change, please try and let us know if this worked…

vscode-jest-4.1.0-rc.1.vsix.ziphttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjest-community%2Fvscode-jest%2Ffiles%2F6462095%2Fvscode-jest-4.1.0-rc.1.vsix.zip&data=04|01|sferg%40exchange.microsoft.com|bcfa17d8a0324b9293fd08d914c3aec2|72f988bf86f141af91ab2d7cd011db47|1|0|637563652949718924|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=fN%2FkSmlzGH8UFApgjqnTGJ1ja9gM0t2N7EYualpUc6o%3D&reserved=0

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjest-community%2Fvscode-jest%2Fissues%2F694%23issuecomment-839187351&data=04|01|sferg%40exchange.microsoft.com|bcfa17d8a0324b9293fd08d914c3aec2|72f988bf86f141af91ab2d7cd011db47|1|0|637563652949728916|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=7BHC%2BwLqaLD1Ro2Nst1acPYN8H%2BvFxcaFdPMJHhaVRs%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FADSXPJVUYN4LDP2IN7XAQQTTNGOOZANCNFSM44RFADNQ&data=04|01|sferg%40exchange.microsoft.com|bcfa17d8a0324b9293fd08d914c3aec2|72f988bf86f141af91ab2d7cd011db47|1|0|637563652949728916|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=9wcUpwp6POmFcXy1MCkinwHXyTS2jxBNmuqEqJeZ0Q4%3D&reserved=0.

ok, made some code change, please try and let us know if this worked…

vscode-jest-4.1.0-rc.1.vsix.zip