Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

samthor/mocha-headless-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

You should use headless-test instead of this. There's nothing wrong with this package, but it's not as easy to use.

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.

About

Headless Mocha testing on a local HTTP server

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published