Retry Launch App

PHOTO EMBED

Mon Mar 28 2022 22:11:16 GMT+0000 (Coordinated Universal Time)

Saved by @gnarwall19

import { retry } from 'ts-retry-promise';

const buildDetoxURLBlacklistRegex = () =>
  `(${constants.BLACKLISTED_URLS.map(urlRegex => `\\"${urlRegex}\\"`).join(',')})`;

export const launchApp = async () => {
  await retry(
    async () => {
      try {
        await device.launchApp({
          newInstance: true,
          launchArgs: {
            detoxPrintBusyIdleResources: 'YES',
            detoxURLBlacklistRegex: buildDetoxURLBlacklistRegex(),
          },
        });
      } catch (error) {
        error.message = `Failed to launch app with error: ${error.message}`;
        throw error;
      }
    },
    { retries: 5 },
  );
};

export const reloadReactNative = async () => {
  await retry(
    async () => {
      try {
        await device.reloadReactNative();
      } catch (error) {
        // eslint-disable-next-line no-console
        console.error('Failed to reload react native with error', error);
        await launchApp();
      }
    },
    { retries: 5 },
  );
};
content_copyCOPY

https://github.com/wix/DetoxSync/issues/5