From 2c099f8d15f8fe68e90a46bda9f63debc6f1e1aa Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Mon, 6 Jan 2025 04:14:31 +0900 Subject: [PATCH] Fix js/lite/src/custom-element/index.test.ts that has been failing frequently (#10287) * Fix js/lite/src/custom-element/index.test.ts that has been failing frequently * Delete the vite-environment specification --- js/lite/src/custom-element/index.test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/js/lite/src/custom-element/index.test.ts b/js/lite/src/custom-element/index.test.ts index cb180f986d14b..a872dea587488 100644 --- a/js/lite/src/custom-element/index.test.ts +++ b/js/lite/src/custom-element/index.test.ts @@ -1,8 +1,8 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; import { bootstrap_custom_element } from "./index"; -const delay = (ms?: number) => - new Promise((resolve) => setTimeout(resolve, ms)); +const awaitAnimationFrame = () => + new Promise((resolve) => window.requestAnimationFrame(resolve)); describe("bootstrap_custom_element", () => { const create = vi.fn(); @@ -20,7 +20,7 @@ describe("bootstrap_custom_element", () => { import gradio as gr `; - await delay(); // Wait for the requestAnimationFrame to run + await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback expect(create).toHaveBeenCalledWith( expect.objectContaining({ @@ -44,7 +44,7 @@ scipy `; - await delay(); // Wait for the requestAnimationFrame to run + await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback expect(create).toHaveBeenCalledWith( expect.objectContaining({ @@ -75,7 +75,7 @@ scipy `; - await delay(); // Wait for the requestAnimationFrame to run + await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback expect(create).toHaveBeenCalledWith( expect.objectContaining({ @@ -100,7 +100,7 @@ scipy import gradio as gr `; - await delay(); // Wait for the requestAnimationFrame to run + await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback expect(create).toHaveBeenCalledWith( expect.objectContaining({ @@ -119,7 +119,7 @@ scipy `; - await delay(); // Wait for the requestAnimationFrame to run + await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback expect(create).toHaveBeenCalledWith( expect.objectContaining({ @@ -149,7 +149,7 @@ scipy `; - await delay(); // Wait for the requestAnimationFrame to run + await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback expect(create).toHaveBeenCalledWith( expect.objectContaining({