Skip to content

Instantly share code, notes, and snippets.

@pedroha
Last active August 29, 2015 14:05
Show Gist options
  • Save pedroha/731a885f62aa632c0075 to your computer and use it in GitHub Desktop.
Save pedroha/731a885f62aa632c0075 to your computer and use it in GitHub Desktop.
Setup Mocha tests with Gulp
1) Running Mocha tests
http://visionmedia.github.io/mocha/#getting-started
$ npm install -g mocha
$ mkdir test
$ $EDITOR test/test.js
var assert = require("assert")
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
assert.equal(-1, [1,2,3].indexOf(5));
assert.equal(-1, [1,2,3].indexOf(0));
})
})
})
$ mocha
2) Running mocha test with Gulp
a) Install gulp
$ npm install -g gulp
b) Add dependencies
$ $EDITOR package.json
{
"devDependencies": {
"gulp": "^3.8.7",
"gulp-mocha": "^1.0.0"
}
}
$ npm install
c) Edit gulpfile.js
$ $EDITOR gulpfile.js
var gulp = require('gulp');
var mocha = require('gulp-mocha');
gulp.task('default', function () {
return gulp.src('test/test.js', {read: false})
.pipe(mocha({reporter: 'nyan'}));
});
$ gulp
3) How abou PhantomJS? This is for client-side Mocha testing
https://www.npmjs.org/package/gulp-mocha-phantomjs
$ npm install gulp-mocha-phantomjs --save-dev
Mocha reporters
var gulp = require('gulp');
var mocha = require('gulp-mocha');
gulp.task('default', function () {
return gulp.src('test/test.js', {read: false})
.pipe(mocha({
reporter: 'nyan',
//reporter: 'dot',
//reporter: 'spec',
//reporter: 'tap',
//reporter: 'list',
//reporter: 'progress',
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment