Coder Social home page Coder Social logo

gulp-mocha-chrome's Introduction

gulp-mocha-phantomjs

โ˜• Run Mocha tests using headless Google Chrome through Gulp

Build Status Known Vulnerabilities npm version GitHub version Open Source Love Dependency Status devDependencies Status

Getting Started

To begin, you'll need to install gulp-mocha-chrome:

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

Then you'll need a local npm install of mocha for your test html files to reference:

$ npm install mocha --save-dev

To run the tests, you'll need an HTML file with some basics:

<!doctype>
<html>
  <head>
    <title>Test</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="node_modules/mocha/mocha.css" />
    <script src="node_modules/mocha/mocha.js"></script>
    <script src="node_modules/chai/chai.js"></script>
  </head>
  <body>
    <div id="mocha"></div>
    <script>
      expect = chai.expect;

      // add tests here

      mocha.run();
    </script>
  </body>
</html>

You can then add your tests either through an external script file or inline within a <script> tag.

Gulpfile

Next, you'll need to add the tests to your gulpfile.js.

const gulp = require('gulp');
const mochaChrome = require('gulp-mocha-chrome');

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

Remote URLs

Because mocha-chrome uses the Chrome Devtools Protocol under the hood, you can also connect to remote (or locally served) urls for testing. eg:

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

Mocha Test Stats

If you're using a Gulp plugin like gulp-tap to inspect the results after the tests run, you can access the Mocha results for individual file via the file.mocha property. eg:

gulp.src('test/runner.html')
  .pipe(mochaChrome())
  .pipe(tap(function(file, t) {
      file.mocha;
  }));

/*
file.mocha -> {
  stats:
  {
    suites: 2,
    tests: 2,
    passes: 2,
    pending: 0,
    failures: 0,
    start: '2017-08-07T14:50:33.989Z',
    end: '2017-08-07T14:50:34.003Z',
    duration: 14
  }
}
*/

Contributing

We welcome your contributions! Please have a read of CONTRIBUTING.

gulp-mocha-chrome's People

Contributors

shellscape avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.