run client-side Mocha tests with PhantomJS
npm install gulp-mocha-phantomjs> a simple wrapper for mocha-phantomjs-core library
shell
$ npm install gulp-mocha-phantomjs --save-dev
`Usage
`html
Mocha
``javascript
var gulp = require('gulp');
var mochaPhantomJS = require('gulp-mocha-phantomjs');gulp.task('test', function () {
return gulp
.src('test/runner.html')
.pipe(mochaPhantomJS());
});
`Reporter can be chosen via
reporter option:`javascript
gulp.task('test', function () {
return gulp
.src('test/runner.html')
.pipe(mochaPhantomJS({reporter: 'spec'}));
});
`Output of mocha tests can be piped into a file via
dump option:`javascript
gulp.task('test', function () {
return gulp
.src('test/runner.html')
.pipe(mochaPhantomJS({reporter: 'spec', dump:'test.log'}));
});
`Test against remote by url:
`javascript
gulp.task('test', function () {
var stream = mochaPhantomJS();
stream.write({path: 'http://localhost:8000/index.html'});
stream.end();
return stream;
});
`Suppress PhantomJS’s console output:
`javascript
gulp.task('test', function() {
return gulp
.src('test/runner.html')
.pipe(mochaPhantomJS({
suppressStdout: true,
suppressStderr: true
}));
});
`Pass options to mocha and/or PhantomJS:
`javascript
gulp.task('test', function () {
return gulp
.src('test/runner.html')
.pipe(mochaPhantomJS({
reporter: 'tap',
mocha: {
grep: 'pattern'
},
phantomjs: {
viewportSize: {
width: 1024,
height: 768
},
useColors:true
}
}));
});
``