node.js - 在 typescript 节点项目中使用 monorepo 样式测试目录时,ts-jest 找不到类型信息
问题描述
我使用references
andcomposite
设置分离了 jest 的测试类型和项目的类型。但是 ts-jest 无法在测试文件中找到类型信息并引发多个错误,例如:error TS2304: Cannot find name 'expect'
.
这是目录结构:
.
├── package.json
├── src
│ └── index.ts
├── tests
│ ├── index.test.ts
│ └── tsconfig.json
├── tsconfig.json
tsconfig.json
:
{
"compilerOptions": {
"composite": true,
},
"include": ["src"]
}
tests/tsconfig.json
:
{
"extends": "../tsconfig.json",
"references": [
{
"name": "my-lib",
"path": ".."
}
],
"compilerOptions": {
"types": ["jest"],
"rootDir": "..",
"noEmit": true
},
"include": ["."]
}
package.json
:
{
"jest": {
"preset": "ts-jest",
"environment": "node"
}
}
如何将 ts-jest 集成到这样的项目中?
解决方案
更新 jest 配置以准确定义 tsconfig 文件ts-jest
:
package.json
{
"jest": {
"preset": "ts-jest",
"environment": "node",
"globals": {
"ts-jest": {
"tsconfig": "./tests/tsconfig.json"
}
}
}
}
推荐阅读
- node.js - 无法从命令行运行 clasp
- sql-server - 如何在 VARCHAR(MAX) 中的 SQL Server 中的两个已知字符串之间选择可变长度字符串,其中某些列没有适用的字符串
- javascript - RegExp for Postal Code, faster/better way?
- ios - Swift:复制/粘贴特定字段的启用和禁用
- java - 让 maven surefire 在存在 module-info.java 文件的类路径上运行
- d3.js - D3 - 将 y 轴标签移到线上
- java - Java中的空检查是否需要大量时间?
- reactjs - React BarChart 使用 D3 可滚动 X 轴
- python - 将函数和颤动结果绘制到相同的图形问题
- python - 使用 python 编程不和谐 BOT 时出现超级错误