Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node Jest- Config paths must be specified

Tags:

node.js

jestjs

I am running Jest test cases into a reactjs project. I am trying to debug my jest test cases in VS code. The tests run ok on command line. But when I launch debugger in VS code I see error.

Launch.json

{
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "Jest Tests",
                "program": "${workspaceRoot}/xxx/xxx/node_modules/jest/bin/jest",
                "args": [
                    "-i"
                ],


                "internalConsoleOptions": "openOnSessionStart",
                "outFiles": [
                    "${workspaceRoot}/xxx/xxx/**/*"
                ]
            }
        ]
    }

Error

Debugger listening on ws://127.0.0.1:31182/2bf113f1-002f-49ed-ad91-5510affd172a
Debugger attached.
Error: Could not find a config file based on provided values:
path: "/Users/xxx/xxx/xxx-ui"
cwd: "/Users/xxx/xxx/xxx-ui"
Configh paths must be specified by either a direct path to a config
file, or a path to a directory. If directory is given, Jest will try to
traverse directory tree up, until it finds either "jest.config.js" or
"package.json".
like image 206
mbarish-me Avatar asked May 15 '26 15:05

mbarish-me


1 Answers

Just specify -c option in your launch config:

{
        "name": "Debug Jest Tests",
        "type": "node",
        "request": "launch",
        "runtimeArgs": [
          "--inspect-brk",
          "{$PathToNPMRoot}/node_modules/jest/bin/jest.js",
          "--runInBand",
          "-c", "{$PathToConfig}/jest.config.js",
        ],
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen",
        "port": 9229
      },

You will have to replace {$PathToNPMRoot} and {$PathToConfig}

Source

like image 178
Flummiboy Avatar answered May 17 '26 06:05

Flummiboy