2

I work on an AngularJS 1.6.X ES6 application. I use Mocha and Sinon to write and run unit tests on it.

I started to hybrid/upgrade this application with ngUpgrade in order to write the new components in angular. So now, I got some angularJS modules and some angular modules. I use @angular-builders/custom-webpack with babel-loader and ng-annotate-loader to properly load the AngularJS modules.

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. Ideally, I would also like to have a common code coverage report for AngularJS and angular modules.

Is it possible to do it with angular-cli ng test? Which Karma configuration do you recommend?

Lin Du
  • 88,126
  • 95
  • 281
  • 483
Steph
  • 21
  • 4

1 Answers1

1

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 CLI introduced something called "builders" which allows you to replace the core CLI commands with your own functionality.

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>. These targets are defined in your angular.json file and are coded in a JavaScript file. You can then map the built in target ng test to a custom target to replace the built it one.

The above article gives an example for replacing ng test with a custom tester.

Reactgular
  • 52,335
  • 19
  • 158
  • 208