从Windows中的Visual Studio代码运行Jest导致未找到任何测试

时间:2017-05-13 16:16:38

标签: react-native visual-studio-code jestjs

出于某种原因,通过Visual Studio代码运行jest会返回类似于以下内容的内容:

running command> jest --no-cache No tests found In c:\Users\gusta\Documents\ts 992 files checked. testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 121 matches testPathIgnorePatterns: \\node_modules\\ - 7 matches Pattern: "" - 0 matches

但是,从命令行运行测试时,它可以很好地解决测试问题。

C:\Users\gusta\Documents\ts>jest --no-cache PASS src\__test__\some-component.test.jsx (6.812s)

尝试在VSCode中进行调试时,以及运行任务时都会发生这种情况。我的tasks.json看起来像这样:

{ "version": "0.1.0", "tasks": [ { "taskName": "jest", "command": "jest", "args": [ "--no-cache" ], "isShellCommand": true, "echoCommand": true, "showOutput": "always" } ] }

我的package.json: { "name": "badgeexplorerts", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "android": "yarn run haul start -- --platform android", "test": "jest" }, "dependencies": { "@types/jest": "^19.2.3", "react": "~15.4.1", "react-native": "0.42.3", "ts-loader": "^2.0.3", "typescript": "^2.2.2" }, "devDependencies": { "@types/react": "^15.0.24", "@types/react-native": "^0.43.12", "babel-jest": "^20.0.0", "babel-loader": "^7.0.0", "babel-preset-es2015": "^6.24.1", "haul-cli": "^0.5.0", "jest": "^20.0.0", "react-test-renderer": "~15.4.1", "ts-jest": "^20.0.2" }, "jest": { "preset": "react-native" } }

有谁知道发生了什么事?我的VSCode版本是1.12.1

1 个答案:

答案 0 :(得分:0)

好的,事实证明如果你将“版本”改为2.0.0就可以了。 我无法解释,但是一个有效的task.json看起来像这样:

{ "version": "2.0.0", "tasks": [ { "taskName": "jest", "command": "jest", "args": [ "--no-cache" ], "isShellCommand": true, "echoCommand": true, "showOutput": "always" } ]
}

我遇到了与节点调试配置相同的问题,其中设置了

"console": "integratedTerminal" 在launch.json内部使它工作。我无法解释,但它对我有用。