Socket
Book a DemoInstallSign in
Socket

mocha-sinon-chai

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha-sinon-chai

Wrapper for Mocha, Sinon and Chai. Wrapper cli for istanbul and mocha. Avoid globals in tests

3.0.0
latest
Source
npmnpm
Version published
Weekly downloads
48
-76.81%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Build status Coverage Status Quality Gate js-standard-style

NPM dependencies NPM downloads License

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-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:

{
  "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.

Keywords

istanbul

FAQs

Package last updated on 11 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.