在将VSCode更新为1.32.1之后开玩笑“未找到测试”

时间:2019-03-11 05:33:23

标签: javascript reactjs visual-studio-code jestjs

我正在通过vscode config使用调试工具,这是launch.json的配置:

{
    "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",
            }
        }
    ]
}

在我将VSCode更新为1.32.1之前,此配置正常工作。现在,当我运行Jest当前文件时,控制台将像这样打印出来:

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...

我们将不胜感激,在此先感谢您。

2 个答案:

答案 0 :(得分:4)

在安装旧版本VSCode(1.30.2)之后,我看到了输出:

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...

差异为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将${relativeFile}的分隔符从\\更改为\,这就是jest无法找到测试文件的原因


对于那些被卡住的人,只需在"${relativeFile}"配置中将"${fileBasenameNoExtension}"更改为launch.json

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

答案 1 :(得分:0)

最好使用--runTestsByPath ${relativeFile},它总是有效的。