【问题标题】:How to use different tsconfig file for test files in vscode?如何在 vscode 中为测试文件使用不同的 tsconfig 文件?
【发布时间】:2019-11-24 10:46:03
【问题描述】:

这个问题和这个问题类似:How to use different tsconfig file for tests? 但是我要的是visual studio代码。

我有两个tsconfig 文件:

  • tsconfig.json 用于所有应用程序文件
  • tsconfig.test.json 用于所有测试文件

tsconfig.json 排除所有*.spec.tstsconfig.test.json 仅包括这些文件。

如何使 Visual Studio 代码了解打开的 .spec.ts 文件属于 tsconfig.test.json

我不想将我所有的测试分离到一个自己的 test 目录中,其中包含自己的 tsconfig.json,而是将它们放在应用程序文件旁边。

【问题讨论】:

标签: typescript visual-studio-code tsconfig


【解决方案1】:

VS Code 目前仅限于单个 tsconfig.json(请参阅:https://github.com/microsoft/vscode/issues/12463)。

考虑项目结构是:

  • src/
  • tsconfig.json
  • tsconfig.test.json

创建./src/tsconfig.json 包含内容的文件:

{
  "extends": "../tsconfig.test.json"
}

【讨论】:

  • 这是否意味着不在 src/ 中测试的文件将使用 src/tsconfig.json ?
  • 是的,不幸的是,根据我的经验,确实如此。这意味着 VS Code 会报告“文件不是 Typescript 项目的一部分”。
猜你喜欢
  • 2019-03-24
  • 2020-05-09
  • 1970-01-01
  • 2021-09-26
  • 2020-01-16
  • 1970-01-01
  • 1970-01-01
  • 2021-09-10
  • 1970-01-01
相关资源
最近更新 更多