Last active
August 29, 2015 14:05
-
-
Save pedroha/731a885f62aa632c0075 to your computer and use it in GitHub Desktop.
Setup Mocha tests with Gulp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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