Setting up test scripts in package.json

Before we run the test, we're going to set up the scripts, just like we did in the test section. We're going to have two: test, which just runs the tests; and test-watch, which runs the test script through nodemon. This means that any time we change our app, the tests will rerun.

Right in test, we'll be running mocha, and the only other argument we need to provide is the globbing pattern for the test files. We're going to fetch everything in the server directory, which could be in a subdirectory (which it will be later), so we'll use two stars (**). It can have any file name, as long as it ends with the .test.js extension.

"scripts": {
  "test": "mocha server/**/*.test.js",
  "test-watch":
},

Now for

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.