# mocha-headless-server

> Run Mocha tests via headless browsers with HTTP server

Latest version **0.1.4** (published 2019-12-08) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install mocha-headless-server
pnpm add mocha-headless-server
yarn add mocha-headless-server
bun add mocha-headless-server
```

Provides the command `mocha-headless-server`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2019-12-08 |
| First published | 2018-07-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 21 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Sam Thorogood |
| Maintainers | samthor |

## Links

- npm: https://www.npmjs.com/package/mocha-headless-server
- Repository: git@github.com:samthor/mocha-headless-server
- npm.io page: https://npm.io/package/mocha-headless-server

## Recent versions

- 0.1.4 (latest) — 2019-12-08
- 0.1.3 — 2019-05-28
- 0.1.2 — 2018-07-30
- 0.1.1 — 2018-07-18
- 0.1.0 — 2018-07-18

## README

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](http://npmjs.com/package/mocha) and [Chai](http://npmjs.com/package/chai) added to your project.
For a good example of the boilerplate files, check out `ok-emoji`: [harness (HTML)](https://github.com/samthor/ok-emoji/blob/master/test.html), which includes [tests (JS)](https://github.com/samthor/ok-emoji/blob/master/suite.js)

## Binary

From the command-line:

```bash
# 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:

```bash
# 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:

```js
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:

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

Then add this script to your `package.json`:

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

Add this `.travis.yml` file to your project:

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

And perform the usual steps to set up [Travis-CI](https://travis-ci.org/) for your project.

---
_Source: https://npm.io/package/mocha-headless-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
