Tool Kit plugin to run [Mocha](http://mochajs.org)
Tool Kit plugin to run Mocha
With Tool Kit already set up, install this plugin as a dev dependency:
``sh`
npm install --save-dev @dotcom-tool-kit/mocha
And add it to your repo's .toolkitrc.yml:
`yml`
plugins:
- '@dotcom-tool-kit/mocha'
Runs mocha to execute tests.
#### Task options
| Property | Description | Type | Default |
| :----------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :--------------- |
| files | A file path glob to Mocha tests. | string | 'test/*/.js' |configPath
| | Path to the Mocha config file. Uses Mocha's own config resolution by default. | string | |
_All properties are optional._
A common use case is to configure test:local and test:ci in your .toolkitrc.yml to run the Eslint task then the relevant Mocha task:
`yaml`
commands:
test:local:
- Eslint
- Mocha
test:ci:
- Eslint
- Mocha
If you want to test the coverage of your code (i.e., how many lines of your code are executed by your unit tests) you can use the Istanbul tool that integrates with Mocha. To use Istanbul, install the command line interface, nyc, by running
`sh`
npm install --save-dev nyc
and then adding a new script to your package.json that just runs the Tool Kit test:local hook (which should in turn run your Mocha tests) with the nyc command prepended to it:
`json``
{
"scripts": {
"test": "dotcom-tool-kit test:local",
"coverage": "nyc npm run test"
}
}