From 494ae53cc0e07e8ebd72d9b2d7736c8e1b538ea3 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 27 Feb 2024 15:00:10 +0100 Subject: [PATCH 1/2] [TS migration] Migrate 'sleep.js' and 'NativeCommandsAction.js' tests --- src/libs/E2E/client.ts | 2 ++ .../{NativeCommandsAction.js => NativeCommandsAction.ts} | 8 +++++--- tests/e2e/utils/{sleep.js => sleep.ts} | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) rename tests/e2e/nativeCommands/{NativeCommandsAction.js => NativeCommandsAction.ts} (62%) rename tests/e2e/utils/{sleep.js => sleep.ts} (54%) diff --git a/src/libs/E2E/client.ts b/src/libs/E2E/client.ts index 265c55c4a230..f5b4237f6b7e 100644 --- a/src/libs/E2E/client.ts +++ b/src/libs/E2E/client.ts @@ -113,3 +113,5 @@ export default { updateNetworkCache, getNetworkCache, }; + +export type {NativeCommand}; diff --git a/tests/e2e/nativeCommands/NativeCommandsAction.js b/tests/e2e/nativeCommands/NativeCommandsAction.ts similarity index 62% rename from tests/e2e/nativeCommands/NativeCommandsAction.js rename to tests/e2e/nativeCommands/NativeCommandsAction.ts index 24ceefb5acb7..17187ca66f1c 100644 --- a/tests/e2e/nativeCommands/NativeCommandsAction.js +++ b/tests/e2e/nativeCommands/NativeCommandsAction.ts @@ -1,17 +1,19 @@ +import type {NativeCommand} from '@libs/E2E/client'; + const NativeCommandsAction = { scroll: 'scroll', type: 'type', backspace: 'backspace', -}; +} as const; -const makeTypeTextCommand = (text) => ({ +const makeTypeTextCommand = (text: string): NativeCommand => ({ actionName: NativeCommandsAction.type, payload: { text, }, }); -const makeBackspaceCommand = () => ({ +const makeBackspaceCommand = (): NativeCommand => ({ actionName: NativeCommandsAction.backspace, }); diff --git a/tests/e2e/utils/sleep.js b/tests/e2e/utils/sleep.ts similarity index 54% rename from tests/e2e/utils/sleep.js rename to tests/e2e/utils/sleep.ts index 6d37ca3cd510..c3f7142a898f 100644 --- a/tests/e2e/utils/sleep.js +++ b/tests/e2e/utils/sleep.ts @@ -1,5 +1,7 @@ -export default function sleep(ms) { +function sleep(ms: number): Promise { return new Promise((resolve) => { setTimeout(resolve, ms); }); } + +export default sleep; From 906f5df9472826fd0e9ed53407ca96dc9e535935 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 27 Feb 2024 15:25:56 +0100 Subject: [PATCH 2/2] [TS migration] Migrate 'wrapOnyxWithWaitForBatchedUpdates.js', 'waitForNetworkPromises.js' and 'waitForBatchedUpdates.js' tests --- .../{waitForBatchedUpdates.js => waitForBatchedUpdates.ts} | 6 +++--- ...waitForNetworkPromises.js => waitForNetworkPromises.ts} | 6 +++--- ...chedUpdates.js => wrapOnyxWithWaitForBatchedUpdates.ts} | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) rename tests/utils/{waitForBatchedUpdates.js => waitForBatchedUpdates.ts} (94%) rename tests/utils/{waitForNetworkPromises.js => waitForNetworkPromises.ts} (74%) rename tests/utils/{wrapOnyxWithWaitForBatchedUpdates.js => wrapOnyxWithWaitForBatchedUpdates.ts} (84%) diff --git a/tests/utils/waitForBatchedUpdates.js b/tests/utils/waitForBatchedUpdates.ts similarity index 94% rename from tests/utils/waitForBatchedUpdates.js rename to tests/utils/waitForBatchedUpdates.ts index c9d7a99fa1fb..8455371093d8 100644 --- a/tests/utils/waitForBatchedUpdates.js +++ b/tests/utils/waitForBatchedUpdates.ts @@ -10,10 +10,8 @@ import getIsUsingFakeTimers from './getIsUsingFakeTimers'; * than to do * ❌ Onyx.merge(...) * waitForBatchedUpdates().then(...) - * - * @returns {Promise} */ -export default () => +const waitForBatchedUpdates = (): Promise => new Promise((outerResolve) => { // We first need to exhaust the microtask queue, before we schedule the next task in the macrotask queue (setTimeout). // This is because we need to wait for all async onyx operations to finish, as they might schedule other macrotasks, @@ -38,3 +36,5 @@ export default () => setTimeout(outerResolve, 0); }); }); + +export default waitForBatchedUpdates; diff --git a/tests/utils/waitForNetworkPromises.js b/tests/utils/waitForNetworkPromises.ts similarity index 74% rename from tests/utils/waitForNetworkPromises.js rename to tests/utils/waitForNetworkPromises.ts index a60061d597e3..8c35514b870e 100644 --- a/tests/utils/waitForNetworkPromises.js +++ b/tests/utils/waitForNetworkPromises.ts @@ -8,7 +8,7 @@ import waitForBatchedUpdates from './waitForBatchedUpdates'; * than to do * ❌ Onyx.merge(...) * waitForBatchedUpdates().then(...) - * - * @returns {Promise} */ -export default () => waitForBatchedUpdates().then(waitForBatchedUpdates); +const waitForNetworkPromises = (): Promise => waitForBatchedUpdates().then(waitForBatchedUpdates); + +export default waitForNetworkPromises; diff --git a/tests/utils/wrapOnyxWithWaitForBatchedUpdates.js b/tests/utils/wrapOnyxWithWaitForBatchedUpdates.ts similarity index 84% rename from tests/utils/wrapOnyxWithWaitForBatchedUpdates.js rename to tests/utils/wrapOnyxWithWaitForBatchedUpdates.ts index e5b6e6bfdfcf..862f3281b2b8 100644 --- a/tests/utils/wrapOnyxWithWaitForBatchedUpdates.js +++ b/tests/utils/wrapOnyxWithWaitForBatchedUpdates.ts @@ -1,3 +1,4 @@ +import type Onyx from 'react-native-onyx'; import waitForBatchedUpdates from './waitForBatchedUpdates'; /** @@ -7,10 +8,8 @@ import waitForBatchedUpdates from './waitForBatchedUpdates'; * are rendered with the onyx data. * This is a convinience function, which wraps the onyxInstance's * functions, to for the promises to resolve. - * - * @param {Object} onyxInstance */ -export default function wrapOnyxWithWaitForBatchedUpdates(onyxInstance) { +function wrapOnyxWithWaitForBatchedUpdates(onyxInstance: typeof Onyx) { const multiSetImpl = onyxInstance.multiSet; // eslint-disable-next-line no-param-reassign onyxInstance.multiSet = (...args) => multiSetImpl(...args).then((result) => waitForBatchedUpdates().then(() => result)); @@ -18,3 +17,5 @@ export default function wrapOnyxWithWaitForBatchedUpdates(onyxInstance) { // eslint-disable-next-line no-param-reassign onyxInstance.merge = (...args) => mergeImpl(...args).then((result) => waitForBatchedUpdates().then(() => result)); } + +export default wrapOnyxWithWaitForBatchedUpdates;