From 4ee3469f4c667428f8281a6d128888ff7e83c957 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Sat, 8 Jun 2024 15:40:45 +0200 Subject: [PATCH] ci: test React 15 --- .github/workflows/test.yml | 19 +++++++++++++------ src/__tests__/InView.test.tsx | 2 +- src/test-utils.ts | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f7070e4f..45d33572 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,7 @@ jobs: fail-fast: false matrix: react: + - 15 - 16 - 17 - 18 @@ -49,11 +50,17 @@ jobs: - name: Install legacy testing-library if: ${{ startsWith(matrix.react, '16') || startsWith(matrix.react, '17') }} run: pnpm add -D @testing-library/react@12.1.4 - - name: Install legacy types + - name: Install legacy React types if: ${{ startsWith(matrix.react, '16') || startsWith(matrix.react, '17') || startsWith(matrix.react, '18') }} run: pnpm add -D @types/react@${{ matrix.react }} @types/react-dom@${{ matrix.react }} - - name: Test ${{ matrix.react }} ${{ matrix.devtools-skip }} - run: | - pnpm add -D react@${{ matrix.react }} react-dom@${{ matrix.react }} - pnpm test - pnpm tsc + - name: Install ${{ matrix.react }} + run: pnpm add -D react@${{ matrix.react }} react-dom@${{ matrix.react }} + - name: Validate types + run: pnpm tsc + - name: Test React 15 + # Hooks are not supported in React 15, so skip testing it + if: ${{ startsWith(matrix.react, '15') }} + run: pnpm vitest InView observe setup + - name: Test React + if: ${{ !startsWith(matrix.react, '5') }} + run: pnpm test diff --git a/src/__tests__/InView.test.tsx b/src/__tests__/InView.test.tsx index c75e5baf..46b12e38 100644 --- a/src/__tests__/InView.test.tsx +++ b/src/__tests__/InView.test.tsx @@ -57,7 +57,7 @@ test("Should handle initialInView", () => { const cb = vi.fn(); render( - {({ inView }) => `InView: ${inView}`} + {({ inView }) => InView: {inView.toString()}} , ); screen.getByText("InView: true"); diff --git a/src/test-utils.ts b/src/test-utils.ts index 753aad77..d70226d8 100644 --- a/src/test-utils.ts +++ b/src/test-utils.ts @@ -6,6 +6,7 @@ declare global { } const act = + // @ts-expect-error - Older versions of React don't have the `act` method, so TypeScript will complain about it typeof React.act === "function" ? React.act : DeprecatedReactTestUtils.act; type Item = {