Skip to content

Commit

Permalink
Merge pull request #37304 from VickyStash/ts-migration/tests-g7
Browse files Browse the repository at this point in the history
[TS migration] Migrate 'sleep.js', 'NativeCommandsAction.js', 'wrapOnyxWithWaitForBatchedUpdates.js', 'waitForNetworkPromises.js' and 'waitForBatchedUpdates.js' tests to TypeScript
  • Loading branch information
youssef-lr authored Mar 4, 2024
2 parents dcdc8eb + 5500a19 commit 07133ba
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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,
});

Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/utils/sleep.js → tests/e2e/utils/sleep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default function sleep(ms) {
function sleep(ms: number): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

export default sleep;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import getIsUsingFakeTimers from './getIsUsingFakeTimers';
* than to do
* ❌ Onyx.merge(...)
* waitForBatchedUpdates().then(...)
*
* @returns {Promise}
*/
export default () =>
const waitForBatchedUpdates = (): Promise<void> =>
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,
Expand All @@ -38,3 +36,5 @@ export default () =>
setTimeout(outerResolve, 0);
});
});

export default waitForBatchedUpdates;
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => waitForBatchedUpdates().then(waitForBatchedUpdates);

export default waitForNetworkPromises;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type Onyx from 'react-native-onyx';
import waitForBatchedUpdates from './waitForBatchedUpdates';

/**
Expand All @@ -7,14 +8,14 @@ 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));
const mergeImpl = onyxInstance.merge;
// eslint-disable-next-line no-param-reassign
onyxInstance.merge = (...args) => mergeImpl(...args).then((result) => waitForBatchedUpdates().then(() => result));
}

export default wrapOnyxWithWaitForBatchedUpdates;

0 comments on commit 07133ba

Please sign in to comment.