[英]is it possible to run angularJS unit tests with angular-cli `ng test`?
I work on an AngularJS 1.6.X ES6 application. 我在AngularJS 1.6.X ES6应用程序上工作。 I use Mocha and Sinon to write and run unit tests on it.
我使用Mocha和Sinon在其上编写和运行单元测试。
I started to hybrid/upgrade this application with ngUpgrade in order to write the new components in angular. 我开始使用ngUpgrade混合/升级此应用程序,以便以角度编写新组件。 So now, I got some angularJS modules and some angular modules.
所以现在,我得到了一些angularJS模块和一些angular模块。 I use
@angular-builders/custom-webpack
with babel-loader
and ng-annotate-loader
to properly load the AngularJS modules. 我将
@angular-builders/custom-webpack
与babel-loader
和ng-annotate-loader
一起使用以正确加载AngularJS模块。
I want to run the existing unit tests of the AngularJS modules at the same time as the unit tests of the new angular modules. 我想与新的angular模块的单元测试同时运行AngularJS模块的现有单元测试。 Ideally, I would also like to have a common code coverage report for AngularJS and angular modules.
理想情况下,我还希望有一个针对AngularJS和angular模块的通用代码覆盖率报告。
Is it possible to do it with angular-cli ng test
? 可以使用角度倾斜
ng test
吗? Which Karma configuration do you recommend? 您推荐哪种业力配置?
Is it possible to do it with angular-cli ng test?
可以使用角度倾斜测试吗?
Yes, I think so. 是的,我想是这样。 If you are running Angular 6 or higher, but I have not tried this myself.
如果您运行的是Angular 6或更高版本,但我自己没有尝试过。
Angular CLI introduced something called "builders" which allows you to replace the core CLI commands with your own functionality. Angular CLI引入了一个称为“ builders”的东西,它允许您用自己的功能替换核心CLI命令。
https://medium.com/dailyjs/angular-cli-6-under-the-hood-builders-demystified-f0690ebcf01 https://medium.com/dailyjs/angular-cli-6-under-the-hood-builders-demystified-f0690ebcf01
Basically, you can define your own ng run <target>
targets that work similuar to npm run <script>
. 基本上,您可以定义自己的
ng run <target>
目标,这些目标的工作方式类似于npm run <script>
。 These targets are defined in your angular.json
file and are coded in a JavaScript file. 这些目标在您的
angular.json
文件中定义,并在JavaScript文件中编码。 You can then map the built in target ng test
to a custom target to replace the built it one. 然后,您可以将内置目标
ng test
映射到自定义目标,以替换内置目标。
The above article gives an example for replacing ng test
with a custom tester. 上面的文章提供了一个用自定义测试仪替换
ng test
的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.