Nativescript 测试 - TypeScript 编译中缺少 tests/example.ts

Nativescript testing - tests/example.ts is missing from the TypeScript compilation

我有一个 Angular 风格的 Nativescript 项目。

按照 https://docs.nativescript.org/tooling/testing/testing 中的步骤进行操作后,我遇到了以下错误:

ERROR in ./src/tests/example.ts Module build failed (from ../node_modules/@ngtools/webpack/src/index.js): Error: /home/..../src/tests/example.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

我做的步骤:

  1. tns test init - 进入茉莉花
  2. npm i @types/jasmine --save-dev
  3. 启动了我的 android 模拟器
  4. tns run android

您可以看到生成的示例测试文件不起作用,但我没有在网站上阅读有关修改 tsconfig.json 的任何内容。

一个可能的解决方案是...完全按照错误消息所说的去做。

插入后:

"include": ["src/tests/**/*.ts"]

tsconfig.json(或tsconfig.tns.json),测试运行没有问题。

虽然我认为这意味着这个文件会包含在每个构建中(不仅仅是测试 运行s),所以还不是最好的解决方案。仅在 tsconfig.spec.json 中包含此行也无济于事,看来我必须为生产准备一个不包含此行的不同版本。