Adding the test script

Next up is the test script. It first has to set up those environment variables that we're going to be configuring; we'll do that later. For now, all we're going to do is run mocha, passing in the pattern for the files we want to test.

The files we want to test are in that server directory. They could be in any subdirectory, so we'll use **, and the files, regardless of their name, are going to end in test.js:

"scripts": {  "start": "node server/server.js",  "test": "mocha server/**/*.test.js",  "test-watch": "nodemon --exec 'npm test'"},

With this in place, we are done. We can now run our test suite.

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.