javascript - jsconfig 和 jest 不交互以使用相同的根路径
问题描述
我正在构建一个 React 项目,目前在进行测试时遇到问题使用 jsconfig 来使用根路径。
结构是这样的,
├── divjoy-project.json
├── jsconfig.json
├── next.config.js
├── node_modules
├── package.json
├── package-lock.json
├── postcss.config.js
├── public
├── README.md
├── src
├── tailwind.config.js
├── worker
└── yarn.lock
jsconfig 很简单,
{
"compilerOptions": {
"baseUrl": "./src"
}
}
开玩笑的是
"jest": {
"testEnvironment": "node",
"testMatch": [
"**/?(*.)(spec|test).?(m)js?(x)"
],
"rootDir":"./src",
"moduleFileExtensions": [
"js",
"jsx",
"mjs"
],
"transform": {
"^.+\\.m?jsx?$": "babel-jest"
},
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": -10
}
}
},
我也在使用 next.js。谢谢!
解决方案
尝试添加"moduleDirectories": ['node_modules', '<rootDir>']
您的笑话配置。这就是开玩笑找到你的 jsconfig 文件。
就我而言,我有一个 jest.config.js 文件:
module.exports = {
moduleDirectories: ['node_modules', '<rootDir>'],
// other configs
}
我也在使用 next.js,上面的内容对我有用。
推荐阅读
- c++ - 如何构建 libboost_thread_vc100-mt-1_62.lib?
- c# - 如何在 Xamarin Android 上实现 JobScheduler
- spring-boot - 如何在 Spring Boot 中提取用户名和密码?
- javascript - 试图至少存在一个可选参数,但它的存在排除了其他参数
- owl - 如何配置 Protégé 执行封闭世界推理?
- 2sxc - 2SXC Web API - 为 ADAM 资产创建内容项元数据
- java - 如何使用 XPath 从网页中获取某些 Html 元素
- c++ - 关于“if”“elseif”“else”语句的良好做法是什么
- php - 如何以编程方式将 Photoshop 滤镜 Pixelate > Crystallize 应用于图像?
- wpf - 为什么 Point3DCollection 的绑定不起作用?