Socket
Socket
Sign inDemoInstall

mocha

Package Overview
Dependencies
23
Maintainers
2
Versions
196
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha


Version published
Weekly downloads
6.2M
decreased by-18.16%
Maintainers
2
Install size
7.75 MB
Created
Weekly downloads
 

Package description

What is mocha?

Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.

What are mocha's main functionalities?

Test Organization

Organize tests in suites and sub-suites using describe() and context(), and specify test cases using it().

"use strict";\nconst assert = require('assert');\ndescribe('Array', function() {\n  describe('#indexOf()', function() {\n    it('should return -1 when the value is not present', function() {\n      assert.equal([1, 2, 3].indexOf(4), -1);\n    });\n  });\n});

Asynchronous Testing

Support for testing asynchronous code with ease, using callbacks, promises, or async/await.

"use strict";\nconst assert = require('assert');\ndescribe('User', function() {\n  describe('#save()', function() {\n    it('should save without error', function(done) {\n      const user = new User('Luna');\n      user.save(function(err) {\n        if (err) done(err);\n        else done();\n      });\n    });\n  });\n});

Hooks

Lifecycle hooks such as before(), after(), beforeEach(), and afterEach() for setting up preconditions and clean-up after tests.

"use strict";\ndescribe('Connection', function() {\n  before(function() {\n    // runs once before the first test in this block\n  });\n\n  after(function() {\n    // runs once after the last test in this block\n  });\n\n  beforeEach(function() {\n    // runs before each test in this block\n  });\n\n  afterEach(function() {\n    // runs after each test in this block\n  });\n\n  // test cases\n});

Other packages similar to mocha

Changelog

Source

6.0.0-0 / 2019-01-01

Documentation for this release can be found at next.mochajs.org!

Welcome @plroebuck, @craigtaub, & @markowsiak to the team!

:boom: Breaking Changes

  • #3149: Drop Node.js v4.x support (@outsideris)
  • #3556: Changes to command-line options (@boneskull):
    • --grep and --fgrep are now mutually exclusive; attempting to use both will cause Mocha to fail instead of simply ignoring --grep
    • --compilers is no longer supported; attempting to use will cause Mocha to fail with a link to more information
    • -d is no longer an alias for --debug; -d is currently ignored
    • #3275: --watch-extensions no longer implies js; it must be explicitly added (@TheDancingCode)
  • #2908: tap reporter emits error messages (@chrmod)
  • #2819: When conditionally skipping in a before hook, subsequent before hooks and tests in nested suites are now skipped (@bannmoore)
  • #627: Emit filepath in "timeout exceeded" exceptions where applicable (@boneskull)
  • #3556: lib/template.html has moved to lib/browser/template.html (@boneskull)
  • #2576: An exception is now thrown if Mocha fails to parse or find a mocha.opts at a user-specified path (@plroebuck)
  • #3458: Instantiating a Base-extending reporter without a Runner parameter will throw an exception (@craigtaub)
  • #3125: For consumers of Mocha's programmatic API, all exceptions thrown from Mocha now have a code property (and some will have additional metadata). Some Error messages have changed. Please use the code property to check Error types instead of the message property; these descriptions will be localized in the future. (@craigtaub)

:fax: Deprecations

These are soft-deprecated, and will emit a warning upon use. Support will be removed in (likely) the next major version of Mocha:

  • -gc users should use --gc-global instead
  • Consumers of the function exported by bin/options should now use the loadMochaOpts or loadOptions (preferred) functions exported by the lib/cli/options module

Regarding the Mocha class constructor (from lib/mocha):

  • Use property color: false instead of useColors: false
  • Use property timeout: false instead of enableTimeouts: false

All of the above deprecations were introduced by #3556.

mocha.opts is now considered "legacy"; please prefer RC file or package.json over mocha.opts.

:tada: Enhancements

Enhancements introduced in #3556:

  • Mocha now supports "RC" files in JS, JSON, YAML, or package.json-based (using mocha property) format

    • .mocharc.js, .mocharc.json, .mocharc.yaml or .mocharc.yml are valid "rc" file names and will be automatically loaded
    • Use --config /path/to/rc/file to specify an explicit path
    • Use --package /path/to/package.json to specify an explicit package.json to read the mocha prop from
    • Use --no-config or --no-package to completely disable loading of configuration via RC file and package.json, respectively
    • Configurations are merged as applicable using the priority list:
      1. Command-line arguments
      2. RC file
      3. package.json
      4. mocha.opts
      5. Mocha's own defaults
    • Check out these example config files
  • Node/V8 flag support in mocha executable:

    • Support all allowed node flags as supported by the running version of node (also thanks to @demurgos)
    • Support any V8 flag by prepending --v8- to the flag name
    • All flags are also supported via config files, package.json properties, or mocha.opts
    • Debug-related flags (e.g., --inspect) now imply --no-timeouts
    • Use of e.g., --debug will automatically invoke --inspect if supported by running version of node
  • Support negation of any Mocha-specific command-line flag by prepending --no- to the flag name

  • Interfaces now have descriptions when listed using --interfaces flag

  • Mocha constructor supports all options

  • --extension is now an alias for --watch-extensions and affects non-watch-mode test runs as well. For example, to run only test/*.coffee (not test/*.js), you can do mocha --require coffee-script/register --extensions coffee.

  • #3552: tap reporter is now TAP13-capable (@plroebuck & @mollstam)

  • #3535: Mocha's version can now be queried programmatically via public property Mocha.prototype.version (@plroebuck)

  • #3428: xunit reporter shows diffs (@mlucool)

  • #2529: Runner now emits a retry event when tests are retried (reporters can listen for this) (@catdad)

  • #2962, #3111: In-browser notification support; warn about missing prereqs when --growl supplied (@plroebuck)

:bug: Fixes

:book: Documentation

:nut_and_bolt: Other

Readme

Source

Mocha test framework

:coffee: Simple, flexible, fun JavaScript test framework for Node.js & The Browser :coffee:

Build Status Coverage Status FOSSA Status Gitter OpenCollective OpenCollective


Mocha Browser Support h/t SauceLabs

Backers

Become a backer and show your support to our open source project.

MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer

Sponsors

Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show on GitHub and on our site - who doesn't want a little extra exposure? Here's the info.

MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer MochaJS Backer

Development

You might want to know that:

  • Mocha is the most-depended-upon module on npm (source: libraries.io), and
  • Mocha is an independent open-source project, maintained exclusively by volunteers.

You might want to help:

Finally, come chat with the maintainers on Gitter if you want to help with:

  • Triaging issues, answering questions
  • Review, merging, and closing pull requests
  • Other project-maintenance-y things

License

MIT

FOSSA Status

Keywords

FAQs

Last updated on 01 Jan 2019

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc