Mocha API testing | Share data between test suites in parallel testing

19 Views Asked by At

We are using mocha to test APIs end to end. In the project we have around 100+ tests suites and each test contains several tests. I have POM structure where tests are using helper methods to call the actual APIs and fetch data from the server. Just to share these helper methods, I want to create the fixtures just like we use in playwright (fixtures) where it initializes all the page objects in fixture and pass that object to each test where each test have the access to those helper objects.

Pseudo code:

export interface Helpers {
    users: UserHelper;
    tasks: AccountsHelper;
}

const helpers: Helpers = {
    users: new UserHelper(),
    tasks: new AccountsHelper(),
};

export default helpers;

Is there any way where I can pass this helper to the test itself as an parameter? I tried the beforeAll() hook by requiring it in the .mocharc.json file and it works fine for the scenario. But in parallel, it is still creating multiple objects.

How can I share the helper object between these parallel tests?

Another practical use case would be to share the JWT token for all the test cases, right now it is actually making login requests per test suite.

0

There are 0 best solutions below