DEV: Allow afterFramePaint to be used in tests (#27226)

We need to register a waiter so that `settled()` will wait for `runAfterFramePaint()` callbacks to be run before proceeding.
This commit is contained in:
David Taylor 2024-05-28 13:09:46 +01:00 committed by GitHub
parent 30e963be03
commit 63b7b598cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,8 +1,13 @@
import { registerWaiter } from "@ember/test";
/**
* Runs `callback` shortly after the next browser Frame is produced.
* ref: https://webperf.tips/tip/measuring-paint-time
*/
export default function runAfterFramePaint(callback) {
let done = false;
registerWaiter(() => done);
// Queue a "before Render Steps" callback via requestAnimationFrame.
requestAnimationFrame(() => {
// MessageChannel is one of the highest priority task queues
@ -10,7 +15,10 @@ export default function runAfterFramePaint(callback) {
const messageChannel = new MessageChannel();
// Setup the callback to run in a Task
messageChannel.port1.onmessage = callback;
messageChannel.port1.onmessage = () => {
done = true;
callback();
};
// Queue the Task on the Task Queue
messageChannel.port2.postMessage(undefined);