diff --git a/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/RuntimeTestsApi.ts b/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/RuntimeTestsApi.ts index 1de8953de76..e8ab86fc59f 100644 --- a/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/RuntimeTestsApi.ts +++ b/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/RuntimeTestsApi.ts @@ -145,6 +145,10 @@ export async function wait(delay: number) { return testRunner.wait(delay); } +export async function waitForAnimationUpdates(updatesCount: number) { + return testRunner.waitForAnimationUpdates(updatesCount); +} + // eslint-disable-next-line @typescript-eslint/unbound-method const testRunnerNotifyFn = testRunner.notify; export function notify(name: string) { diff --git a/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/TestRunner.ts b/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/TestRunner.ts index 2b1a213e127..f01c7dfbfd5 100644 --- a/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/TestRunner.ts +++ b/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/TestRunner.ts @@ -437,6 +437,7 @@ export class TestRunner { } return global.mockedAnimationTimestamp; }; + global.framesCount = 0; const originalRequestAnimationFrame = global.requestAnimationFrame; global.originalRequestAnimationFrame = originalRequestAnimationFrame; @@ -452,6 +453,7 @@ export class TestRunner { global.mockedAnimationTimestamp! += 16; global.__frameTimestamp = global.mockedAnimationTimestamp; global.originalFlushAnimationFrame!(global.mockedAnimationTimestamp!); + global.framesCount!++; }; }); } @@ -498,6 +500,9 @@ export class TestRunner { if (global.mockedAnimationTimestamp) { global.mockedAnimationTimestamp = undefined; } + if (global.framesCount) { + global.framesCount = undefined; + } }); } @@ -507,6 +512,25 @@ export class TestRunner { }); } + public waitForAnimationUpdates(updatesCount: number): Promise { + const CHECK_INTERVAL = 20; + const flag = makeMutable(false); + return new Promise(resolve => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + const interval = setInterval(async () => { + await new SyncUIRunner().runOnUIBlocking(() => { + 'worklet'; + assertMockedAnimationTimestamp(global.framesCount); + flag.value = global.framesCount >= updatesCount - 1; + }); + if (flag.value) { + clearInterval(interval); + resolve(true); + } + }, CHECK_INTERVAL); + }); + } + private printSummary() { const { passed, failed, failedTests, startTime, endTime, skipped } = this._summary; diff --git a/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/types.ts b/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/types.ts index 1e2f5cd5d38..974707856ac 100644 --- a/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/types.ts +++ b/apps/common-app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/types.ts @@ -121,6 +121,7 @@ export type Mismatch = { /* eslint-disable no-var */ declare global { var mockedAnimationTimestamp: number | undefined; + var framesCount: number | undefined; var originalRequestAnimationFrame: ((callback: (timestamp: number) => void) => void) | undefined; var originalGetAnimationTimestamp: (() => number) | undefined; var originalUpdateProps: ((operations: Operation[]) => void) | undefined;