rog*_*uib 7 node.js typescript jestjs ts-node ts-jest
我无法在运行玩笑测试时附加 VS Code 调试器。我尝试使用launch.json找到的不同替代方案配置文件,但它们总是失败并显示以下错误消息,抱怨 node_modules 文件夹中的文件:
Debugger attached.
Waiting for the debugger to disconnect...
local\path\to\node_modules\.bin\jest:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
Run Code Online (Sandbox Code Playgroud)
我的package.json文件具有以下配置:
Debugger attached.
Waiting for the debugger to disconnect...
local\path\to\node_modules\.bin\jest:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
Run Code Online (Sandbox Code Playgroud)
我的launch.json:
"scripts": {
"compile": "tsc",
"run": "node ./build/index.js",
"execute": "tsc && node ./build/index.js",
"test": "tsc && jest ./build/tests/*"
},
"author": "roguib",
"license": "ISC",
"dependencies": {
"@types/jest": "^26.0.20",
"ts-jest": "^26.5.1",
"ts-node": "^9.1.1"
},
"devDependencies": {
"@types/node": "^14.14.21",
"jest": "^26.6.3"
}
Run Code Online (Sandbox Code Playgroud)
如果有帮助,执行npm run test通常会运行我的笑话测试,所以我不确定它是否与笑话本身有关。
Windows 上似乎存在一个错误,解决方案是将 VS Code 直接指向 jest.js 而不是 .bin 版本:
所以尝试替换这个:
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand"],
类似的东西:
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/jest/bin/jest.js", "--runInBand", "--coverage", "false"],
https://github.com/facebook/jest/issues/3750
另外,如果您遇到有关 jest 配置的另一个错误,请添加参数-c:
"args": [
"--runInBand",
"-c", "${workspaceFolder}/package/jest.config.js",
],
Run Code Online (Sandbox Code Playgroud)
我通过安装 ts-jest 并在launch.json.
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
},
Run Code Online (Sandbox Code Playgroud)
来源。
| 归档时间: |
|
| 查看次数: |
2821 次 |
| 最近记录: |