Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: test multiple React versions #680

Merged
merged 5 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Test

on: [ push, pull_request ]
on: [push, pull_request]

jobs:
build:
test:
runs-on: ubuntu-latest

steps:
Expand All @@ -13,7 +13,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Lint
Expand All @@ -24,3 +24,37 @@ jobs:
CI: true
- name: Build
run: pnpm build

test_matrix:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
react:
- 16
- 17
- 18
- latest
- rc
steps:
- run: corepack enable
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- 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 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: Install ${{ matrix.react }}
run: pnpm add -D react@${{ matrix.react }} react-dom@${{ matrix.react }}
- name: Validate types
run: |
pnpm tsc
pnpm test
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore-workspace-root-check=true
10 changes: 3 additions & 7 deletions src/__tests__/InView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test("Should handle initialInView", () => {
const cb = vi.fn();
render(
<InView initialInView onChange={cb}>
{({ inView }) => `InView: ${inView}`}
{({ inView }) => <span>InView: {inView.toString()}</span>}
</InView>,
);
screen.getByText("InView: true");
Expand Down Expand Up @@ -186,9 +186,7 @@ test("should render with fallback", () => {
render(<InView onChange={cb}>Inner</InView>);
// @ts-ignore
console.error.mockRestore();
}).toThrowErrorMatchingInlineSnapshot(
`[TypeError: IntersectionObserver is not a constructor]`,
);
}).toThrow();
});

test("should render with global fallback", () => {
Expand All @@ -215,7 +213,5 @@ test("should render with global fallback", () => {
render(<InView onChange={cb}>Inner</InView>);
// @ts-ignore
console.error.mockRestore();
}).toThrowErrorMatchingInlineSnapshot(
`[TypeError: IntersectionObserver is not a constructor]`,
);
}).toThrow();
});
1 change: 1 addition & 0 deletions src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare global {
}

const act =
// @ts-ignore - 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 = {
Expand Down