# grunt-mocha-phantomjs

> Run client-side mocha tests using phantomjs

Latest version **4.0.0** (published 2016-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install grunt-mocha-phantomjs
pnpm add grunt-mocha-phantomjs
yarn add grunt-mocha-phantomjs
bun add grunt-mocha-phantomjs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2016-08-09 |
| First published | 2013-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 70 |
| Author | Justin Cataldo |
| Maintainers | jdcataldo |
| Keywords | gruntplugin, mocha, mocha-phantomjs, phantomjs |

## Links

- npm: https://www.npmjs.com/package/grunt-mocha-phantomjs
- Repository: https://github.com/jdcataldo/grunt-mocha-phantomjs
- Issues: https://github.com/jdcataldo/grunt-mocha-phantomjs/issues
- npm.io page: https://npm.io/package/grunt-mocha-phantomjs

## Dependencies (4)

- [async](https://npm.io/package/async.md) ^1.5.2
- [object-assign](https://npm.io/package/object-assign.md) ^4.1.0
- [phantomjs-prebuilt](https://npm.io/package/phantomjs-prebuilt.md) ^2.1.3
- [mocha-phantomjs-core](https://npm.io/package/mocha-phantomjs-core.md) ^1.3.0

## Recent versions

- 4.0.0 (latest) — 2016-08-09
- 3.0.0 — 2016-02-05
- 2.0.1 — 2015-11-19
- 2.0.0 — 2015-09-02
- 1.0.2 — 2015-08-10
- 1.0.1 — 2015-08-09
- 1.0.0 — 2015-07-28
- 0.7.0 — 2015-07-16
- 0.6.2 — 2015-07-16
- 0.6.1 — 2015-02-26
- 0.6.0 — 2014-07-25
- 0.5.0 — 2014-05-08
- 0.4.3 — 2014-03-01
- 0.4.2 — 2014-02-19
- 0.4.1 — 2014-02-18
- … 13 more at https://npm.io/package/grunt-mocha-phantomjs/versions

## README

# grunt-mocha-phantomjs

> A simple wrapper to run client-side mocha tests using [mocha-phantomjs](http://metaskills.net/mocha-phantomjs/) core library

[![Build Status](https://travis-ci.org/jdcataldo/grunt-mocha-phantomjs.svg?branch=master)](https://travis-ci.org/jdcataldo/grunt-mocha-phantomjs)
[![Downloads](https://img.shields.io/npm/dm/grunt-mocha-phantomjs.svg)](https://www.npmjs.com/package/grunt-mocha-phantomjs)

## Getting Started
This plugin requires Grunt `~0.4.0`

If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

```shell
npm install grunt-mocha-phantomjs --save-dev
```

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

```js
grunt.loadNpmTasks('grunt-mocha-phantomjs');
```

## The "mocha_phantomjs" task

_Run this task with the `grunt mocha_phantomjs` command._

Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.

[PhantomJS][] is installed when installing using NPM.

[PhantomJS]: http://www.phantomjs.org/

### Options

#### reporter
Type: `String`  
Default: `spec`

The reporter that should be used. See [the supported reporters](https://github.com/metaskills/mocha-phantomjs#supported-reporters) for more information.

#### output
Type: `String`  

The file that the task should output the results to. If `output` is specified, the task will always complete and not throw an error code if errors are found. The CI will determine if the build failed or not.

#### failWithOutput
Type: `Boolean`  

Setting `failWithOutput` to true when used with the `output` option will fail a build along with creating a test artifact. This is useful for CIs (CircleCI) that don't fail a build based on the test artifact.

#### silent
Type: `Boolean`  

Setting `silent` to true will prevent the results from being printed using stdout.

#### urls
Type: `Array`  
Default: `[]`

Absolute `http://` or `https://` urls to be passed to PhantomJS. Specified URLs will be merged with any specified `src` files first. Note that urls must be served by a web server, and since this task doesn't contain a web server, one will need to be configured separately. The [grunt-contrib-connect plugin](https://github.com/gruntjs/grunt-contrib-connect) provides a basic web server.

Additional arguments may be passed. See [mocha-phantomjs's](https://github.com/metaskills/mocha-phantomjs#usage) usage.

#### phantomConfig
Type: `Object`
Default: `{}`

Options to be passed directly to phantomjs. Eg:

```js
{
    "--local-storage-path": "my/temp-phantom-files",
    "--local-storage-quota": "20480"
}
```

See `phantomjs -h` for more full options list.

#### config
Type: `Object`  
Default: `{ useColors: true }`

Options to be passed to mocha-phantomjs. See [mocha-phantomjs-core's](https://github.com/nathanboktae/mocha-phantomjs-core#usage) usage.

### Usage examples

#### Basic usage (CI checks for error code)

```js
// Project configuration.
grunt.initConfig({
  mocha_phantomjs: {
    all: ['test/**/*.html']
  }
});
```

#### File output for CI

```js
// Project configuration.
grunt.initConfig({
  mocha_phantomjs: {
    options: {
      reporter: 'xunit',
      output: 'tests/results/result.xml'
    },
    all: ['test/**/*.html']
  }
});
```

#### Passing options to mocha-phantomjs

```js
// Project configuration.
grunt.initConfig({
  mocha_phantomjs: {
    options: {
      reporter: 'xunit',
      output: 'tests/results/result.xml',
      config: {
        useColors: false,
        viewportSize: {
            width: 1024,
            height: 768
        },
        grep: 'pattern'
      }
    },
    all: ['test/**/*.html']
  }
});
```

#### Local server
Include the [grunt-contrib-connect plugin][] to run a local server
[grunt-contrib-connect plugin]: https://github.com/gruntjs/grunt-contrib-connect

```js
// Project configuration.
grunt.initConfig({
  mocha_phantomjs: {
    all: {
      options: {
        urls: [
          'http://localhost:8000/test/foo.html',
          'http://localhost:8000/test/bar.html'
        ]
      }
    }
  },
  connect: {
      server: {
        options: {
          port: 8000,
          base: '.',
        }
      }
    }
});

grunt.registerTask('test', ['connect', 'mocha_phantomjs']);
```

### Notes
This is a very basic implementation of mocha-phantomjs. Failed tests and errors do not bubble up for custom reporting. The idea of this is to be mainly used by a CI and let the CI manage the error reporting.

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