Categories
JavaScript Answers

How to run Mocha tests with extra options or parameters with JavaScript?

Spread the love

To run Mocha tests with extra options or parameters with JavaScript, we get the values from process.argv.

For instance, we write

const argv = require("minimist")(process.argv.slice(2));
console.log("config", argv.config);

to get the command args with process.argv in the Mocha test file.

We then parse it with the minimist library into an object and get the config config.

Then we run the test with

mocha test.js --config=VALUE

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *