From 095b798c279fb9bcc18790ded306a7858d954aa4 Mon Sep 17 00:00:00 2001 From: Ruturaj-Browserstack Date: Fri, 3 Apr 2026 17:39:52 +0530 Subject: [PATCH] fix: mock sharp in tests to prevent CI failure on linux sharp is a native binary module that fails to load in CI (ubuntu-latest) when platform-specific binaries aren't installed. Mock it globally in test setup since tests don't need actual image compression. Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/setup.ts | 10 ++++++++++ vite.config.ts | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/setup.ts diff --git a/tests/setup.ts b/tests/setup.ts new file mode 100644 index 00000000..b56b9f4a --- /dev/null +++ b/tests/setup.ts @@ -0,0 +1,10 @@ +import { vi } from "vitest"; + +// Mock sharp globally — it's a native binary module that may not be available in CI +vi.mock("sharp", () => ({ + default: vi.fn().mockReturnValue({ + png: vi.fn().mockReturnValue({ + toBuffer: vi.fn().mockResolvedValue(Buffer.from("mock-image")), + }), + }), +})); diff --git a/vite.config.ts b/vite.config.ts index 98282319..ed038a76 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,7 +4,6 @@ import { defineConfig } from 'vite' export default defineConfig({ test: { - /* for example, use global to avoid globals imports (describe, test, expect): */ - // globals: true, + setupFiles: ['./tests/setup.ts'], }, }) \ No newline at end of file