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

[reJest] waitForAnimationUpdates #6236

Merged
merged 5 commits into from
Jul 16, 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
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ export class TestRunner {
}
return global.mockedAnimationTimestamp;
};
global.framesCount = 0;

const originalRequestAnimationFrame = global.requestAnimationFrame;
global.originalRequestAnimationFrame = originalRequestAnimationFrame;
Expand All @@ -452,6 +453,7 @@ export class TestRunner {
global.mockedAnimationTimestamp! += 16;
global.__frameTimestamp = global.mockedAnimationTimestamp;
global.originalFlushAnimationFrame!(global.mockedAnimationTimestamp!);
global.framesCount!++;
};
});
}
Expand Down Expand Up @@ -498,6 +500,9 @@ export class TestRunner {
if (global.mockedAnimationTimestamp) {
global.mockedAnimationTimestamp = undefined;
}
if (global.framesCount) {
global.framesCount = undefined;
}
});
}

Expand All @@ -507,6 +512,25 @@ export class TestRunner {
});
}

public waitForAnimationUpdates(updatesCount: number): Promise<boolean> {
const CHECK_INTERVAL = 20;
const flag = makeMutable(false);
return new Promise<boolean>(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;
piaskowyk marked this conversation as resolved.
Show resolved Hide resolved
});
if (flag.value) {
clearInterval(interval);
resolve(true);
}
}, CHECK_INTERVAL);
});
}

private printSummary() {
const { passed, failed, failedTests, startTime, endTime, skipped } = this._summary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down