npm.io
0.1.4 • Published 6 years agoCLI

mocha-headless-server

Licence
Apache-2.0
Version
0.1.4
Deps
0
Size
21 kB
Vulns
0
Weekly
0
Stars
3
DeprecatedThis package is deprecated

Use to run Mocha tests via headless browsers (currently just Chrome) via a local HTTP server.

Running a local HTTP server enables resources that require network access (e.g., JS module loading). This will serve files in the current working directory.

Usage

You should have a boilerplate Mocha test file and a suite of tests. You'll need Mocha and Chai added to your project. For a good example of the boilerplate files, check out ok-emoji: harness (HTML), which includes tests (JS)

Binary

From the command-line:

# either of
yarn global add mocha-headless-server
npm install -g mocha-headless-server

# then
mocha-headless-server path/to/test.html

Node

First, add this project as a dev dependency:

# either of
npm install --save-dev mocha-headless-server
yarn add --dev mocha-headless-server

Then you can require() this module and include it in your scripts:

const tester = require('mocha-headless-server');

const options = {
  path: 'path/to/test.html',  // path, required
  log: false,                 // whether to log to console
  headless: true,             // whether to run headless or to show browser
};
const p = tester(options);
p.then((out) => {
  if (out.fail.length) {
    // oh no, a test failed
  }
});

Travis-CI

First, add this project as a dev dependency:

# either of
npm install --save-dev mocha-headless-server
yarn add --dev mocha-headless-server

Then add this script to your package.json:

{
  "scripts": {
    "test": "mocha-headless-server path/to/test.html"
  }
}

Add this .travis.yml file to your project:

language: node_js
dist: trusty
node_js:
  - "node"
addons:
  chrome: stable

And perform the usual steps to set up Travis-CI for your project.