jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.85k stars 295 forks source link

Can't debug tests with version 5.1 of plugin #997

Closed StMartin81 closed 1 year ago

StMartin81 commented 1 year ago

Environment

  1. vscode-jest version: v5.1.0
  2. node -v: v18.13.0
  3. npm -v: 9.3.1
  4. npm ls jest:
    ├─┬ @vue/vue2-jest@29.2.2
    │ └── jest@29.3.1 deduped
    ├── jest@29.3.1
    └─┬ ts-jest@29.0.3
    └── jest@29.3.1 deduped
  5. your vscode-jest settings if customized: -
  6. Operating system: Windows 11

Behavior

With version 5.1 of this plugin I'm not able to debug the tests anymore. With version v4.6.0 it was possible to debug the tests.

I saw that the command line for running the tests did change: v4.6.0:

PS C:\repositories\myProject>  C:; cd 'C:\repositories\myProject'; ${env:NODE_OPTIONS}='--require "c:/Users/mstolpe/AppData/Local/Programs/Microsoft VS Code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.bundle.js" --inspect-publish-uid=http'; ${env:VSCODE_INSPECTOR_OPTIONS}='{"inspectorIpc":"\\\\.\\pipe\\node-cdp.31144-4.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\mstolpe\\AppData\\Local\\Temp\\node-debug-callback-408ed9fbf17fa557"}'; & 'C:\Program Files\nodejs\node.exe' '.\node_modules\jest\bin\jest' '--runInBand' '--watchAll=false' '--testNamePattern' '.*' '--runTestsByPath' 'C:\repositories\myProject\tests\unit\myTest.spec.ts'

v5.1.0:

PS C:\repositories\myProject>  ${env:NODE_OPTIONS}='--require "c:/Users/mstolpe/AppData/Local/Programs/Microsoft VS Code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.bundle.js" --inspect-publish-uid=http'; ${env:VSCODE_INSPECTOR_OPTIONS}='{"inspectorIpc":"\\\\.\\pipe\\node-cdp.35324-1.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\mstolpe\\AppData\\Local\\Temp\\node-debug-callback-bc64ae59dd403a5d"}'; & 'C:\Program Files\nodejs\node.exe' '.\node_modules\.bin\jest.cmd' '--runInBand' '--watchAll=false' '--testNamePattern' '.*' '--runTestsByPath' 'C:\repositories\myProject\tests\unit\myTest.spec.ts'

This is the output:

Debugger attached.
Waiting for the debugger to disconnect...
C:\repositories\myProject\node_modules\.bin\jest.cmd:1
@ECHO off
^

SyntaxError: Invalid or unexpected token
    at internalCompileFunction (node:internal/vm:74:18)
    at wrapSafe (node:internal/modules/cjs/loader:1141:20)
    at Module._compile (node:internal/modules/cjs/loader:1182:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.13.0
galaxyfeeder commented 1 year ago

+1 over here with v5.1:

node -v: 16.10 npm -v 7.24.0 OS: Macos Ventura 13.0

connectdotz commented 1 year ago

Shoot, yes, looks like there is a problem... This looks like an auto-config issue. It used .\node_modules\.bin\jest.cmd instead of .\node_modules\jest\bin\jest.

You can workaround this by clone the auto-config vscode-jest-tests.v2 to launch.json (see https://github.com/jest-community/vscode-jest#how-to-debug-tests), then changing the program path jest.cmd to jest. Or downgrade to 4.6 until the patch is ready.

[update] Actually, the easiest workaround might be to just add an "test": "jest" script in package.json then reload the window.

I will take a closer look tomorrow to see how we can patch it soon.

connectdotz commented 1 year ago

We just released v5.2.1 pre-release with the fix. Please give it a try and let us know how it works for you.

StMartin81 commented 1 year ago

It works. Thank you!