我有一个 TypeScript 项目,并且正在通过ts-jest使用 Jest 进行测试。在 VS Code 中,我安装了插件vscode-jest。调试并不像我想要的那样工作:
- 我可以通过单击
Debug
vscode-jest 生成的 CodeLens来启动调试会话 - 如果我在测试代码中放置断点,调试器将按预期在断点处暂停
- 但是如果我在源代码中设置断点,调试器会忽略它
我想这是因为 ts-jest 的工作方式。可能永远找不到断点,因为测试是在 JS 文件而不是 TS 文件上运行的。
如果我在使用 Create React App 引导的 JS 项目中尝试相同的操作,我可以在源文件中设置断点,调试器将停止。这很有趣,因为这些源文件也正在由 babel 编译......
我想知道是否可以调整我的设置,以便调试器识别源文件中的断点。
在下面发布一些可能相关的文件:
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
}