I checked some NPM libraries to test a webpages or web-services. But all of them expect that the server is already running. Since I want to automate functional testing, how can I setup NPM package in such a way that
- It can start the server
- Test the application
- Stop the server
So that I can test it locally, as well as on online CI tools like travis-ci or circleci.
Case 1: Webservice
I wrote a NPM package which starts nodejs HTTP(s) server. It can be started from command line $stubmatic
. Currently, I use 2 approaches to test it,
- manual : I manually start it from command line. Then run the tests.
- Automatic: I use
exec
module to run a unix command which can start the application and runpkill
command to kill the application. But for this automation, my application need to be installed on testing machine.
Case 2: Website
I have create a NPM package: fast-xml-parser
and created a demo page within the repo so that I can be tested in the browser. To test the demo page, I currently start a local server using http-server
npm package manually. Test the application.
What can be the better way to write automate functional tests for node js applications?
Note:
- I never used task runners like gulp or grunt. So I'm not sure if they can help in this case.
- In case 1, my application starts node js native HTTP server. I'm not using any 3rd party application like
express
currently.