Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vscode jest debug profile with external jest-config #43522

Closed
firsttris opened this issue Feb 12, 2018 · 12 comments
Closed

vscode jest debug profile with external jest-config #43522

firsttris opened this issue Feb 12, 2018 · 12 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@firsttris
Copy link

Holla,
I'm trying to create a jest debug profile with external config.

but i always get the following message:

Error: Can't find a root directory while resolving a config file path.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Jest Tests",
            "type": "node",
            "request": "launch",
            "port": 9229,
            "runtimeArgs": [
                "--inspect-brk",
                "${workspaceRoot}/node_modules/jest/bin/jest.js",
                "-i",
                "-t should dispatch GetAccessToken Test",
                "-c ${workspaceRoot}/jest-config.json",  
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen"
        },
    ]
}

while running jest with config from cli is possible, im not able todo this from a vscode debug profile.

on cli you can pass config with -c jest-config.json

any advice?

regards
tristan

@weinand
Copy link
Contributor

weinand commented Feb 12, 2018

@firsttris what do you mean by "external config"?

A "launch.json" will only be found if you open a project folder in VS Code (otherwise there is no ".vscode" folder where the launch.json could live).

BTW, a somewhat simpler and clearer config for jest is:

        {
            "name": "Debug Jest Tests",
            "type": "node",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
            "args": [
                "-i",
                "-t", "should dispatch GetAccessToken Test",
                "-c", "${workspaceFolder}/jest-config.json"
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen"
        }

@weinand weinand added info-needed Issue requires more information from poster debug Debug viewlet, configurations, breakpoints, adapter issues labels Feb 12, 2018
@firsttris
Copy link
Author

Hey @weinand

thx for taking the time to reply to my issue!

with external config i mean external Jest config jest-config.json

if the jest-config is located in package.json i have no issue.

@firsttris
Copy link
Author

firsttris commented Feb 12, 2018

i updated my debug-profile to the more cleaner version, thx!

no issues running Jest with external jest-config from CLI.

no issues with running VSCode Debug Profile for Jest and Jest-config in Package.json

but Error with VSCode Debug Profile for Jest and Jest-Config in a external file e.g. ./jest-config.json

image

@firsttris firsttris changed the title vscode jest debug profile with external config vscode jest debug profile with external jest-config Feb 12, 2018
@weinand
Copy link
Contributor

weinand commented Feb 12, 2018

Does it make a difference if you make the "jest-config.json" relative, e.g.

        {
            "name": "Debug Jest Tests",
            "type": "node",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
            "args": [
                "-i",
                "-t should dispatch GetAccessToken Test",
                "-c jest-config.json",  
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen"
        }

@firsttris
Copy link
Author

firsttris commented Feb 13, 2018

Same Issue
(already tried all possible variants for absolut & relative paths)

Error: Can't find a root directory while resolving a config file path.
Provided path to resolve:  jest-config.json

@weinand
Copy link
Contributor

weinand commented Feb 13, 2018

@firsttris the error message you are seeing originates from jest, not from VS Code. So you might want to investigate on the jest side as well, e.g. jestjs/jest#3499.

@firsttris
Copy link
Author

i thought so as well..

but...

  • this issue only happens within a VSCode Debug Profile. not from CLI
  • In Webstorm i have also not issue debugging with external jest-config
  • A jest config change (like suggested in the issue you liked) won't help since jest can't find the config in the first place

continue investigating on both sides

@weinand
Copy link
Contributor

weinand commented Feb 13, 2018

So where does the jest-config.json actually live?

@firsttris
Copy link
Author

firsttris commented Feb 13, 2018

jest-config.json is in the ProjectRoot Directory.

i found out if i rename the jest-config.json to jest.config.js

it finds the config without --config (-c) argument

because they setup some default names, to look for:
https://github.com/facebook/jest/blob/master/packages/jest-config/src/constants.js#L16

       {
            "name": "Debug Jest Tests",
            "type": "node",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
            "args": [
                "-i",
                "-t should dispatch GetAccessToken Test"
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen"
        }

for me this workaround is acceptable.

if you don't want to explore further why --config (-c) is not working, we can close this issue

@weinand
Copy link
Contributor

weinand commented Feb 13, 2018

Oh, I think I know what the problem is.
A construct like "-c jest-config.json" must be passed as two separate arguments, e.g. "-c", "jest-config.json". The equivalent "--config=jest-config.json" can be passed as one.

Try this:

        {
            "name": "Debug Jest Tests",
            "type": "node",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
            "args": [
                "-i",
                "-t", "should dispatch GetAccessToken Test",
                "-c", "jest-config.json"
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen"
        }

I will fix my suggestion from above too (so that no one will find a bogus example).

@firsttris
Copy link
Author

firsttris commented Feb 13, 2018

thanks for your help, your suggestion is working!

now i can update my vscode addon 👍
https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner

@weinand
Copy link
Contributor

weinand commented Feb 13, 2018

Great, and sorry for not spotting this earlier.

@weinand weinand removed the info-needed Issue requires more information from poster label Feb 13, 2018
@weinand weinand closed this as completed Feb 13, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

2 participants