簡體   English   中英

將 VSCode 更新到 1.32.1 后開玩笑“未找到測試”

[英]Jest "No tests found" after update VSCode to 1.32.1

我正在使用帶有 vscode 配置的調試玩笑,這里是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...

任何幫助將不勝感激,提前致謝。

安裝舊版本 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. name.test.js/ /src\\\\utils\\\\storage\\\\my-file-name.test.js/i.
  • v1.32.1: src\\utils\\storage\\my-file-name.test.js

VSCode 將其${relativeFile}的分隔符從\\\\更改為\\ ,這就是為什么jest找不到測試文件的原因


對於那些被卡住的人,只需在launch.json配置"${fileBasenameNoExtension}" "${relativeFile}"更改為"${fileBasenameNoExtension}"

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

更好地使用--runTestsByPath ${relativeFile} ,它始終有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM