0.1.4 • Published 4 years ago

mocha-headless-server v0.1.4

Weekly downloads
9
License
Apache-2.0
Repository
github
Last release
4 years ago

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.

0.1.4

4 years ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago