Configuring Test Suite Separately By The Test Scopes

İbrahim Gündüz
2 min readApr 2, 2022

Different test copes may require different configurations. For example, unit tests can finish in a short time frame as all the dependencies are mocked, however, end-to-end tests may need a higher timeout value if the application needs to communicate external services.

In this article, we’ll see how to create a test scope-specific configuration for the mocha framework but most of them support similar features.

Creating Configuration files

Though mocha can automatically recognize a configuration file named .mocharc.json in the project root, it allows using custom configuration file names as well. So you can create your own configuration files based on each test scope needs.

mocha.unit-test.json

{
// Define timeout value in milliseconds
“timeout”: 100,

// You can import any module before running the suite as below.
“require”: [“ts-node/register”],
// Define the filename pattern for the unit tests to be executed.
“spec”: “test/unit/*.test.ts”,
// And.. other configurations supported by mocha
“color”: true,
“forbid-only”: true,
“check-leaks”: true
}

mocha.e2e-test.json

{
// As the e2e tests may take…

--

--