Tool Kit plugin to run Mocha
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'
Key | Description | Default value |
---|---|---|
files |
A file path glob to Mocha tests | 'test/**/*.js' |
configPath |
Path to the Mocha config file | use Mocha's own config resolution |
Task | Description | Preconfigured hook |
---|---|---|
Mocha |
runs mocha to execute tests |
test:local , test:ci |
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:
hooks:
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
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"
}
}