[FIX] tests: fix cause of non determinism

Since commit 7e4baf6, some tests were failing non deterministically. It
seems like the root cause for the problem is that the nextTick method
was sometimes completed too early.

From my understanding of the problem, the nextTick method was correct,
however it is running in a jest test, in node, which simulates the
requestanimationframe behaviour, probably not perfectly.

Switching to an alternate implementation, which swaps the setTimeout and
the requestanimationframe seems to be more solid.

Note that this commit had to introduce the nextFrame method as well,
because the animation tests really seems to want to be in the next
frame, not in a callback executed in the same frame, but at the end.

closes #757
This commit is contained in:
Géry Debongnie
2020-10-19 21:33:51 +02:00
committed by aab-odoo
parent 4a2d019161
commit ed9d820d9e
2 changed files with 16 additions and 11 deletions
+8 -3
View File
@@ -37,8 +37,13 @@ export function nextMicroTick(): Promise<void> {
}
export async function nextTick(): Promise<void> {
await new Promise((resolve) => scheduler.requestAnimationFrame(resolve));
await new Promise((resolve) => setTimeout(resolve));
await new Promise((resolve) => scheduler.requestAnimationFrame(resolve));
}
export async function nextFrame(): Promise<void> {
await new Promise((resolve) => scheduler.requestAnimationFrame(resolve));
await new Promise((resolve) => scheduler.requestAnimationFrame(resolve));
}
export function makeTestFixture() {
@@ -127,7 +132,7 @@ export function renderToString(
// is useful for animations tests, as we hook before repaints to trigger
// animations (thanks to requestAnimationFrame). Patching nextFrame allows to
// simulate calls to this hook. One must not forget to unpatch afterwards.
let nextFrame = QWeb.utils.nextFrame;
let _nextFrame = QWeb.utils.nextFrame;
export function patchNextFrame(f: Function) {
QWeb.utils.nextFrame = (cb: () => void) => {
setTimeout(() => f(cb));
@@ -135,7 +140,7 @@ export function patchNextFrame(f: Function) {
}
export function unpatchNextFrame() {
QWeb.utils.nextFrame = nextFrame;
QWeb.utils.nextFrame = _nextFrame;
}
export async function editInput(input: HTMLInputElement | HTMLTextAreaElement, value: string) {