Skip to content

Write HTML. Render video. Built for agents.

test(studio): bundle the real-Chrome undo test with esbuild so its setup fits on Windows (#5080)

Miguel Ángelb9998dd5a823
diff --git a/bun.lock b/bun.lock
index 6b628247d4..1a3620f306 100644
--- a/bun.lock
+++ b/bun.lock
@@ -354,6 +354,7 @@
"@types/react-dom": "19",
"@vitejs/plugin-react": "^4.0.0",
"chokidar": "^4.0.3",
+ "esbuild": "^0.25.12",
"fake-indexeddb": "^6.2.5",
"puppeteer-core": "^25.2.1",
"tailwindcss": "^4.3.3",
diff --git a/packages/studio/package.json b/packages/studio/package.json
index 29512279ff..9a184cc1a8 100644
--- a/packages/studio/package.json
+++ b/packages/studio/package.json
@@ -122,6 +122,7 @@
"@types/react-dom": "19",
"@vitejs/plugin-react": "^4.0.0",
"chokidar": "^4.0.3",
+ "esbuild": "^0.25.12",
"fake-indexeddb": "^6.2.5",
"puppeteer-core": "^25.2.1",
"tailwindcss": "^4.3.3",
diff --git a/packages/studio/src/utils/gsapUndoRestore.browser.test.ts b/packages/studio/src/utils/gsapUndoRestore.browser.test.ts
index 58d1b0a342..a3d20a2a0f 100644
--- a/packages/studio/src/utils/gsapUndoRestore.browser.test.ts
+++ b/packages/studio/src/utils/gsapUndoRestore.browser.test.ts
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import puppeteer, { type Browser } from "puppeteer-core";
-import { build } from "vite";
+import { build, type Plugin } from "esbuild";
import { afterAll, beforeAll, expect, it, vi } from "vitest";
import { findSystemChrome } from "../../vite.browser";
import { writeFixture } from "../../tests/e2e/edit-accuracy/grid.mjs";
@@ -18,20 +18,29 @@ let browser: Browser;
let undoBundle: string;
let softReloadBundle: string;
+// recast imports these, and its code that uses them is dropped from the bundle. A new
+// built-in fails the build instead of turning into an empty module the way Vite makes it.
+const emptyNodeBuiltins: Plugin = {
+ name: "empty-node-builtins",
+ setup(build) {
+ build.onResolve({ filter: /^(node:)?(fs|os)$/ }, ({ path }) => ({ path, namespace: "empty" }));
+ build.onLoad({ filter: /.*/, namespace: "empty" }, () => ({ contents: "module.exports = {}" }));
+ },
+};
+
async function bundle(file: string, name: string): Promise<string> {
const out = await build({
- configFile: false,
- logLevel: "silent",
- resolve: {
- alias: { canvas: fileURLToPath(new URL("../shims/canvasBrowserStub.js", import.meta.url)) },
- },
- build: {
- write: false,
- minify: false,
- lib: { entry: fileURLToPath(new URL(file, import.meta.url)), formats: ["iife"], name },
- },
+ entryPoints: [fileURLToPath(new URL(file, import.meta.url))],
+ bundle: true,
+ write: false,
+ platform: "browser",
+ format: "iife",
+ globalName: name,
+ alias: { canvas: fileURLToPath(new URL("../shims/canvasBrowserStub.js", import.meta.url)) },
+ plugins: [emptyNodeBuiltins],
+ define: { "import.meta.env": "{}" },
});
- return (Array.isArray(out) ? out[0]! : (out as { output: [{ code: string }] })).output[0].code;
+ return out.outputFiles[0]!.text;
}
beforeAll(async () => {