Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest "No tests found" after update VSCode to 1.32.1

I'm using debugging jest with vscode config, here is launch.json configurations:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Jest Current File",
            "program": "${workspaceFolder}/node_modules/.bin/jest",
            "args": [
                "${relativeFile}"
            ],
            "env": {
                "cross-env": "1",
                "NODE_PATH": "./src",
                "__PLATFORM__": " WEB",
            },
            "runtimeArgs": [
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "windows": {
                "program": "${workspaceFolder}/node_modules/jest/bin/jest",
            }
        }
    ]
}

This configurations worked properly until I updated VSCode to 1.32.1. Now when I run Jest current file, the console prints out like this:

Debugger attached.
No tests found
In D:\workspace\my-project
  747 files checked.
  testMatch:  - 747 matches
  testPathIgnorePatterns: \\node_modules\\ - 747 matches
  testRegex: (\\__tests__\\.*|(\.|\\)(test))\.js?$ - 15 matches
Pattern: src\utils\storage\my-file-name.test.js - 0 matches
Waiting for the debugger to disconnect...

Any help would be appreciated, thanks in advance.

like image 890
Hai Pham Avatar asked Mar 11 '19 05:03

Hai Pham


2 Answers

After install old version VSCode (1.30.2), I saw the output:

Test Suites: 1 passed, 1 total
Tests:       9 passed, 9 total
Snapshots:   0 total
Time:        4.866s
Ran all test suites matching /src\\utils\\storage\\my-file-name.test.js/i.
Waiting for the debugger to disconnect...

Difference is Pattern:

  • v1.30.2: /src\\utils\\storage\\my-file-name.test.js/i.
  • v1.32.1: src\utils\storage\my-file-name.test.js

VSCode change their ${relativeFile}'s seperator from \\ to \, this is why jest couldn't find out test file


For those who are being stuck, just change "${relativeFile}" to "${fileBasenameNoExtension}" in launch.json configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Jest Current File",
            "program": "${workspaceFolder}/node_modules/.bin/jest",
            "args": [
                "./${fileBasename}"
            ],
            "env": {
                "cross-env": "1",
                "NODE_PATH": "./src",
                "__PLATFORM__": " WEB",
            },
            "runtimeArgs": [
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "windows": {
                "program": "${workspaceFolder}/node_modules/jest/bin/jest",
            }
        }
    ]
}
like image 142
Hai Pham Avatar answered Nov 17 '22 02:11

Hai Pham


Better use --runTestsByPath ${relativeFile}, which always works.

like image 1
Michael Kriese Avatar answered Nov 17 '22 02:11

Michael Kriese