Test Driven Node.JS Development

What would a language and framework be with unit testing, BDD, and other testing methods, frameworks and systems?

So once you get beyond casual Node.JS development, you will need to start unit testing.  Node.js has a surprisingly robust and mature set of testing tools and options.  Out of the box, Node.js has Built In Assert which will let you do some basic XUnit style tests.   A step beyond that is NodeUnit, which is pretty easy to use for XUnit oriented people.  For me, it’s easy to pick up coming from doing a lot of JUnit tests.  This article is great for Using NodeUnit for Testing.  Node.js is great because so many people have developed tools, frameworks and utilities for it.  The only issue I have it some are not very mature and the options are so fragmented.  There’s no Spring framework or hibernate that garners massive usage.  So many variations and options, I wish they could work together to put together a killer Rails or Spring type group of mature, tested, interconnected tools and utilities.  Full Testing Suite – Mocha is installable via NPM and works with a CI server.  This one is pretty cool.

The source for everything testing/bdd/mocking for Node.JS is Joyent’s Testing Wiki.
There’s a number of behavior driven development tools including the polyglot tool Cucumber -> BDD Testing Tool – Cucumber.JS.  Another option is Asynchronous BDD Testing Tool – Vow.
For mocking,  Mockito Style Mock Objects – Mary Jane, looks great.   I will hope that maybe Mockito will officially support this one.
For JQuery fans, someone has ported QUnit to Node.JS [Node-Qunit]
This is just a sampling of test options.  Obviously tools like Selenium and Firebug will help you and so would JMeter and and SOAPUI.  A lot of general web testing tools are available that can do full system testing or integration testing for your Node.JS web apps.
I will be adding some examples in a future post with a github link.

Ehcache + Hibernate / JPA and TomEE

Ehcache + Hibernate and/or JPA
OpenJEE / TomEE

Spring / HTML5 / Flex

Spring Remoting
FLEX for Spring
Spring BlazeDS Integration
HTML5
Mobile First Responsive Web Design
Application Cache

Node.js and JavaScript Links

OAuth for Node.jS
Backbone hackers guide
Realtime multiplayer game in html5
Nodebots
Cloud Control Hosting
Deploy Node.JS to Staging
HALLOJS Editor
Mod Player
Node.JS Stack Trace
JavaScript Terminal
JavaScript Test Runner

Nodejitsu

Nodejitsu is another Node.js PAAS that offers a free plan.  The free plan is shared hosting through Joyent.  The performance of NodeJitsu’s free plan is very good, especially considering it’s free.  To start sign up on NodeJitsu’s site with the free plan and then follow the Getting Started instructions.  It was a very quick process on Windows.  You can use either their command line, Node.JS based jitsu tool, use the admin web site or use the HTTP API.

Executing the basic jitsu command will show you the following information:

G:>jitsu
info: Welcome to Nodejitsu
info: It worked if it ends with Nodejitsu ok
info: Executing command
help: ___ __
help: / / / /_ / /
help: __/ / / __/ /__/
help:
help: Flawless deployment of Node.js apps to the cloud
help: open-source and fully customizable.
help: https://github.com/nodejitsu/jitsu
help:
help: Usage:
help:
help: jitsu <resource> <action> <param1> <param2> ...
help:
help: Common Commands:
help:
help: To sign up for Nodejitsu
help: jitsu signup
help:
help: To log into Nodejitsu
help: jitsu login
help:
help: To install a pre-built application
help: jitsu install
help:
help: Deploys current path to Nodejitsu
help: jitsu deploy
help:
help: Lists all applications for the current user
help: jitsu list
help:
help: Additional Commands
help: jitsu apps
help: jitsu logs
help: jitsu env
help: jitsu conf
help: jitsu users
help: jitsu databases
help: jitsu snapshots
help: jitsu logout
help:
help: Options:
help: --version, -v print jitsu version and exit
[string]
help: --localconf search for .jitsuconf file in ./ and then parent dir
ectories [string]
help: --jitsuconf, -j specify file to load configuration from
[string]
help: --noanalyze skip require-analyzer: do not attempt to dynamically
detect dependencies [boolean]
help: --colors --no-colors will disable output coloring
[boolean] [default: true]
help: --release, -r specify release version number or semantic increment
(build, patch, minor, major) [string]
help: --raw jitsu will only output line-delimited raw JSON ( use
ful for piping ) [boolean]
info: Nodejitsu ok

To add a MongoDB NoSQL Database is really simple!

jitsu databases create mongo myMongo
info: Welcome to Nodejitsu tspannnodejs
info: It worked if it ends with Nodejitsu ok
info: Executing command databases create mongo myMongo
info: A new mongo has been created
data: Database Type: mongo
data: Database Name: myMongo
data: Connection url: mongodb://nodejitsu:c23948239348239482934@st
aff.mongohq.com:10064/nodejitsudb684248241564
info: Nodejitsu ok

To create your first test app, you can install their demo Hello World application as follows:

jitsu install helloworld
Directory of paasnodejitsuhelloworld
07/20/2012 12:41 PM <DIR> node_modules
07/20/2012 12:41 PM 1,015 package.json
07/20/2012 12:41 PM <DIR> bin
07/20/2012 12:41 PM 1,534 ReadMe.md
2 File(s) 2,549 bytes
4 Dir(s) 2,900,639,744 bytes free
cd helloworld
jitsu deploy
info: Welcome to Nodejitsu tspannnodejs
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
warn:
warn: Your package.json file is missing required fields:
warn:
warn: subdomain
warn:
warn: Prompting user for required fields.
warn: Press ^C at any time to quit.
warn:
prompt: subdomain: (tspannnodejs.helloworld)
warn: About to write G:paasnodejitsuhelloworldpackage.json
data:
data: {
data: contributors: [
data: { name: 'Marak Squires', email: 'marak.squires@gmail.com' },
data: { name: 'Joshua Holbrook', email: 'josh.holbrook@gmail.com' }
data: ],
data: dependencies: {},
data: repository: { type: 'git', url: 'git://github.com/nodeapps/hellowor
ld.git' },
data: bugs: { url: 'https://github.com/nodeapps/helloworld/issues' },
data: subdomain: 'tspannnodejs.helloworld',
data: engines: { node: '>=0.4' },
data: optionalDependencies: {},
data: analyze: false,
data: name: 'nodeapps-helloworld',
data: devDependencies: {},
data: scripts: { start: 'node ./bin/server' },
data: author: { name: 'Nodejitsu Inc.', email: 'support@nodejitsu.com' },
data: main: '',
data: description: 'a very basic node.js helloworld application',
data: homepage: 'http://nodeapps.github.com/helloworld',
data: version: '0.2.0',
data: licenses: [
data: { type: 'MIT', url: 'https://github.com/nodeapps/helloworld/raw
/master/LICENSE' }
data: ],
data: keywords: [ 'nodeapps', 'helloworld' ]
data: }
data:
prompt: Is this ok?: (yes) yes
info: Skipping require-analyzer because noanalyze option is set
info: Checking app availability nodeapps-helloworld
info: Creating app nodeapps-helloworld
info: Creating snapshot 0.2.0
info: Updating app nodeapps-helloworld
info: Activating snapshot 0.2.0 for nodeapps-helloworld
info: Starting app nodeapps-helloworld
info: App nodeapps-helloworld is now started
info: http://tspannnodejs.helloworld.jit.su on Port 80
info: Nodejitsu ok

 

You can see the deployed application here.

This NYC Node.js PAAS is very performant with a fast easy to use tool.  I am liking them so far.  They are also very Node.JS oriented, being the only of the PAAS vendors to use Node.JS for their command line tool.

They have also developed the very interesting FlatIron Framework, which I will be looking at next.

 

 

 

 

 

 

Nodester Node.JS + Express + Mongo App Part 1 – Nodester

The Running Node.JS Application on a Nodester

 

I am still working on putting up a full application for the tutorial.  Also I will try the same application on Nodejitsu, CloudFoundry and Heroku.

The following are the basic steps for working with Nodester. It is very similiar to all the other command-line PaaS interfaces. I am running this on
Windows, but it will work in most environments.

 

npm install nodester-cli -g
nodester user setup <username> <password>
nodester user setkey c:.sshid_rsa.pub
nodester app create <appname>
nodester app init <appname>
nodester npm install express
nodester npm install mongoose
nodester npm install socket.io

git add .
git commit -am "Ready to deploy"
git push nodester master

nodester app info
nodester app stop|start|restart
nodester app logs

For nodester they push to master for Nodester to get a new build.

Log into your Application List Page on the Administration Site for Nodester and you will see your newly added Application. Nodester has a good help system that will be useful to you while learning. The git commands are standard GIT which makes using all the cloud systems pretty similiar.

After uploading, I check the logs for errors:

nodester app logs
nodester info Showing logs for: rollerderby
New PID: 18884
chroot_runner
chroot_runner
Spawing /app/server.js
Running node v-0.8.1
:: nodester ::

App listening on port 19885

nodester info ok!

nodester deployed

 

I used there out of the box example and added a connection to my test mongo db database at MongoLab.

 

Link Section:

The final deployed application from this tutorial

http://blog.nodester.com/post/3634535277/running-websockets-on-nodester

http://blog.nodester.com/post/19902515151/tips-for-windows-users

http://blog.nodester.com/

https://github.com/nodester/nodester/wiki/

Restify with Mongodb and Mongoose (src)

Backbone.js Boilerplate

Node.JS Mongodb Native Driver

Mongoose Driver

Mongoose Tutorial

Node.JS and Mongodb Video Tutorial

Node.JS / Mongodb / Mongoose Tutorial

Finding Documents in MongoDB with Mongoose

Node.js Tutorial

Restful API with Node.js and Mongodb + Expresss & Mongoose

Backbone.js Fundamentals

Mongoose Model Definition