Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zambezi/mocha-headless-chrome

Run Mocha tests using headless Google Chrome
https://github.com/zambezi/mocha-headless-chrome

headless headless-chrome mocha

Last synced: 11 days ago
JSON representation

Run Mocha tests using headless Google Chrome

Awesome Lists containing this project

README

        

# mocha-headless-chrome

Run Mocha tests with Node.js using headless Google Chrome.

They are alternative npm packages to do this task but this one differs from the other existing one by
- Working on Node.js < 8
- Not relying on GoogleChrome/puppeteer. Which make it faster and lighter.

## Getting Started

To begin, you'll need to install `@zambezi/mocha-headless-chrome`:

```console
$ npm install @zambezi/mocha-headless-chrome --save-dev
```

Then you'll need a local npm install of mocha:

```console
$ npm install mocha --save-dev
```

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

```html


Test








expect = chai.expect;
mocha.setup('bdd')

// add tests here

mocha.run();

```

You can then add your tests either through an external script file or
inline within a `` tag. Running the tests is easy, either with the CLI
binary, or programmatically.

## CLI

```console
$ mocha-headless-chrome --help

Usage
$ mocha-headless-chrome <file.html> [options]

Options
--mocha A JSON string representing a config object to pass to Mocha
--log-level Specify a log level; trace, debug, info, warn, error
--no-colors Disable colors in Mocha's output
--reporter Specify the Mocha reporter to use
--timeout Specify the test startup timeout to use

Examples
$ mocha-headless-chrome test.html --no-colors
$ mocha-headless-chrome test.html --reporter dot
$ mocha-headless-chrome test.html --mocha '{"ui":"tdd"}'
```

## Reporters

Third party reporter have to be loaded within the page to be used. For instance to use `mocha-teamcity-reporter` ;

- Install the reporter `npm install mocha-teamcity-reporter --save-dev`.
- Modify the HTML page to add a script tag:

```html
<!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">






expect = chai.expect;
mocha.setup('bdd')

// add tests here

mocha.run();