简体   繁体   English

如何在 Angular CLI 管理的项目中配置 test.ts 的路径

[英]How to configure the path to test.ts in Angular CLI managed project

I've used swagger code gen with typescript-angular to generate an API client from a swagger v3 file.我使用带有 typescript-angular 的 swagger code gen 从 swagger v3 文件生成 API 客户端。 This is really nice, fast, and easy;这真的很好,又快又容易; however, I think the output organization is a little dated or incomplete.但是,我认为 output 组织有点过时或不完整。 There are no boilerplate tests or spec files, and I want to create tests.没有样板测试或规范文件,我想创建测试。

So, as a comparison, when I use Angular CLI to generate a new library, I can see that the root workspace has an angular.json that points to multiple projects in my workspace including my newly created library and other Angular apps.因此,作为比较,当我使用 Angular CLI 生成新库时,我可以看到根工作区有一个 angular.json,它指向我工作区中的多个项目,包括我新创建的库和其他 Angular 应用程序。 Each has a test.ts in the projects/[library]/src folder, which is required by karma.conf.js and assumably used by ng when starting up tests.每个在 projects/[library]/src 文件夹中都有一个 test.ts,这是 karma.conf.js 所必需的,并且可能在启动测试时由 ng 使用。 My swagger generated api doesn't have this file, but I can replicate it manually.我的swagger生成的api没有这个文件,不过我可以手动复制。 Still, when I run ng test @mycompany/my-api I get an error saying `Error: ENOENT: no such file or directory, open /my-workspace/projects/my-api/api/test.js.不过,当我运行ng test @mycompany/my-api时,我收到一条错误消息,提示“错误:ENOENT:没有这样的文件或目录,打开/my-workspace/projects/my-api/api/test.js。 Notice the generated code and project structures is like./my-api/ api /test.js instead of the typical ng generated, ./my-lib/src/test.ts请注意,生成的代码和项目结构类似于./my-api/ api /test.js 而不是典型的 ng 生成的 ./my-lib/src/test.ts

I can see also that the root workspace has an angular.json, which specifies locations of those test.ts files like so:我还可以看到根工作区有一个 angular.json,它指定了这些 test.ts 文件的位置,如下所示:

"test": {
  "builder": "@angular-devkit/build-angular:karma",
  "options": {
    "main": "projects/my-company/my-api/src/test.ts",
    "tsConfig": "projects/my-company/my-api/tsconfig.spec.json",
    "karmaConfig": "projects/my-company/my-api/karma.conf.js"
   }
},

If I change./src/.如果我改变./src/. to./app/.到./app/. to match the structure of the swagger generated code, it has no effect.匹配swagger生成代码的结构,没有效果。

I could re-organize the generated code manually to match what Angular CLI expects, to make it organized exactly like ng generated code, but then I'd create a maintenance nightmare and not be able to easily update with a regenerated API from swagger.我可以手动重新组织生成的代码以匹配 Angular CLI 的预期,使其组织起来与 ng 生成的代码完全一样,但这样我会造成维护噩梦并且无法使用从 swagger 重新生成的 API 轻松更新。

Any idea how I can tell ng to look for the test.ts in the./app/.知道如何告诉 ng 在 ./app/ 中查找 test.ts。 directory instead of the./src/.目录而不是./src/。 directory?目录? Is it an ng thing or a karma configuration thing.它是一个 ng 的东西还是一个业力配置的东西。 I can find no tips or information about this anywhere, so far.到目前为止,我在任何地方都找不到关于此的提示或信息。

It's not an ng or a karma configuration issue, instead I solved it by revising the tsconfig.spec.json, changing src/test.ts to api/test.ts here:这不是 ng 或 karma 配置问题,而是我通过修改 tsconfig.spec.json,将 src/test.ts 更改为 api/test.ts 来解决它:

"files": [
  "api/test.ts"
],

I've no idea what that angular.json path affects, but I also set that to match the true location as well, but it seemingly has no effect.我不知道 angular.json 路径会影响什么,但我也将其设置为也匹配真实位置,但它似乎没有效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何覆盖 Angular 项目中的 test.ts 文件 - How to cover the test.ts file in an Angular project 运行ng测试时如何解决test.ts? - How to resolve test.ts when running ng test? Angular 6单元测试:如何使用test.ts进行业力测试 - Angular 6 Unit testing : how to use test.ts for running karma tests 迁移到 Angular 15 后,上下文从 test.ts 中删除 - After migration to Angular 15, context was removed from test.ts 从angular4升级到角度5后,npm测试失败“TypeScript编译中缺少test.ts” - npm test fails after upgrade from angular4 to angular 5 “test.ts is missing from the TypeScript compilation” angular - ReferenceError:在http:// localhost:9877src / test.ts中找不到变量:URLSearchParams - angular - ReferenceError: Can't find variable: URLSearchParams in http://localhost:9877src/test.ts 如何配置 Angular-CLI 生成的项目以包含 SharedWorker - How to configure Angular-CLI-generated project to include a SharedWorker 如何在 Angular 8 项目中为 angular CLI 配置自定义 webpack? - How to configure a custom webpack for angular CLI in Angular 8 project? 如何为rc5配置angular-cli项目? - how to configure angular-cli project for rc5? 正则表达式:所有以.ts结尾且没有单词index.ts和test.ts的字符串 - Regex: All strings that finishes with .ts and does not have the word index.ts and test.ts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM