'Unable to do Parallel testing with Detox and Jest

I have seen similar questions on Stack Overflow but I don't feel like we're having the same issue and its been one year for the last question with no answers.

I have followed the documentation and all my tests are working fine, but when I open 4 simulators to try parallel testing only one of them reacts.

package.json

{
 ...
  "detox": {
    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "ios/build/AppName/Build/Products/Debug-iphonesimulator/AppName.app",
        "build": "xcodebuild -project ios/AppName.xcodeproj -scheme AppName -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "device": {
          "type": "iPhone 11"
        }
      }
    },
    "test-runner": "jest --detectOpenHandles --verbose",
    "runner-config": "tests/detox/jest.config.js"
  }
}

tests/detox/jest.config.js

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  setupFilesAfterEnv: ['./init.ts']
};

init.ts

import { cleanup, init } from 'detox';
const adapter = require('detox/runners/jest/adapter');

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

jest.setTimeout(90000);

jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
  await init(config, { initGlobals: false });
}, 90000);

afterAll(async () => {
  await adapter.afterAll();
  await cleanup();
});

And here is the command I use to start tests, after having 4 IOS simulators running and ready

detox test -l warn -w 4 ./path-to-all-tests

Dependencies

  • MacOS catalina
  • xed version 11.4
  • detox: ^16.0.2
  • jest: ^24.9.0
  • ts-jest: ^24.1.0


Solution 1:[1]

--detectOpenHandles makes the test run synchronously.

from jest docs:

--detectOpenHandles

Attempt to collect and print open handles preventing Jest from exiting cleanly. Use this in cases where you need to use --forceExit in order for Jest to exit to potentially track down the reason. This implies --runInBand, making tests run serially. Implemented using async_hooks. This option has a significant performance penalty and should only be used for debugging.

https://jestjs.io/docs/cli

You must remove it to run tests in parallel

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bob Lozano