v6.0.0
6.0.0 / 2019-02-18
💥 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 impliesjs
; it must be explicitly added (@TheDancingCode)
- #2908:
tap
reporter emits error messages (@chrmod) - #2819: When conditionally skipping in a
before
hook, subsequentbefore
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 tolib/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 aRunner
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). SomeError
messages have changed. Please use thecode
property to checkError
types instead of themessage
property; these descriptions will be localized in the future. (@craigtaub)
📠 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 theloadMochaOpts
orloadOptions
(preferred) functions exported by thelib/cli/options
module
Regarding the Mocha
class constructor (from lib/mocha
):
- Use property
color: false
instead ofuseColors: false
- Use property
timeout: false
instead ofenableTimeouts: 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
.
🎉 Enhancements
- #3726: Add ability to unload files from
require
cache (@plroebuck)
Enhancements introduced in #3556:
-
Mocha now supports "RC" files in JS, JSON, YAML, or
package.json
-based (usingmocha
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 explicitpackage.json
to read themocha
prop from - Use
--no-config
or--no-package
to completely disable loading of configuration via RC file andpackage.json
, respectively - Configurations are merged as applicable using the priority list:
- Command-line arguments
- RC file
package.json
mocha.opts
- 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 ofnode
(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, ormocha.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 ofnode
- Support all allowed
-
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 onlytest/*.coffee
(nottest/*.js
), you can domocha --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) -
#2529:
Runner
now emits aretry
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)
🐛 Fixes
- #3737: Fix falsy values from options globals (@plroebuck)
- #3707: Fix encapsulation issues for
Suite#_onlyTests
andSuite#_onlySuites
(@vkarpov15) - #3711: Fix diagnostic messages dealing with plurality and markup of output (@plroebuck)
- #3723: Fix "reporter-option" to allow comma-separated options (@boneskull)
- #3722: Fix code quality and performance of
lookupFiles
andfiles
(@plroebuck) - #3650, #3654: Fix noisy error message when no files found (@craigtaub)
- #3632: Tests having an empty title are no longer confused with the "root" suite (@juergba)
- #3666: Fix missing error codes (@vkarpov15)
- #3684: Fix exiting problem in Node.js v11.7.0+ (@addaleax)
- #3691: Fix
--delay
(and other boolean options) not working in all cases (@boneskull) - #3692: Fix invalid command-line argument usage not causing actual errors (@boneskull)
- #3698, #3699: Fix debug-related Node.js options not working in all cases (@boneskull)
- #3700: Growl notifications now show the correct number of tests run (@outsideris)
- #3686: Avoid potential ReDoS when diffing large objects (@cyjake)
- #3715: Fix incorrect order of emitted events when used programmatically (@boneskull)
- #3706: Fix regression wherein
--reporter-option
/--reporter-options
did not support comma-separated key/value pairs (@boneskull) - Fix missing
mocharc.json
in published package (@boneskull) - #3356:
--no-timeouts
and--timeout 0
now does what you'd expect (@boneskull) - #3475: Restore
--no-exit
option (@boneskull) - #3570: Long-running tests now respect
SIGINT
(@boneskull) - #2944:
--forbid-only
and--forbid-pending
now "fail fast" when encountered on a suite (@outsideris) - #1652, #2951: Fix broken clamping of timeout values (@plroebuck)
- #2095, #3521: Do not log
stdout:
prefix in browser console (@Bamieh) - #3595: Fix mochajs.org deployment problems (@papandreou)
- #3518: Improve
utils.isPromise()
(@fabiosantoscode) - #3320: Fail gracefully when non-extensible objects are thrown in async tests (@fargies)
- #2475: XUnit does not duplicate test result numbers in "errors" and "failures"; "failures" will always be zero (@mlucool)
- #3398, #3598, #3457, #3617: Fix regression wherein
--bail
would not execute "after" nor "after each" hooks (@juergba) - #3580: Fix potential exception when using XUnit reporter programmatically (@Lana-Light)
- #1304: Do not output color to
TERM=dumb
(@plroebuck)
📖 Documentation
- #3525: Improvements to
.github/CONTRIBUTING.md
(@markowsiak) - #3466: Update description of
slow
option (@finfin) - #3405: Remove references to bower installations (@goteamtim)
- #3361: Improvements to
--watch
docs (@benglass) - #3136: Improve docs around globbing and shell expansion (@akrawchyk)
- #2819: Update docs around skips and hooks (@bannmoore)
- Many improvements by @outsideris
- #3652: Switch from Jekyll to Eleventy (@Munter)
🔩 Other
- #3677: Add error objects for createUnsupportedError and createInvalidExceptionError (@boneskull)
- #3733: Removed unnecessary processing in post-processing hook (@wanseob)
- #3730: Update nyc to latest version (@coreyfarrell)
- #3648, #3680: Fixes to support latest versions of unexpected and unexpected-sinon (@sunesimonsen)
- #3638: Add meta tag to site (@MartijnCuppens)
- #3653: Fix parts of test suite failing to run on Windows (@boneskull)
- #3557: Use
ms
userland module instead of hand-rolled solution (@gizemkeser) - Many CI fixes and other refactors by @plroebuck
- Test refactors by @outsideris