Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Jest globalSetup with Detox

Tags:

jestjs

detox

I want to use globalSetup and globalTeardown from Jest with Detox so that the detox setup only happens one time but Detox seems to fail if the init is not beforeAll.

Any suggestions?

Jest version :22.0.4 Detox Version:6.0.4

config:

"globalSetup": "./setUpDetox.js",
"globalTeardown": "./tearDownDetox.js",
like image 331
Garima ren Avatar asked Nov 07 '22 12:11

Garima ren


1 Answers

Instead of using the globalSetup and globalTeardown, setup and teardown the test environment from within your init. Just use jest's beforeAll and afterAll.

e2e/init.js

const detox = require('detox');
const config = require('../package.json').detox;

jest.setTimeout(120000);

beforeAll(async () => {
  // custom setup
  console.log('Initializing Detox');
  await detox.init(config, { launchApp: false });
});

afterAll(async () => {
  // custom teardown
  await detox.cleanup();
});

e2e/config.json

{
  "setupTestFrameworkScriptFile" : "./init.js"
}
like image 184
Taylor Johnson Avatar answered Dec 07 '22 10:12

Taylor Johnson