Server-side unit testing
In the previous example, we saw a way to start and run our test in Mocha. Server-side testing is important, because it helps you to know your code quality, speed, services request, and response time.
Implementing the web server
For a server-side support, we need to implement an HTTP server, which will serve our requests. Follow the points here to add a web server in our application:
Create a subdirectory called
app
with anindex.html
file inside. Leave theindex.html
file blank as of now.Create a file inside the
test
directory namedtestMyapp.js
.Create a file
app.js
to add our application code. Theserverside-testing
application directory structure will now look like this:Before we write any production code, let's write a test that shows your server running status in
testMyapp.js
. First, we need to load the following modules that we need in our tests:var assert = require("chai").assert; var http = require("http");
Note
The
http
module: with the help of this module requests...