@dotcom-tool-kit/mocha
v4.0.2
Published
Tool Kit plugin to run [Mocha](http://mochajs.org)
Downloads
2,246
Readme
@dotcom-tool-kit/mocha
Tool Kit plugin to run Mocha
Installation & Usage
With Tool Kit already set up, install this plugin as a dev dependency:
npm install --save-dev @dotcom-tool-kit/mocha
And add it to your repo's .toolkitrc.yml
:
plugins:
- '@dotcom-tool-kit/mocha'
Tasks
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.
Tips
Resolving test command conflicts
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:
commands:
test:local:
- Eslint
- Mocha
test:ci:
- Eslint
- Mocha
Reporting code coverage
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
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:
{
"scripts": {
"test": "dotcom-tool-kit test:local",
"coverage": "nyc npm run test"
}
}