Skip to content

Commit 2c099f8

Browse files
authored
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
1 parent 5ce2832 commit 2c099f8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

js/lite/src/custom-element/index.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { describe, it, expect, vi, beforeEach } from "vitest";
22
import { bootstrap_custom_element } from "./index";
33

4-
const delay = (ms?: number) =>
5-
new Promise((resolve) => setTimeout(resolve, ms));
4+
const awaitAnimationFrame = () =>
5+
new Promise((resolve) => window.requestAnimationFrame(resolve));
66

77
describe("bootstrap_custom_element", () => {
88
const create = vi.fn();
@@ -20,7 +20,7 @@ describe("bootstrap_custom_element", () => {
2020
import gradio as gr
2121
</gradio-lite>
2222
`;
23-
await delay(); // Wait for the requestAnimationFrame to run
23+
await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback
2424

2525
expect(create).toHaveBeenCalledWith(
2626
expect.objectContaining({
@@ -44,7 +44,7 @@ scipy
4444
</gradio-requirements>
4545
</gradio-lite>
4646
`;
47-
await delay(); // Wait for the requestAnimationFrame to run
47+
await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback
4848

4949
expect(create).toHaveBeenCalledWith(
5050
expect.objectContaining({
@@ -75,7 +75,7 @@ scipy
7575
</gradio-requirements>
7676
</gradio-lite>
7777
`;
78-
await delay(); // Wait for the requestAnimationFrame to run
78+
await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback
7979

8080
expect(create).toHaveBeenCalledWith(
8181
expect.objectContaining({
@@ -100,7 +100,7 @@ scipy
100100
import gradio as gr
101101
</gradio-lite>
102102
`;
103-
await delay(); // Wait for the requestAnimationFrame to run
103+
await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback
104104

105105
expect(create).toHaveBeenCalledWith(
106106
expect.objectContaining({
@@ -119,7 +119,7 @@ scipy
119119
</gradio-code>
120120
</gradio-lite>
121121
`;
122-
await delay(); // Wait for the requestAnimationFrame to run
122+
await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback
123123

124124
expect(create).toHaveBeenCalledWith(
125125
expect.objectContaining({
@@ -149,7 +149,7 @@ scipy
149149
</gradio-file>
150150
</gradio-lite>
151151
`;
152-
await delay(); // Wait for the requestAnimationFrame to run
152+
await awaitAnimationFrame(); // Wait for `create` to be called in the `requestAnimationFrame` callback
153153

154154
expect(create).toHaveBeenCalledWith(
155155
expect.objectContaining({

0 commit comments

Comments
 (0)