Skip to content

Commit b575376

Browse files
authored
ci: test multiple React versions (#680)
* ci: run multiple versions, to ensure it works with all versions
1 parent 01c9992 commit b575376

4 files changed

Lines changed: 42 additions & 10 deletions

File tree

.github/workflows/test.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Test
22

3-
on: [ push, pull_request ]
3+
on: [push, pull_request]
44

55
jobs:
6-
build:
6+
test:
77
runs-on: ubuntu-latest
88

99
steps:
@@ -13,7 +13,7 @@ jobs:
1313
uses: actions/setup-node@v4
1414
with:
1515
node-version: 20
16-
cache: 'pnpm'
16+
cache: "pnpm"
1717
- name: Install dependencies
1818
run: pnpm install
1919
- name: Lint
@@ -24,3 +24,37 @@ jobs:
2424
CI: true
2525
- name: Build
2626
run: pnpm build
27+
28+
test_matrix:
29+
runs-on: ubuntu-latest
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
react:
34+
- 16
35+
- 17
36+
- 18
37+
- latest
38+
- rc
39+
steps:
40+
- run: corepack enable
41+
- uses: actions/checkout@v4
42+
- name: Setup Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: 20
46+
cache: "pnpm"
47+
- name: Install dependencies
48+
run: pnpm install
49+
- name: Install legacy testing-library
50+
if: ${{ startsWith(matrix.react, '16') || startsWith(matrix.react, '17') }}
51+
run: pnpm add -D @testing-library/react@12.1.4
52+
- name: Install legacy React types
53+
if: ${{ startsWith(matrix.react, '16') || startsWith(matrix.react, '17') || startsWith(matrix.react, '18') }}
54+
run: pnpm add -D @types/react@${{ matrix.react }} @types/react-dom@${{ matrix.react }}
55+
- name: Install ${{ matrix.react }}
56+
run: pnpm add -D react@${{ matrix.react }} react-dom@${{ matrix.react }}
57+
- name: Validate types
58+
run: |
59+
pnpm tsc
60+
pnpm test

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore-workspace-root-check=true

src/__tests__/InView.test.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test("Should handle initialInView", () => {
5757
const cb = vi.fn();
5858
render(
5959
<InView initialInView onChange={cb}>
60-
{({ inView }) => `InView: ${inView}`}
60+
{({ inView }) => <span>InView: {inView.toString()}</span>}
6161
</InView>,
6262
);
6363
screen.getByText("InView: true");
@@ -186,9 +186,7 @@ test("should render with fallback", () => {
186186
render(<InView onChange={cb}>Inner</InView>);
187187
// @ts-ignore
188188
console.error.mockRestore();
189-
}).toThrowErrorMatchingInlineSnapshot(
190-
`[TypeError: IntersectionObserver is not a constructor]`,
191-
);
189+
}).toThrow();
192190
});
193191

194192
test("should render with global fallback", () => {
@@ -215,7 +213,5 @@ test("should render with global fallback", () => {
215213
render(<InView onChange={cb}>Inner</InView>);
216214
// @ts-ignore
217215
console.error.mockRestore();
218-
}).toThrowErrorMatchingInlineSnapshot(
219-
`[TypeError: IntersectionObserver is not a constructor]`,
220-
);
216+
}).toThrow();
221217
});

src/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ declare global {
66
}
77

88
const act =
9+
// @ts-ignore - Older versions of React don't have the `act` method, so TypeScript will complain about it
910
typeof React.act === "function" ? React.act : DeprecatedReactTestUtils.act;
1011

1112
type Item = {

0 commit comments

Comments
 (0)