Skip to content

Automate browser based workflows with AI

fix(frontend): port vitest.setup.ts + wire setupFiles config (#6207)

Trevor Cheungd723dcb60404
diff --git a/skyvern-frontend/tsconfig.json b/skyvern-frontend/tsconfig.json
index 20bbc930f..1dee07761 100644
--- a/skyvern-frontend/tsconfig.json
+++ b/skyvern-frontend/tsconfig.json
@@ -27,6 +27,6 @@
"@/*": ["./src/*"]
}
},
- "include": ["./src/", "vite-env.d.ts"],
+ "include": ["./src/", "vite-env.d.ts", "vitest.setup.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}
diff --git a/skyvern-frontend/vitest.config.ts b/skyvern-frontend/vitest.config.ts
index 81d92d568..6a8a02460 100644
--- a/skyvern-frontend/vitest.config.ts
+++ b/skyvern-frontend/vitest.config.ts
@@ -20,6 +20,7 @@ export default defineConfig({
VITE_WSS_BASE_URL: "ws://localhost:8000/api/v1",
VITE_ENVIRONMENT: "test",
},
+ setupFiles: "./vitest.setup.ts",
},
resolve: {
alias: {
diff --git a/skyvern-frontend/vitest.setup.ts b/skyvern-frontend/vitest.setup.ts
new file mode 100644
index 000000000..bb03b615f
--- /dev/null
+++ b/skyvern-frontend/vitest.setup.ts
@@ -0,0 +1,47 @@
+type StorageRecord = Record<string, string>;
+
+const createMemoryStorage = (): Storage => {
+ let values: StorageRecord = {};
+
+ return {
+ get length() {
+ return Object.keys(values).length;
+ },
+ clear() {
+ values = {};
+ },
+ getItem(key: string) {
+ return Object.prototype.hasOwnProperty.call(values, key)
+ ? (values[key] ?? null)
+ : null;
+ },
+ key(index: number) {
+ return Object.keys(values)[index] ?? null;
+ },
+ removeItem(key: string) {
+ delete values[key];
+ },
+ setItem(key: string, value: string) {
+ values[key] = String(value);
+ },
+ };
+};
+
+const localStorageNeedsShim =
+ typeof globalThis.localStorage?.clear !== "function" ||
+ typeof window.localStorage?.clear !== "function" ||
+ typeof globalThis.localStorage?.setItem !== "function" ||
+ typeof window.localStorage?.setItem !== "function";
+
+if (localStorageNeedsShim) {
+ const storage = createMemoryStorage();
+
+ Object.defineProperty(globalThis, "localStorage", {
+ configurable: true,
+ value: storage,
+ });
+ Object.defineProperty(window, "localStorage", {
+ configurable: true,
+ value: storage,
+ });
+}