As far as I understand,
you'd like to run your local server, once the server is up tests cycle should be triggered.
I suggest to use the package "start-server-and-test" sounds suite for your solution, the NPM package page is here
Let's take your current package.json
script object, and rewrite them.
The start and test scripts are the two basic scripts you need to maintain your app easily.
start - to start your app (I suggest to use nodemon or pm2)
test - call your test script
Notes:
- To dev tests you will need to handle two terminals, each for the above.
- I'm assuming you're running on port 8080
- The package is also handling the termination of both processes (node and mocha) in both cases success and failure so no need (
posttest:ci
, --exit
, etc..)
- There is no need to use child process (the
&
) that mentioned at the end of your web-server
package.json
's script.
Here is the new script object, from my POV
"scripts": {
"start": "node app.js",
"test": "NODE_ENV=test mocha ./tests/functional/*.js",
"test:ci": "NODE_ENV=test start-server-and-test start \"http://localhost:8080\" test"
}
Now, from your CLI:
npm run test:ci
The ci
suffix mentions this process is fully automated
It's expected that you'll have to define CI=true for a real CI environment,
just as all CI tools do and it's not necessary for local usage.
&
, maybe sleep abitnpm run web-server && sleep 2; mocha ..
– Pronouncement