使用 Chrome 调试 Jest 在 Jest 中停止但不在测试调试器语句中停止,如何让它在测试中停止?
Debugging Jest with Chrome stops in Jest but not on test debugger statement, how to make it stop in the test?
我已经调试 Jest 并且 运行 很多次了。出于某种原因,在这个 repo(我是新手)中,调试器将在 jest.js
:
中停止
但不会停留在测试本身。测试:
it('opens the drawer and presses the reset button', async () => {
debugger; // never stops here
console.log('test should have stopped');
我的命令是运行:
✗ node --inspect-brk node_modules/.bin/jest --runInBand -t 'opens the drawer and presses the reset button'
Debugger listening on ws://127.0.0.1:9229/3bb1a020-5ad6-42d5-b485-df8ab89db21b
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
PASS src/components/views/RecommendationPage/FilterDrawer/FilterDrawer.spec.tsx (12.355 s)
● Console
console.log
test should have stopped
at _callee3$ (src/components/views/RecommendationPage/FilterDrawer/FilterDrawer.spec.tsx:217:13)
所以测试肯定是 运行 而 console.log 是 运行 但调试器不会在调试器语句上停止。这个我已经做过好几次了,绝对可以做到。但是这个 repo 中的 Jest 配置有问题。
我最好的猜测是调试器语句以某种方式被删除了。这是我的 jest.config.js:
module.exports = {
preset: 'jest-expo',
clearMocks: true,
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
transform: {
'\.(js|jsx)': 'babel-jest',
},
roots: ['<rootDir>/__mocks__', '<rootDir>/src'],
transformIgnorePatterns: [
'node_modules/@expo/vector-icons/.*\.json',
'node_modules/react-native/.*\.json',
'node_modules/(?!((jest-)?@react-native|react-native|expo-camera|react-native-adapter|react-clone-referenced-element|expo(nent)?|@expo(nent)?/.*|react-native-vector-icons|react-native-vector-icons/.*|react-navigation|react-navigation-redux-helpers|@react-navigation/.*|unimodules-permissions-interface|@expo/vector-icons/.*|@unimodules|@unimodules/.*|jest-expo/.*|@sentry/.*|sentry-expo|native-base|victory-*|ol))',
],
moduleNameMapper: {
'lang/.*\.json': '<rootDir>/__mocks__/EmptyI18nResource',
},
setupFilesAfterEnv: ['./jest.setup.ts', './setupTests.js'],
watchPathIgnorePatterns: ['<rootDir>/node_modules'],
};
这是一款混合 React Native 应用。
有些东西会阻止调试器在该调试器行上停止,但肯定会被命中后 console.log。
我还克隆了 a boilerplate TS React repo 并尝试调试该存储库中的测试。它停在 debugger
没有问题。
我错过了什么?
不是真正的答案,但我想分享最终有效的方法:我用 Webstorm 进行了调试。按照 Jest / Webstorm debugging guide. 我在测试中设置了一个断点,在 Webstorm 中开始调试,瞧,它击中了断点。
我已经调试 Jest 并且 运行 很多次了。出于某种原因,在这个 repo(我是新手)中,调试器将在 jest.js
:
但不会停留在测试本身。测试:
it('opens the drawer and presses the reset button', async () => {
debugger; // never stops here
console.log('test should have stopped');
我的命令是运行:
✗ node --inspect-brk node_modules/.bin/jest --runInBand -t 'opens the drawer and presses the reset button'
Debugger listening on ws://127.0.0.1:9229/3bb1a020-5ad6-42d5-b485-df8ab89db21b
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
PASS src/components/views/RecommendationPage/FilterDrawer/FilterDrawer.spec.tsx (12.355 s)
● Console
console.log
test should have stopped
at _callee3$ (src/components/views/RecommendationPage/FilterDrawer/FilterDrawer.spec.tsx:217:13)
所以测试肯定是 运行 而 console.log 是 运行 但调试器不会在调试器语句上停止。这个我已经做过好几次了,绝对可以做到。但是这个 repo 中的 Jest 配置有问题。
我最好的猜测是调试器语句以某种方式被删除了。这是我的 jest.config.js:
module.exports = {
preset: 'jest-expo',
clearMocks: true,
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
transform: {
'\.(js|jsx)': 'babel-jest',
},
roots: ['<rootDir>/__mocks__', '<rootDir>/src'],
transformIgnorePatterns: [
'node_modules/@expo/vector-icons/.*\.json',
'node_modules/react-native/.*\.json',
'node_modules/(?!((jest-)?@react-native|react-native|expo-camera|react-native-adapter|react-clone-referenced-element|expo(nent)?|@expo(nent)?/.*|react-native-vector-icons|react-native-vector-icons/.*|react-navigation|react-navigation-redux-helpers|@react-navigation/.*|unimodules-permissions-interface|@expo/vector-icons/.*|@unimodules|@unimodules/.*|jest-expo/.*|@sentry/.*|sentry-expo|native-base|victory-*|ol))',
],
moduleNameMapper: {
'lang/.*\.json': '<rootDir>/__mocks__/EmptyI18nResource',
},
setupFilesAfterEnv: ['./jest.setup.ts', './setupTests.js'],
watchPathIgnorePatterns: ['<rootDir>/node_modules'],
};
这是一款混合 React Native 应用。
有些东西会阻止调试器在该调试器行上停止,但肯定会被命中后 console.log。
我还克隆了 a boilerplate TS React repo 并尝试调试该存储库中的测试。它停在 debugger
没有问题。
我错过了什么?
不是真正的答案,但我想分享最终有效的方法:我用 Webstorm 进行了调试。按照 Jest / Webstorm debugging guide. 我在测试中设置了一个断点,在 Webstorm 中开始调试,瞧,它击中了断点。