This feature was added in Jest’s 22 version, with globalSetup and globalTeardown configurations.
Look at this for examples.
package.json (or in jest.config.js)
{
...
"jest": {
"globalSetup": "./scripts/jestGlobalSetup.js"
}
}
/scripts/jestGlobalSetup.js
module.exports = async () => {
console.log('\nhello, this is just before tests start running');
};
OR
export default async () => {
console.log('\nhello, this is just before tests start running');
};