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.

prerequisites
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:

% 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
 * 1) curl http://npmjs.org/install.sh | sh

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 installation
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 /path/to/home/node_modules/.bin $

You might want to append that binary path to your PATH environment variable: NODE_PATH="/Users/hashar/node_modules" export PATH=$PATH:"$NODE_PATH/.bin"
 * 1) node.js

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.

GNU/Linux (Debian)
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 deb http://ftp.free.fr/mirrors/ftp.debian.org/ testing main contrib non-free deb http://ftp.free.fr/mirrors/ftp.debian.org/ unstable main contrib non-free
 * 1) Please note the URL http://ftp.free.fr/mirrors/ftp.debian.org/ might be different
 * 2) for your local setup. The important thing is adding a line with 'unstable' :)
 * 1) Testing source list:
 * 1) Unstable source list:

/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 $

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 DOM
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 install
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) :

Then run the above code using node: $ node qunit_start.js test passes $

Congratulations! You have everything needed :-)