mocha-sinon-chai v3.0.0
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 = require('mocha-sinon-chai')
test.describe('mocha-sinon-chai', () => {
test.it('should return mocha globals', () => {
test.expect(test.after).to.not.be.undefined()
test.expect(test.afterEach).to.not.be.undefined()
test.expect(test.before).to.not.be.undefined()
test.expect(test.beforeEach).to.not.be.undefined()
test.expect(test.describe).to.not.be.undefined()
test.expect(test.it).to.not.be.undefined()
})
test.it('should return chai expect', () => {
test.expect(test.expect).to.not.be.undefined()
})
test.it('should return chai assert', () => {
test.expect(test.assert).to.not.be.undefined()
})
test.it('should return sinon', () => {
test.expect(test.sinon).to.not.be.undefined()
})
})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:
{
"scripts": {
"test": "mocha-sinon-chai"
},
"devDependencies" : {
"mocha-sinon-chai": "3.0.0"
}
}npm test -- --mocha my-test-folderAll 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:
{
"scripts": {
"test": "mocha-sinon-chai --istanbul --include-all-sources --print=detail --verbose --mocha --recursive my-test-folder"
}
}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:
{
"scripts": {
"test": "msc-mocha --recursive test",
"coverage": "msc-istanbul --include-all-sources --print=detail cover msc_mocha -- --recursive test"
}
}Note: In Windows environments, you can't pass a binary to istanbul. The "coverage" script in the previous example should be:
{
"scripts": {
"coverage": "msc-istanbul --include-all-sources --print=detail cover node_modules/mocha-sinon-chai/bin/msc_mocha -- --recursive test"
}
}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.