Skip to content

Commit bc0d8f6

Browse files
authored
test: support react strict test (alibaba#1986)
* chore: add cross-env and script `test:strict` * chore: add test ci * test: add strict test util * test(useUnmountedRef): adjust test with util * style: remove console
1 parent 262aa30 commit bc0d8f6

File tree

7 files changed

+80
-4
lines changed

7 files changed

+80
-4
lines changed

.github/workflows/node-ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ jobs:
2323
with:
2424
node-version: ${{ matrix.node-version }}
2525

26-
- name: pnpm run intall, build, and test
26+
- name: pnpm run intall, build
2727
run: |
2828
pnpm run init
29-
pnpm run test
3029
env:
3130
CI: true

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Test CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
matrix:
11+
mode: ['normal', 'strict']
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install pnpm
17+
uses: pnpm/[email protected]
18+
with:
19+
version: 7
20+
21+
- name: Get pnpm store directory
22+
id: pnpm-cache
23+
run: |
24+
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
25+
26+
- name: Setup pnpm cache
27+
uses: actions/cache@v3
28+
with:
29+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
30+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
31+
restore-keys: |
32+
${{ runner.os }}-pnpm-store-
33+
34+
- name: Use Node.js ${{ matrix.node-version }}
35+
uses: actions/setup-node@v3
36+
with:
37+
node-version: ${{ matrix.node-version }}
38+
39+
- name: pnpm run intall, build
40+
run: |
41+
pnpm run init
42+
43+
- name: test with react normal mode
44+
if: ${{ matrix.mode == 'normal' }}
45+
run: |
46+
pnpm run test
47+
48+
- name: test with react strict mode
49+
if: ${{ matrix.mode == 'strict' }}
50+
run: |
51+
pnpm run test:strict

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"pub": "pnpm run build && pnpm -r --filter=./packages/* publish",
2424
"pub:beta": "pnpm run build && pnpm -r --filter=./packages/* publish --tag beta",
2525
"preinstall": "npx only-allow pnpm",
26-
"prepare": "husky install"
26+
"prepare": "husky install",
27+
"test:strict": "cross-env REACT_MODE=strict jest"
2728
},
2829
"devDependencies": {
2930
"@ant-design/icons": "^4.6.2",
@@ -46,6 +47,7 @@
4647
"babel-plugin-import": "^1.12.0",
4748
"babel-plugin-transform-async-to-promises": "^0.8.15",
4849
"coveralls": "^3.1.1",
50+
"cross-env": "^7.0.3",
4951
"del": "^5.1.0",
5052
"dumi": "^1.1.48",
5153
"enzyme": "^3.10.0",

packages/hooks/src/useUnmountedRef/__tests__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react';
1+
import { renderHook } from '../../utils/tests';
22
import useUnmountedRef from '../index';
33

44
describe('useUnmountedRef', () => {
File renamed without changes.

packages/hooks/src/utils/tests.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { StrictMode } from 'react';
2+
import { renderHook } from '@testing-library/react';
3+
4+
export * from '@testing-library/react';
5+
6+
const Wrapper = process.env.REACT_MODE === 'strict' ? StrictMode : undefined;
7+
8+
const customRender: typeof renderHook = (ui, options) =>
9+
renderHook(ui, { wrapper: Wrapper, ...options });
10+
11+
export { customRender as renderHook };

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)