Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
Cleaning up detox in cucumber run

I'm using detox with cucumber and the setup works great until the last moment of calling AfterAll hooks. In the hook I do the following:

AfterAll(async () => {
  console.log('CLEANING DETOX');
  await detox.cleanup();
});

To run cucumber I use the following script from package.json:

"bdd": "cucumber-js --require-module @babel/register",

The problem happens when I interrupt cucumber run for any reason. AfterAll hook won't run in this case and detox won't clear its stale files. Which wouldn't be a problem but detox is using ~/Library/Detox/device.registry.state.lock file to track which simulators are being used by runner. Essentially, this leads to detox constantly launching new simulator devices as this file never gets cleared. I thought, I could just create a simple wrapper script:

const { execSync } = require('child_process');
const detox = require('detox');

const stdout = execSync('cucumber-js --require-module @babel/register');
process.on('SIGINT', async function () {
  console.log('Cleanig up detox');
  await detox.cleanup();
});
console.log(stdout);

However, that didn't work either as detox.cleanup() only removes the file when it has detox.device setup. Which happens in BeforeAll hook:

BeforeAll({ timeout: 120 * 1000 }, async () => {
  const detoxConfig = { selectedConfiguration: 'ios.debug2' };
  // console.log('CONFIG::', detoxConfig);
  await detox.init(detoxConfig);
  await detox.device.launchApp();
});

My only idea left is to manually clear the file - I should be able to grab lock file path from detox internal somehow - my worry about this approach is tight dependency on detox implementation. Which is why I would rather call detox.cleanup.

EDIT: Ended up doing this workaround for now:

BeforeAll({ timeout: 120 * 1000 }, async () => {
  await startDetox();
});
async function startDetox() {
  const detoxConfig = { selectedConfiguration: 'ios.debug' };

  const lockFile = getDeviceLockFilePathIOS();
  unlink(lockFile, (err) => {
    if (err) {
      console.debug('Lock file was not deleted:::', err);
    }
  });
  await detox.init(detoxConfig);
  await detox.device.launchApp();
}

Wonder if anyone has a better idea ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!