Sha*_*aed 4 typescript jestjs visual-studio-code ts-jest
我希望我的打字稿测试在test文件夹与src. 我不希望在构建打字稿项目时转换测试。
我的打字稿节点项目的结构如下:
.
??? server
? ?
? ?
? ??? src
? ? ?
? ? ??? app.ts
? ??? test
? ? ?
? ? ??? app.test.ts
? ??? node_modules/
? ??? package-lock.json
? ??? package.json
? ??? tslint.json
? ??? tsconfig.json
??? front_end/
??? README.md
Run Code Online (Sandbox Code Playgroud)
使用我的 tsconfig:
{
"compilerOptions": {
"baseUrl": ".",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"sourceMap": true,
"strict": true,
"target": "ESNext",
"paths": {
"*": ["node_modules/*"]
}
},
"include": ["src/**/*"]
}
Run Code Online (Sandbox Code Playgroud)
当我导航到 vscode 中的测试文件时,vscode 语言功能无法识别 node_modules 中安装的类型和包。令人惊讶的是,如果我仅在服务器文件夹中打开 vscode(正如您从我的文件夹结构中看到的那样,服务器不是根目录),语言功能将起作用。
测试用于ts-jest运行,因此tsc此处不需要。扩展一个tsconfig.jsonfor 测试会更好吗?
这是可以在设置中修复的东西,还是我应该向https://github.com/microsoft/vscode/issues/new/choose提交错误。
vscode 有一个单根 tsconfig 文件的问题。相邻的test文件夹src将使用 tsconfig(在此拉取请求中添加),但是如果您打开的文件夹是它上面的一个目录(例如,如果您有服务器和客户端文件夹),它将不起作用。此问题正在跟踪解决方案:https : //github.com/Microsoft/vscode/issues/12463。
此外,如果您想升级到 eslint(不推荐使用 tslint),如果您希望将 test 文件夹排除在主 tsconfig.txt 中,则打字稿解析器还会强制您将 tsconfig 文件添加到 test 文件夹中。链接到 eslint multi tsconfig 文档。
简单的解决方案是使用两个额外的tsconfigs。一个用于 linter tsconfig.eslint.json,一个用于文件夹内的测试test:test/tsconfig.json具有以下内容:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["./**/*"]
}
Run Code Online (Sandbox Code Playgroud)
不优雅,但目前不存在更好的解决方案。
| 归档时间: |
|
| 查看次数: |
1298 次 |
| 最近记录: |