From 57d00e0bab6c917fbece2859b6acf674bbb21427 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Fri, 16 Jul 2021 03:42:14 -0700 Subject: [PATCH] One sleep to rule them all. Zzz Summary: Boyscouted some code duplication away. Reviewed By: jknoxville Differential Revision: D29731016 fbshipit-source-id: d5f1677a667f032f6e7e031da296be26e1976932 --- desktop/app/src/reducers/notifications.tsx | 2 +- .../appinspect/__tests__/LaunchEmulator.spec.tsx | 2 +- desktop/app/src/utils/Idler.tsx | 3 +-- desktop/app/src/utils/__tests__/Idler.node.tsx | 2 +- desktop/app/src/utils/__tests__/sideEffect.node.tsx | 2 +- desktop/app/src/utils/index.tsx | 11 ----------- desktop/app/src/utils/promiseTimeout.tsx | 10 +--------- .../src/__test__/shared_preferences.spec.tsx | 6 +----- 8 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 desktop/app/src/utils/index.tsx diff --git a/desktop/app/src/reducers/notifications.tsx b/desktop/app/src/reducers/notifications.tsx index 21f0ff4ed..3afa6512e 100644 --- a/desktop/app/src/reducers/notifications.tsx +++ b/desktop/app/src/reducers/notifications.tsx @@ -9,8 +9,8 @@ import {Notification} from 'flipper-plugin'; import {Actions} from './'; -import {getStringFromErrorLike} from '../utils'; import React from 'react'; +import {getStringFromErrorLike} from '../utils/errors'; export const GLOBAL_NOTIFICATION_PLUGIN_ID = 'Flipper'; diff --git a/desktop/app/src/sandy-chrome/appinspect/__tests__/LaunchEmulator.spec.tsx b/desktop/app/src/sandy-chrome/appinspect/__tests__/LaunchEmulator.spec.tsx index 4d60b1852..b6c0d8fe6 100644 --- a/desktop/app/src/sandy-chrome/appinspect/__tests__/LaunchEmulator.spec.tsx +++ b/desktop/app/src/sandy-chrome/appinspect/__tests__/LaunchEmulator.spec.tsx @@ -15,7 +15,7 @@ import {LaunchEmulatorDialog} from '../LaunchEmulator'; import {createRootReducer} from '../../../reducers'; import {act} from 'react-dom/test-utils'; -import {sleep} from '../../../utils'; +import {sleep} from 'flipper-plugin'; jest.mock('../../../devices/AndroidDevice', () => ({ launchEmulator: jest.fn(() => Promise.resolve([])), diff --git a/desktop/app/src/utils/Idler.tsx b/desktop/app/src/utils/Idler.tsx index 0d8c57f35..aea5abcaf 100644 --- a/desktop/app/src/utils/Idler.tsx +++ b/desktop/app/src/utils/Idler.tsx @@ -8,8 +8,7 @@ */ import {CancelledPromiseError} from './errors'; -import {sleep} from './promiseTimeout'; -import {Idler} from 'flipper-plugin'; +import {Idler, sleep} from 'flipper-plugin'; export class IdlerImpl implements Idler { private lastIdle = performance.now(); diff --git a/desktop/app/src/utils/__tests__/Idler.node.tsx b/desktop/app/src/utils/__tests__/Idler.node.tsx index 7fd59a25f..d145312f9 100644 --- a/desktop/app/src/utils/__tests__/Idler.node.tsx +++ b/desktop/app/src/utils/__tests__/Idler.node.tsx @@ -8,7 +8,7 @@ */ import {IdlerImpl, TestIdler} from '../Idler'; -import {sleep} from '../promiseTimeout'; +import {sleep} from 'flipper-plugin'; test('Idler should interrupt', async () => { const idler = new IdlerImpl(); diff --git a/desktop/app/src/utils/__tests__/sideEffect.node.tsx b/desktop/app/src/utils/__tests__/sideEffect.node.tsx index 1c96eb9fa..4ef6a3259 100644 --- a/desktop/app/src/utils/__tests__/sideEffect.node.tsx +++ b/desktop/app/src/utils/__tests__/sideEffect.node.tsx @@ -10,7 +10,7 @@ import {sideEffect} from '../sideEffect'; import {createStore, Store} from 'redux'; import produce from 'immer'; -import {sleep} from '../promiseTimeout'; +import {sleep} from 'flipper-plugin'; jest.useFakeTimers(); diff --git a/desktop/app/src/utils/index.tsx b/desktop/app/src/utils/index.tsx deleted file mode 100644 index 6d5c796a3..000000000 --- a/desktop/app/src/utils/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -export {getStringFromErrorLike} from './errors'; -export {sleep} from './promiseTimeout'; diff --git a/desktop/app/src/utils/promiseTimeout.tsx b/desktop/app/src/utils/promiseTimeout.tsx index 533226dff..432477adc 100644 --- a/desktop/app/src/utils/promiseTimeout.tsx +++ b/desktop/app/src/utils/promiseTimeout.tsx @@ -7,6 +7,7 @@ * @format */ +import {sleep} from 'flipper-plugin'; import {StatusMessageType} from '../reducers/application'; export default function promiseTimeout( @@ -23,15 +24,6 @@ export default function promiseTimeout( return Promise.race([promise, timeout]); } -export function sleep(ms: number): Promise { - return new Promise((resolve) => { - const id = setTimeout(() => { - clearTimeout(id); - resolve(); - }, ms); - }); -} - export function showStatusUpdatesForPromise( promise: Promise, message: string, diff --git a/desktop/plugins/public/shared_preferences/src/__test__/shared_preferences.spec.tsx b/desktop/plugins/public/shared_preferences/src/__test__/shared_preferences.spec.tsx index 2152feeb9..3be17c267 100644 --- a/desktop/plugins/public/shared_preferences/src/__test__/shared_preferences.spec.tsx +++ b/desktop/plugins/public/shared_preferences/src/__test__/shared_preferences.spec.tsx @@ -7,13 +7,9 @@ * @format */ -import {TestUtils} from 'flipper-plugin'; +import {TestUtils, sleep} from 'flipper-plugin'; import * as plugin from '..'; -async function sleep(ms: number) { - return new Promise((resolve) => setTimeout(() => resolve(), ms)); -} - // this testing is inspired by Flipper sample app test('general plugin logic testing', async () => { const {instance, onSend, connect, sendEvent} = TestUtils.startPlugin(plugin, {