问题描述
这个问题类似于这个问题:如何使用不同的tsconfig用于测试的文件?但我要的是 Visual Studio 代码.
This question is similar to this question: How to use different tsconfig file for tests? But I am asking for visual studio code.
我有两个 tsconfig
文件:
tsconfig.json
适用于所有应用程序文件tsconfig.test.json
用于所有测试文件
tsconfig.json
for all application filestsconfig.test.json
for all test files
tsconfig.json
排除所有 *.spec.ts
而 tsconfig.test.json
只包括这些文件.
tsconfig.json
excludes all *.spec.ts
while tsconfig.test.json
only includes these files.
如何让visual studio代码理解打开的.spec.ts
文件属于tsconfig.test.json
?
How can I make visual studio code to understand that an opened .spec.ts
file belongs to tsconfig.test.json
?
我不想将我的所有测试分开到自己的 test
目录中,并包含自己的 tsconfig.json
而是将它们放在应用程序文件旁边.
I dont want to separate all my tests into an own test
directory with its own tsconfig.json
included but rather keep them next to the application files.
推荐答案
VS Code 目前仅限于单个 tsconfig.json
(请参阅:https://github.com/microsoft/vscode/issues/12463).
VS Code has limitation to a single tsconfig.json
for now (see: https://github.com/microsoft/vscode/issues/12463).
考虑到项目结构是:
- src/
- tsconfig.json
- tsconfig.test.json
创建带有内容的 ./src/tsconfig.json
文件:
Create ./src/tsconfig.json
file with content:
{
"extends": "../tsconfig.test.json"
}
这篇关于如何在 vscode 中为测试文件使用不同的 tsconfig 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!