在typescript源文件中使用ts jest断点的vscode jest
我有一个TypeScript项目,正在使用Jest via进行测试。在VS代码中,我安装了插件。调试没有像我希望的那样正常工作:在typescript源文件中使用ts jest断点的vscode jest,typescript,visual-studio-code,jestjs,vscode-debugger,Typescript,Visual Studio Code,Jestjs,Vscode Debugger,我有一个TypeScript项目,正在使用Jest via进行测试。在VS代码中,我安装了插件。调试没有像我希望的那样正常工作: 我可以通过单击vscode jest生成的DebugCodeLens来启动调试会话 如果我在测试代码中设置断点,调试器将按预期在断点处暂停 但是如果我在源代码中放置断点,调试器将忽略它 我想这是因为玩笑的运作方式。可能从未找到断点,因为测试是在JS文件而不是TS文件上运行的 如果我在用createreact应用程序引导的JS项目中尝试同样的方法,我可以在源文件中设
- 我可以通过单击vscode jest生成的
CodeLens来启动调试会话Debug
- 如果我在测试代码中设置断点,调试器将按预期在断点处暂停
- 但是如果我在源代码中放置断点,调试器将忽略它
jest.config.js
module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
collectCoverage: false,
};
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"sourceMap": true,
"watch": false
},
"include": ["src"],
"compileOnSave": true
}
嗯,我和你的情况一样,但我可以在源代码和测试代码上设置断点。 请注意,即使vscode在源代码上将我的断点标记为“未验证”,它也会在到达断点时正确停止 我将向您传递我的配置: tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"outDir": "build",
"module": "commonjs",
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"suppressImplicitAnyIndexErrors": true,
"removeComments": true,
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noEmitOnError": true,
"typeRoots": [
"./node_modules/@types",
"./types"
],
"lib": [
"es5",
"es6",
"dom",
"scripthost"
],
"traceResolution": false,
"listEmittedFiles": false,
"listFiles": false,
"pretty": true,
},
"exclude": [
"node_modules/**/*.*",
"build/**/*.*"
],
"include": [
"src/**/*.ts",
"test/**/*.test.ts",
"demo/**/*.ts"
],
}
jest.config.js
module.exports = {
globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.jest.json'
},
"__TRANSFORM_HTML__": true
},
moduleFileExtensions: [
'ts',
'js'
],
transform: {
"^.+\\.(ts|html)$": "ts-jest",
"^.+\\.xml$": "<rootDir>/tools/xmlTransformer.js",
},
clearMocks: true,
resetMocks: true,
restoreMocks: true,
collectCoverage: true,
"collectCoverageFrom": [
"**/src/**/*.ts"
],
coverageDirectory: 'coverage',
coverageReporters: [
'lcov'
],
// "coverageThreshold": {
// "global": {
// "branches": 80,
// "functions": 80,
// "lines": 80,
// "statements": 80
// }
// },
testEnvironment: 'jsdom',
testMatch: [
'**/test/unit/**/*.test.ts'
],
setupTestFrameworkScriptFile: 'jest-mock-console/dist/setupTestFramework.js'
};
module.exports={
全球:{
“开玩笑”{
tsconfig文件:“tsconfig.jest.json”
},
“\uuuuuu转换\uuuhtml\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
},
moduleFileExtensions:[
"ts",,
“js”
],
转换:{
“^.+\\(ts | html)$”:“ts笑话”,
“^.+\.xml$”:“/tools/xmlTransformer.js”,
},
clearMocks:没错,
真的,
是的,
报道:是的,
“CollectionCoverage from”:[
“***/src/***.ts”
],
coverage目录:“coverage”,
搬运工:[
“lcov”
],
//“覆盖率阈值”:{
//“全球”:{
//“分支机构”:80,
//“职能”:80,
//“行”:80,
//“声明”:80
// }
// },
测试环境:“jsdom”,
测试匹配:[
“***/test/unit/***.test.ts”
],
SetupTestFrameworkScript文件:“jest模拟控制台/dist/setupTestFramework.js”
};
编辑:如何在调试模式下启动jest?谢谢您的回复。很可能是某个版本的依赖关系导致了我的问题。最近,我已经能够处理好所有的事情。您的编辑询问您如何在调试模式下启动Jest,我的问题是关于vscode Jest的,所以我假设您想知道如何使用此插件进行调试。我只需单击失败测试上出现的“调试”链接即可完成此操作。要启动与vscode jest无关的调试会话,您必须进行launch.json配置并使用该配置启动调试会话。不,我问的是在调试模式下启动jest,只是因为这是您没有指定的唯一一件事,所以我在想jest启动参数中缺少了什么(例如,runInBand param)您使其工作了吗?