Categories
javascript mocha.js node.js

mocha.opts deprecated, how to migrate to package.json?

I’m working on a massive project and since last week I updated mocha, Now we are getting warning:

DeprecationWarning: Configuration via mocha.opts is DEPRECATED and
will be removed from a future version of Mocha. Use RC files or
package.json instead.

I want to migrate the options to package.json but there is no good migration guide. all posts on GitHub with similar questions are all answered “see the docs”. But the docs doesn’t show how to transfer one option from mocha.opts to package.json, there is no information on how it should be formatted. Only thing I can find is that the “spec” property is the pattern for files to run. Nothing else seems implicit to me.

Our mocha.opts file:

--reporter dot
--require test/mocha.main
--recursive src/**/*.test.js
--grep @slow --invert

My attempt which doesn’t work:

  "mocha": {
"reporter": "dot",
"require": "test/mocha.main",
"spec": "src/**/*.test.js",
"grep": "@slow --invert"
},

Please explain how I should format this configuration block in order to achieve samme behaviour as when using the options from the above mocha.opts