Skip to content

fix: mock sharp in tests to prevent CI failure on linux#261

Merged
gaurav-singh-9227 merged 1 commit intobrowserstack:mainfrom
ruturaj-browserstack:fix/mock-sharp-ci
Apr 3, 2026
Merged

fix: mock sharp in tests to prevent CI failure on linux#261
gaurav-singh-9227 merged 1 commit intobrowserstack:mainfrom
ruturaj-browserstack:fix/mock-sharp-ci

Conversation

@ruturaj-browserstack
Copy link
Copy Markdown
Collaborator

Summary

  • Add global vitest setup file that mocks sharp native binary module
  • Fixes CI test failures on ubuntu-latest where sharp platform-specific binaries aren't installed

Problem

The sharp module is a native binary that requires platform-specific builds. When tests run on CI (ubuntu-latest), the linux-x64 binary may not be available, causing 3 test suites to fail at import time:

  • tests/tools/appautomate.test.ts
  • tests/tools/rcaAgent.test.ts
  • tests/tools/testmanagement.test.ts

These all transitively import src/lib/utils.ts which has import sharp from "sharp" at the top level.

Fix

  • tests/setup.ts — global vitest setup file that mocks sharp with a no-op implementation
  • vite.config.ts — points vitest to the setup file via setupFiles

Tests don't need actual image compression, so mocking is the correct approach. No CI config changes or production code changes needed.

Test Plan

  • All 123 unit tests pass locally
  • Lint and TypeScript compilation clean
  • No production code changes

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) <noreply@anthropic.com>
@gaurav-singh-9227 gaurav-singh-9227 merged commit 0ddc47b into browserstack:main Apr 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants