Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'sleep.js', 'NativeCommandsAction.js', 'wrapOnyxWithWaitForBatchedUpdates.js', 'waitForNetworkPromises.js' and 'waitForBatchedUpdates.js' tests to TypeScript #37304

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading