I have an Angular 4 application that I'm setting up a build pipeline for. What I would like to do is have the pipeline run ng test
and then once the tests pass then run ng build
Does anyone have an example of how I can do this?
I have an Angular 4 application that I'm setting up a build pipeline for. What I would like to do is have the pipeline run ng test
and then once the tests pass then run ng build
Does anyone have an example of how I can do this?
inside your package.json you can create a custom script.
"scripts": {
"build": "ng build",
"test": "ng test --single-run",
"ci": "npm run test && npm run build"
},
then just run
npm run ci
To add to the other answers: As of Angular 6 --single-run
no longer works, but you should use this instead:
--watch=false
It is described here:
Tests will execute after a build is executed via Karma, and it will automatically watch your files for changes. You can run tests a single time via --watch=false.
So now you need to do:
ng test --watch=false && ng build
ng test --single-run && ng build
Explanation:
ng test --single-run
.&&
to indicate that the next command should only run on successful exit status.ng build
.This should work for both Windows and Linux systems...