HTML and CSS Reference
In-Depth Information
I named the project “chapp,” as in “chat app.” The deps directory is for third
party dependencies; the other two should be self-explanatory.
14.1.1.2 Testing Framework
Node has a CommonJS compliant Assert module, but in line with the low-level
focus of Node, it only provides a few assertions. No test runner, no test cases, and
no high-level testing utilities; just the bare knuckles assertions, enabling framework
authors to build their own.
For this chapter we will be using a version of a small testing framework called
Nodeunit. Nodeunit was originally designed to look like QUnit, jQuery's unit testing
framework. I have added some bells and whistles to it to bring it slightly closer to
JsTestDriver in style, so testing with it should look familiar.
The version of Nodeunit used for this chapter can be downloaded from the
book's website, 3 and should live in deps/nodeunit . Listing 14.2 shows a small
script to help run tests. Save it in ./run _ tests and make it executable with
chmod +x run _ tests .
Listing 14.2 Script to run tests
#!/usr/local/bin/node
require.paths.push( __ dirname);
require.paths.push( __ dirname + "/deps");
require.paths.push( __ dirname + "/lib");
require("nodeunit").testrunner.run(["test/chapp"]);
14.1.2 Starting Point
There's a lot of code ahead of us, and to get us started I will provide a basic starting
point, consisting of a small HTTP server and a convenient script to start it. We will
then proceed top-down, actually taking the server for a spin halfway.
14.1.2.1 The Server
To create an HTTP server in Node we need the http module and its create-
Server method. This method accepts a function, which will be attached as a
request listener . CommonJS modules will be properly introduced in a moment,
3. http://tddjs.com
 
Search WWH ::




Custom Search