User:Hashar/cli-js

Note taking mostly. Do not quote me on this stuff!

This page covers installing nodejs and qunit port under Mac OS X and GNU/Linux Debian.

new node-qunitEdit

qunit-port is being refactored under github branch 'refactoring'. This include the original QUnit source code but require unstable NodeJS version > 0.5

Possible node modules prerequisites:

  • argsparser
  • bunker
  • cli-table
  • chainer
  • underscore
  • tracejs
  • jsdom
  • jquery

With home brew, to install them globally with all dependencies use:

$ npm-g install argsparser bunker cli-table chainer underscore tracejs jsdom jquery

More prerequisites might be needed.

nodejs 0.5.9 (homebrew)Edit

As of October 18th, homebrew does not ship a NodeJS 0.5 version which is unstable.

NodeJS 0.5.7 and 0.5.8 is missing child_process.fork on Mac OS X 10.7.

You have to add a node-unstable node-unstable formula for this. The provided version come from a Github commit in bramswenson/homebrew fork. I have manually updated it to install version v0.5.9, thus you can add it to your homebrew formula with the command:

Grab the formula from github at https://gist.github.com/1295768 and add it as node-unstable.rb in your brew directory. You will then be able to install NodeJS 0.5.9. Then install that NodeJS using the downloaded formula:

$ brew install node-unstable

Note: you might want to uninstall the previous, stable, node installation with 'brew uninstall node'.

Once installed, make sure you have a v0.5.x node installed:

$ node --version
v0.5.9
$

Mac OS X installEdit

prerequisitesEdit

Install language interpreters python 2.7 and node.js. On a Mac OS X Computer, it will be with the port command (see MacPorts):

$ sudo port install python2.7
$ sudo port install node  # got me node 0.4.8

Then install "Node Package Manager" (npm) with a small risk of getting hacked in the way:

# curl http://npmjs.org/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3874  100  3874    0     0   8970      0 --:--:-- --:--:-- --:--:-- 13451
fetching: http://registry.npmjs.org/npm/-/npm-1.0.6.tgz
/tmp/npm.50407/package
0.4.8
1.0.6
prefix=/opt/local

This script will find and eliminate any shims, symbolic
links, and other cruft that was installed by npm 0.x.

Is this OK? enter 'yes' or 'no' 
yes  <--- enter 'yes' and press return :)

All clean!
! [ -d .git ] || git submodule update --init
node cli.js cache clean
node cli.js rm npm -g -f --loglevel error
node cli.js install -g -f
/opt/local/bin/npm -> /opt/local/lib/node_modules/npm/bin/npm.js
node-uuid@1.1.0 /opt/local/lib/node_modules/npm/node_modules/node-uuid
npm@1.0.6 /opt/local/lib/node_modules/npm
It worked
#

Then install node-qunit ( https://github.com/kof/node-qunit ) using the node package manager:

$ sudo npm install qunit

> qunit@0.1.5 install ~/node_modules/qunit
> make install

  ... output of ./configure && make && make install

argsparser@0.0.5 ./node_modules/qunit/node_modules/argsparser
uglify-js@1.0.2 ./node_modules/qunit/node_modules/sharedjs/node_modules/uglify-js
sharedjs@0.0.2 ./node_modules/qunit/node_modules/sharedjs
qunit@0.1.5 ./node_modules/qunit

setup profile and check installationEdit

You should have something like:


$ sudo npm list
/path/to/home
└─┬ qunit@0.1.5 
  ├── argsparser@0.0.5 
  └─┬ sharedjs@0.0.2 
    └── uglify-js@1.0.2 
$

NPM actually install the requested modules under /path/to/home/node_modules/ and then use a symbolic link to publish the binary. The folder can be found by using npm bin:

$ npm bin
/path/to/home/node_modules/.bin
$

You might want to append that binary path to your PATH environment variable:

# node.js
NODE_PATH="/Users/hashar/node_modules"
export PATH=$PATH:"$NODE_PATH/.bin"

At this step, you should be ready to run qunit :

$ which qunit
/path/to/home/node_modules/.bin/qunit
$ qunit -h

Usage: cli [options] value (boolean value can be used)

...

Please use the -h switch when invoking qunit or it might just throw an exception.

Mac OS X (with homebrew)Edit

$ brew install node
$ brew install npm

Make sure to update your NODE_PATH env variable in your .bashrc. Brew use /usr/local as a prefix, so you should add:

export NODE_PATH="/usr/local/lib/node_modules"

Then install the node module globally with npm-g (alias set up by homebrew):

$ npm-g install qunit

This will install the stable version. As of October 18th 2011, this mean using an outdated QUnit port which do not support stop(timeout) method.


GNU/Linux (Debian)Edit

As of July 2011, you have to use unstable release to install node and npm. You can backport unstable packages in your testing release by adding unstable in your /etc/apt/sources.list and updating your /etc/apt/preferences:

/etc/apt/sources.list

# Please note the URL http://ftp.free.fr/mirrors/ftp.debian.org/ might be different
# for your local setup. The important thing is adding a line with 'unstable' :)
 
# Testing source list:
deb http://ftp.free.fr/mirrors/ftp.debian.org/ testing main contrib non-free
# Unstable source list:
deb http://ftp.free.fr/mirrors/ftp.debian.org/ unstable main contrib non-free

/etc/apt/preferences

Package: *
Pin: release a=testing
Pin-Priority: 900

Package: *
Pin: release o=debian
Pin-Priority: -10

Then update using apt-get update and install the package with the target unstable:

 $ apt-get install -t unstable nodejs npm

Debian should take care of everything for you. Then install qunit:

$ npm install qunit
 <snip>
$

Debian install symbolic links in your ~/bin . Make sure it is in your PATH. You will end up with something like:

$ ls -l ~/bin/qunit*
lrwxrwxrwx 1 hashar hashar  13 16 juil. 19:46 /home/hashar/bin/qunit -> ./qunit@0.1.5*
-rwxr-xr-x 1 hashar hashar 708 16 juil. 19:46 /home/hashar/bin/qunit@0.1.5*
$

Jquery and DOMEdit

Install Jquery and a javascript DOM for node is really easy, using the Node Package Manager of course!

jQuery for node:

$ npm install jquery
htmlparser@1.7.3 ./node_modules/jquery/node_modules/htmlparser
mjsunit.runner@0.1.3 ./node_modules/jquery/node_modules/jsdom/node_modules/mjsunit.runner
request@1.9.5 ./node_modules/jquery/node_modules/jsdom/node_modules/request
jsdom@0.1.20 ./node_modules/jquery/node_modules/jsdom
jquery@1.5.1 ./node_modules/jquery
$

DOM in node:

$ npm install jsdom
request@1.9.5 ./node_modules/jsdom/node_modules/request
htmlparser@1.7.3 ./node_modules/jsdom/node_modules/htmlparser
jsdom@0.2.0 ./node_modules/jsdom
$

Verifying installEdit

We will do the first node run and verify jQuery and DOM seems fine.

Create a JavaScript file with the following content (From https://github.com/coolaj86/node-jquery) :

var jsdom = require( 'jsdom' ).jsdom,
    newWindow = jsdom().createWindow(),
    $ = require( 'jquery' ),
    jQuery = require( 'jquery' ).create( newWindow );

$("<h1>test passes</h1>").appendTo("body");
console.log( $("body").html()  )

Then run the above code using node:

$ node qunit_start.js 
<h1>test passes</h1>
$

Congratulations! You have everything needed :-)