Advanced Node.js Development
上QQ阅读APP看书,第一时间看更新

Installing npm modules for testing POST /todos route

Now before we can do any of this, we have to install all of those modules we installed in the test section, expect for assertions, mocha for the entire test suite, supertest to test our Express routes, and nodemon. The nodemon module is going to let us create that test-watch script we had, so we can automatically restart the test suite. Now I know you have nodemon installed globally, but since we are using it inside of a package.json script, it's a great idea to install it locally as well.

We're going to run npm i with expect version 22.3.0, the most recent. Next up is going to be mocha. The most recent version is 5.0.1. After that is nodemon version 1.15.0, and last but not least is supertest at version 3.0.0. With this in place, all we have to do is tack on that --save-dev flag. We want to save these, but not as regular dependencies. They're for testing purposes only, so we're going to save them as devDependencies:

npm i expect@22.3.0 mocha@5.0.1 nodemon@1.15.0 supertest@3.0.0 --save-dev

Now, we can go ahead and run this command, and once it's done we'll be able to start setting up the test files inside of Atom.