Vscode-jest: Debug codelens doesn't use custom `pathToConfig` setting

Created on 16 May 2019  路  4Comments  路  Source: jest-community/vscode-jest

It seems that #191 is back.

Environment

  1. node -v: 8.16.0
  2. npm -v: 6.4.1
  3. yarn -v: 1.16.0
  4. npm ls jest or npm ls react-scripts (if you haven鈥檛 ejected): 24.8.0
  5. your vscode-jest settings if customized:

    • jest.pathToJest? ./node_modules/jest/bin/jest.js --onlyChanged --coverage
    • jest.pathToConfig? ./dev/tools/jest-runner/jest.config.js
  6. Operating system: macOS 10.14.4

Prerequisite

  • are you able to run jest test from command line? yes
  • how do you run your tests from command line? yarn test which calls jest --config dev/tools/jest-runner/jest.config.js

Steps to Reproduce

  1. Use a custom config and set jest.pathToConfig accordingly
  2. Try using the Debug codelens
  3. Note that the jest debug session is never given the path to the config file

Expected Behavior

  1. Use a custom config and set jest.pathToConfig accordingly
  2. Try using the Debug codelens
  3. The jest debug session is given the path to the config file and it finds the test to be executed and debugs it

Actual Behavior

  1. Use a custom config and set jest.pathToConfig accordingly
  2. Try using the Debug codelens
  3. The jest debug session is never given the path to the config file and it never finds the test to be executed

Most helpful comment

this issue has come up a few times, let's take this opportunity to discuss

why debug codelens doesn't use pathToConfig

Actually codelens not only does not incorporate pathToConfig it also doesn't use pathToJest. Because like most IDEs, vscode has its own debug architecture. It spawned its own node process following its debug configuration in launch.json.

The debug codelens will always look for the debug config named vscode-jest-tests in users "launch.json". If no such config found, it then falls back to a simple default debug config, which works for simple/basic projects but most likely not adequate for more sophisticated projects.

_"ok, I can't use jest.pathToJest but can't you add jest.pathToConfig to the default debug config?"_, you might ask...

Indeed we could, but you can also imagine that some projects might need different jest config for debugging vs. regular test run, so maybe we should add a separate jest.pathToDebugConfig? You can see in order to keep up with various development environments and frameworks, we can either keep expanding our configurations and risking overlapping/reinventing-the-wheel with vscode's, or we can help users to adopt vscode's native debug config, which is a useful skill beyond jest debug anyway... thus we choose the latter approach.

how do you add the custom jest config for debugging?

knowing why we choose this approach, now let's try to resolve your issue. This extension provides a few debug config baseline you can use:

  • "Jest: Default jest configuration"
  • "Jest: create-react-app"
  • "Jest: create-react-app (ejected)"

first, go to your debug view and open the launch.json so you can add the debug config, see vscode instruction.

when asking selecting debug environment or when clicking on the "add configuration..." button, choose one of the jest debug config mentioned above. In your case, you would probably choose "Jest: Default jest configuration" and add a config argument like below:

      {
            "type": "node",
            "name": "vscode-jest-tests",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest",
            "args": [
                "--runInBand",
                "--config",
                "./dev/tools/jest-runner/jest.config.js"
            ],
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true
        },

more...

vscode is gaining popularity, there is a large community to discuss and share information about how to configure vscode debugger, such as this. And we always welcome PRs to add more debug config snippets for other popular use cases.

All 4 comments

this issue has come up a few times, let's take this opportunity to discuss

why debug codelens doesn't use pathToConfig

Actually codelens not only does not incorporate pathToConfig it also doesn't use pathToJest. Because like most IDEs, vscode has its own debug architecture. It spawned its own node process following its debug configuration in launch.json.

The debug codelens will always look for the debug config named vscode-jest-tests in users "launch.json". If no such config found, it then falls back to a simple default debug config, which works for simple/basic projects but most likely not adequate for more sophisticated projects.

_"ok, I can't use jest.pathToJest but can't you add jest.pathToConfig to the default debug config?"_, you might ask...

Indeed we could, but you can also imagine that some projects might need different jest config for debugging vs. regular test run, so maybe we should add a separate jest.pathToDebugConfig? You can see in order to keep up with various development environments and frameworks, we can either keep expanding our configurations and risking overlapping/reinventing-the-wheel with vscode's, or we can help users to adopt vscode's native debug config, which is a useful skill beyond jest debug anyway... thus we choose the latter approach.

how do you add the custom jest config for debugging?

knowing why we choose this approach, now let's try to resolve your issue. This extension provides a few debug config baseline you can use:

  • "Jest: Default jest configuration"
  • "Jest: create-react-app"
  • "Jest: create-react-app (ejected)"

first, go to your debug view and open the launch.json so you can add the debug config, see vscode instruction.

when asking selecting debug environment or when clicking on the "add configuration..." button, choose one of the jest debug config mentioned above. In your case, you would probably choose "Jest: Default jest configuration" and add a config argument like below:

      {
            "type": "node",
            "name": "vscode-jest-tests",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest",
            "args": [
                "--runInBand",
                "--config",
                "./dev/tools/jest-runner/jest.config.js"
            ],
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true
        },

more...

vscode is gaining popularity, there is a large community to discuss and share information about how to configure vscode debugger, such as this. And we always welcome PRs to add more debug config snippets for other popular use cases.

@connectdotz thank you for that detailed response. This is incredibly helpful. I'm closing this out.

This should be documented in a Wiki page or something like that I think

Also requesting that this gets documented - it was not easy for me to find this relatively simple answer. Even a tiny note somewhere more obvious would be appreciated 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skippednote picture skippednote  路  3Comments

orta picture orta  路  5Comments

jpokrzyk picture jpokrzyk  路  5Comments

callmeberzerker picture callmeberzerker  路  3Comments

DaniGTA picture DaniGTA  路  3Comments