Mocha-Sinon-Chai
Wrapper for Mocha, Sinon, Chai, sinon-chai and dirty-chai
It also includes Istanbul as a dependency, and provides "proxy" bin
files that allow to launch tests and generate coverages.
Use this package to implement test runner, assertions, spies, mocks and stubs importing an unique dependency, and avoid using global variables in your tests.
Usage
const test = test
Tests runner, and coverage
Binary "proxies" for "istanbul cover" and "mocha" are provided. This is because in npm install
, binaries from dependencies of dependencies sometimes are not added to .bin
folder as symlinks.
Add the next script to your package.json
file:
npm test -- --mocha my-test-folder
All received parameters preceded by --istanbul
will be passed to istanbul cover
command, and all parameters preceded by --mocha
will be passed to _mocha
command:
npm test -- --istanbul --include-all-sources --print=detail --mocha --recursive my-test-folder# same as "./node_modules/.bin/istanbul --include-all-sources --print=detail cover ./node_modules/.bin/_mocha -- --recursive my-test/folder"
You can read more about istanbul or mocha configurations in their own documentation pages.
Add your test custom configuration to your package.json
file:
Configuration using files
Configuration file .istanbul.yml
in your package root is supported as well.
Custom execution
Proxies for "istanbul", "mocha" and "_mocha" original binaries are available too:
Note: In Windows environments, you can't pass a binary to istanbul. The "coverage" script in the previous example should be:
Why
- Because Mocha works with globals.
- Because I used to import all these dependencies in all my test files.
- Because now, my tests are compliant with standardjs.
Contributing
Contributions are welcome! Read the contributing guide lines and code of conduct, check out the issues or the PRs, and make your own if you want something that you don't see there.