Skip to content

Upgrading mocha 5 to 6

Breaking5.2.0 → 6.2.3Breaking11Security4Platform1Deprecated7New21Changed8Fixed59Other47

BreakingUpgrade verdict

11 breaking changes and a platform requirement change and 4 security fixes.

  • The old --compilers flag no longer works and Mocha will error out if you pass it.
  • The short -d flag no longer turns on debug mode and is silently ignored.
  • If you rely on watching JavaScript files, you must now list js in the watch extensions.
  • You can no longer combine the two test-filtering options; Mocha will stop with an error.
Top 5 of 23 that need code or config changes

Node.js requirement changed in 6.0.0-0: >= 4.0.0 → >= 6.0.0.

Adds ansi-colors 3.2.3, find-up 3.0.0, js-yaml 3.13.1, log-symbols 2.2.0, ms 2.1.1, node-environment-flags 1.0.5, object.assign 4.1.0, strip-json-comments 2.0.1, which 1.3.1, wide-align 1.1.3, yargs 13.3.2, yargs-parser 13.1.2, yargs-unparser 1.6.0.

Drops commander.

Installs 171 packages in all (was 23).

Also installs ansi-regex, ansi-styles, argparse, array-buffer-byte-length, array.prototype.reduce, arraybuffer.prototype.slice, async-function, async-generator-function, available-typed-arrays, call-bind, call-bind-apply-helpers, call-bound, camelcase, chalk, cliui and 111 more.

Moves debug 3.1.0 → 3.2.6, glob 7.1.2 → 7.1.3, he 1.1.1 → 1.2.0, minimist 0.0.8 → 1.2.8, mkdirp 0.5.1 → 0.5.4, ms 2.0.0 → 2.1.1, supports-color 5.4.0 → 5.5.0, 6.0.0. Your build may pick other versions.

Breaking11
Removes support for the --compilers option; using it now fails with a link to more information.
--compilers
Removes -d as an alias for --debug; -d is now ignored.
-d--debug
--watch-extensions no longer implies js; js must be added explicitly.
--watch-extensions
Makes --grep and --fgrep mutually exclusive; using both now fails instead of ignoring --grep.
--grep--fgrep
The tap reporter now emits error messages.
tap
Timeout exceeded exceptions now include the filepath where applicable.
Moves lib/template.html to lib/browser/template.html.
lib/template.htmllib/browser/template.html
Throws an exception if Mocha cannot parse or find a mocha.opts at a user-specified path.
mocha.opts
Instantiating a Base-extending reporter without a Runner parameter now throws an exception.
BaseRunner
All exceptions from Mocha's programmatic API now have a code property; check code instead of message.
codemessage
Conditionally skipping in a before hook now also skips subsequent before hooks and tests in nested suites.
before
Security4
Updates dependencies mkdirp, yargs-parser and yargs as a security fix.
mkdirpyargs-parseryargs
Upgrades js-yaml to address a code injection vulnerability.
js-yaml
Updates dependency js-yaml to v3.13.0 per npm security advisory.
js-yaml
Avoids potential ReDoS when diffing large objects.
Platform1
Drops support for Node.js v4.x.
Deprecated7
Renames --exclude to --ignore and creates an alias.
--exclude--ignore
Soft-deprecates this.skip() in "after all" hooks, emitting a warning; support will likely be removed in the next major version.
this.skip()
Soft-deprecates -gc in favor of --gc-global, emitting a warning on use.
-gc--gc-global
Soft-deprecates the function exported by bin/options in favor of loadMochaOpts or loadOptions from lib/cli/options.
bin/optionsloadMochaOptsloadOptionslib/cli/options
Soft-deprecates the Mocha constructor option useColors in favor of color: false.
MochacoloruseColors
Soft-deprecates the Mocha constructor option enableTimeouts in favor of timeout: false.
MochatimeoutenableTimeouts
Considers mocha.opts legacy and prefers RC file or package.json configuration.
mocha.opts