/gulp-mocha-phantomjs

run client-side Mocha tests with PhantomJS

Primary LanguageJavaScript

gulp-mocha-phantomjs Build Status

run client-side Mocha tests with PhantomJS

Installation

node

$ npm install gulp-mocha-phantomjs --save-dev

Usage

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mocha Test Runner</title>
    <link rel="stylesheet" href="bower_components/mocha/mocha.css">
  </head>
  <body>
    <div id="mocha"></div>
    <script src="bower_components/mocha/mocha.js"></script>
    <script src="bower_components/should/should.js"></script>
    <script>mocha.setup('bdd')</script>
    <script src="spec/test.js"></script>
    <script>
      if (window.mochaPhantomJS) {
        mochaPhantomJS.run();
      } else {
        mocha.run();
      }
    </script>
  </body>
</html>
var gulp = require('gulp');
var mochaPhantomJS = require('gulp-mocha-phantomjs');

gulp.task('test', function () {
  return gulp
  .src('test/runner.html')
  .pipe(mochaPhantomJS());
});

The reporter can be chosen by supplying an object with reporter property:

gulp.task('test', function () {
  return gulp
  .src('test/runner.html')
  .pipe(mochaPhantomJS({reporter: 'nyan'}));
});

You can set the dump option to write the results of mocha tests in a file:

gulp.task('test', function () {
  return gulp
  .src('test/runner.html')
  .pipe(mochaPhantomJS({reporter: 'xunit', dump:'test.xml'}));
});

You can set the grep option to run selected test:

gulp.task('test', function () {
  return gulp
  .src('test/runner.html')
  .pipe(mochaPhantomJS({grep: 'PATTERN_OF_MOCHA_TEST'}));
});

It results the same as running the following command in command line

mocha-phantomjs "test/runner.html?grep=PATTERN_OF_MOCHA_TEST"

To test against remote by url:

gulp.task('test', function () {
  var stream = mochaPhantomJS();
  stream.write({path: 'http://localhost:8000/index.html'});
  stream.end();
  return stream;
});

License

MIT