firsttris / vscode-jest-runner

Simple way to run or debug one or more tests from context menu, codelens or command plalette
https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner
MIT License
265 stars 124 forks source link

can not debug es6 #222

Closed sinkcup closed 2 years ago

sinkcup commented 2 years ago

config Jest Command or set ENV is useful for Run, but not for Debug.

export NODE_OPTIONS=--experimental-vm-modules
NODE_OPTIONS=--experimental-vm-modules npx jest

image image image image

Napam commented 2 years ago

I have the same issue as well, I have "jestrunner.jestCommand": "node --experimental-vm-modules node_modules/jest/bin/jest.js" in my settings.json, and it works for run, but is unused for debug

firsttris commented 2 years ago

does this isue still persists with 0.4.48 ?

sinkcup commented 2 years ago

yes, 0.4.48 still has this bug. @firsttris

ESM code: https://github.com/sinkcup/coverage-badge

jjm340 commented 2 years ago

I would love to see this fixed as well as I can't debug in certain scenarios because I need to run a custom NPM script in order to have all the settings line up.

Feijo commented 2 years ago

Any news about it?

firsttris commented 2 years ago

this should already be possible:

see the code: https://github.com/firsttris/vscode-jest-runner/blob/master/src/jestRunner.ts#L143

you should be able to overwrite the complete debug config to your specific requirements:

example:

{

  "jestrunner.debugOptions": {
    "program": "pathToJestExecutable",
    "env": {
      "YOU_ENV_VARIABLE": "value"
    }
  }
}

Please report back if it works

maybe we should include into the readme.md

firsttris commented 2 years ago

https://create-react-app.dev/docs/debugging-tests/#debugging-tests-in-visual-studio-code

Feijo commented 2 years ago

@firsttris it works!

    "jestrunner.debugOptions": {
        "program": "node_modules/jest/bin/jest.js",
        "env": {
            "NODE_OPTIONS": "--experimental-vm-modules"
        }
    },
    "jestrunner.jestCommand": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
jtlapp commented 1 year ago

I'm using a monorepo with root-level dependencies. "Run" works and "Debug" doesn't. The following does NOT correct my problem:

    "jestrunner.jestCommand": "npx jest",
    "jestrunner.debugOptions": {
      "program": "npx jest"
    }

I get this error:

Error: Cannot find module '/Users/joe/repos/fieldzoo/utils/kysely-tables/node_modules/jest/bin/jest.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1047:15)
    at Module._load (node:internal/modules/cjs/loader:893:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
jtlapp commented 1 year ago

UPDATE: I have the following working for both "Run" and "Debug". It requires that all of my monorepo workspaces be at the same depth:

    "jestrunner.jestCommand": "npx jest",
    "jestrunner.debugOptions": {
      "program": "../../node_modules/jest/bin/jest.js"
    },