Categories
JavaScript Answers

How to run Mocha tests with extra options or parameters?

Spread the love

Sometimes, we want to run Mocha tests with extra options or parameters.

In this article, we’ll look at how to run Mocha tests with extra options or parameters.

How to run Mocha tests with extra options or parameters?

To run Mocha tests with extra options or parameters, we can set some environment variables before running the tests and then access them from process.env.

For instance, we run the tests with

env KEY=YOUR_KEY mocha test/*.js 

Then in the tests, we get the KEY environment variable with

const key = process.env.KEY;

Conclusion

To run Mocha tests with extra options or parameters, we can set some environment variables before running the tests and then access them from process.env.

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 *