I've been using Angular/CLI from within the context of VS Code.
From the Terminal prompt within VS Code one can invoke ng serve or ng test -- but is there a way to combine the two (eg: something like ng serve test) so that as I TDD, and develop tests first, I see the Terminal show failed tests, then go green as i write code to meet the tests, AND see the web page results on another screen?
Thanks!
There are 2 solutions that I know of for this issue:
ng serveng testI tried with VS Code terminals, and traditional windows cmd terminals. It works but it is very limited and implies much visual pollution.
You may use an npm package called npm-run-all. This package helps you running multiple npm tasks in parallel or sequentially.
Just run
npm install --save-dev npm-run-all
This shall install npm-run-all in the dev dependencies of your project.
npm-run-all has 2 modes:
run-p: runs multiple tasks in parallelrun-s: runs multiple tasks sequentiallyIn the package.json file of your project, in the script section, you may now add:
"scripts": {
...
"tdd": "run-p \"start\" \"test\"",
"verify": "run-s \"test -- --watch=false\" \"lint\"",
...
},
You may call the tasks anything you want. I just named the dev task tdd to be more explicit on my intent.
Note: You may also use another npm package called concurrently, but i'm not sure it has the run sequentially mode.
This solution is distributable: every developper is now able to perform a npm install on your project and run task tdd (or whatever you want to call it). Moreover, you may also create task to be ran in a build factory. This alows your project to be integrated in a dev-ops context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With