简体   繁体   English

如何在 react18 jest 单元测试中正确调试未转换的源代码?

[英]How to debug unconverted source code correctly in react18 jest unit test?

Environment:react18 source code, win10, node v16.13.1环境:react18源码,win10,node v16.13.1

I'm using jest tests inside the source code to explore the react18 source code,but jest use babel to convert source code, when i debug jest unit test,it will jump to babel's converted code,it is hard to read,我在源代码中使用jest测试来探索react18源代码,但是jest使用babel转换源代码,当我调试jest单元测试时,它会跳转到babel的转换代码,很难阅读,
So I want to ask is there any way to debug on the source code,not the converted code?所以我想问一下有没有办法在源代码上调试,而不是转换后的代码?
for Example:例如: 在此处输入图像描述 when i debug it,it will be converted当我调试它时,它将被转换在此处输入图像描述

Even in some places,It's almost unreadable:甚至在某些地方,它几乎是不可读的: 在此处输入图像描述

i want to debug unconverted source code correctly in react18 jest unit test.我想在 react18 jest 单元测试中正确调试未转换的源代码。

here is my vscode lanuch.json config:这是我的 vscode lanuch.json 配置:

 { "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Jest Current File", "program": "${workspaceFolder}/node_modules/.bin/jest", "args": [ "${fileBasenameNoExtension}", "--config", "./scripts/jest/config.source.js", "--runInBand" ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "env": { "NODE_ENV": "development" }, "windows": { "program": "${workspaceFolder}/node_modules/jest/bin/jest", } } ] }

i found in 'preprocessor.js' file, it contain babel configuration我在 'preprocessor.js' 文件中找到,它包含 babel 配置

在此处输入图像描述

so,we just add global item process.env.JEST_ENABLE_SOURCE_MAPS: inline.所以,我们只需添加全局项 process.env.JEST_ENABLE_SOURCE_MAPS: inline。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM