How can I use Jasmine in Cloud9?
I use Jasmine (BDD for JavaScript) regularly and just discovered Cloud9 and want to give it a try.
On my local machine, I use jasmine-node to run my specs, but I have no idea, how to do this within Cloud9. I was able to use the console bar at the bottom of the Cloud9 editor to somehow ins开发者_开发问答tall jasmine-node via npm, but I was not able to use it.
I write the code in CoffeeScript, but this should not be the problem, I tried JavaScript as well.
Add a run-tests.js file to the project which contains an adaption of the jasmine-node script. In this example, production code is under a lib folder parallel to the run-tests.js file.
Run config:
File path: run-tests.js
Command line arguments: --coffee spec
run-tests.js
if( !process.env.NODE_ENV ) process.env.NODE_ENV = 'test';
var path = require('path');
// find out the current paths
//console.log(require.paths);
// I have ~/.node_modules in there, which did not exist and did a
// ln -s ~/local/lib/node_modules/ ~/.node_modules
// my jasmine-node/cli.js is in
// ~/local/lib/node_modules/jasmine-node/lib/jasmine-node/cli.js
// Add the local lib path to allow the specs to require from there
require.paths.unshift(path.join(__dirname, 'lib'));
require('jasmine-node/lib/jasmine-node/cli.js');
Currently in Cloud9 you are able to do:
npm install -g jasmine-node
Then use the simplified script as run-tests.js
:
require('jasmine-node/lib/jasmine-node/cli.js');
That's all (at least it was for me). Just don't forget to name your spec files as .spec.js
精彩评论