5

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",
skyboyer
  • 22,209
  • 7
  • 57
  • 64
Garima ren
  • 81
  • 4

1 Answers1

1

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"
}
Taylor Johnson
  • 1,845
  • 1
  • 18
  • 31