From a8564b4a9086bf1c01784b3e32c444d92c1b65df Mon Sep 17 00:00:00 2001 From: skalthoff <32023561+skalthoff@users.noreply.github.com> Date: Mon, 24 Nov 2025 17:17:15 -0800 Subject: [PATCH] FIXING BUN JEST (#719) * FIXING BUN JEST * Update Jest configuration and add nitro-fetch mocks for improved testing --- .github/workflows/run-jest-test-suite.yml | 13 ++++++++++++- .gitignore | 1 + jest.config.js | 6 ++++++ jest/setup/nitro-fetch.ts | 21 +++++++++++++++++++++ package.json | 2 +- 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 jest/setup/nitro-fetch.ts diff --git a/.github/workflows/run-jest-test-suite.yml b/.github/workflows/run-jest-test-suite.yml index b3c01bc6..78368855 100644 --- a/.github/workflows/run-jest-test-suite.yml +++ b/.github/workflows/run-jest-test-suite.yml @@ -21,6 +21,17 @@ jobs: with: bun-version: 1.3.2 + - name: ๐Ÿ“ฆ Cache dependencies + uses: actions/cache@v4 + with: + path: | + ~/.bun/install/cache + node_modules + .jest-cache + key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }} + restore-keys: | + ${{ runner.os }}-bun- + - name: ๐Ÿ’ฌ Echo package.json version to Github ENV run: echo VERSION_NUMBER=$(bun -p "require('./package.json').version") >> $GITHUB_ENV @@ -31,7 +42,7 @@ jobs: run: bun tsc - name: ๐Ÿงช Run yarn test - run: bun test + run: CI=true bun run test - name: ๐Ÿฆ‹ Check Styling run: bun run format:check diff --git a/.gitignore b/.gitignore index d1e257bb..d2f0746f 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,7 @@ node_modules/ # testing /coverage +.jest-cache # Yarn #.yarn/* diff --git a/jest.config.js b/jest.config.js index e0b67339..49804ff3 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,6 +2,11 @@ module.exports = { preset: 'react-native', testTimeout: 10000, + + // Performance optimizations for CI + maxWorkers: process.env.CI ? 2 : '50%', + cacheDirectory: '.jest-cache', + setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'], setupFilesAfterEnv: [ './jest/setup/setup.ts', @@ -13,6 +18,7 @@ module.exports = { './jest/setup/rnfs.ts', './jest/setup/rntp.ts', './jest/setup/sentry.ts', + './jest/setup/nitro-fetch.ts', './jest/setup/nitro-image.ts', './jest/setup/nitro-ota.ts', './tamagui.config.ts', diff --git a/jest/setup/nitro-fetch.ts b/jest/setup/nitro-fetch.ts new file mode 100644 index 00000000..ba8ede5a --- /dev/null +++ b/jest/setup/nitro-fetch.ts @@ -0,0 +1,21 @@ +// Mock for react-native-nitro-fetch +jest.mock('react-native-nitro-fetch', () => ({ + nitroFetchOnWorklet: jest.fn(() => Promise.resolve({})), + nitroFetch: jest.fn(() => Promise.resolve({})), +})) + +// Update the nitro-modules mock to include the box method +jest.mock('react-native-nitro-modules', () => { + const actual = jest.requireActual('react-native-nitro-modules') + return { + ...actual, + NitroModules: { + ...actual?.NitroModules, + createModule: jest.fn(), + install: jest.fn(), + createHybridObject: jest.fn(() => ({})), + box: jest.fn((value) => value), // Mock the box method + }, + createNitroModule: jest.fn(), + } +}) diff --git a/package.json b/package.json index 17dc5f31..a33c43c3 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "ios": "react-native run-ios", "lint": "eslint .", "start": "react-native start", - "test": "jest", + "test": "bunx jest", "tsc": "tsc", "codegen": "env DEBUG=metro:* react-native codegen", "clean:ios": "cd ios && pod deintegrate",