[英]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.