Skip to content

Commit e84ef60

Browse files
authored
Bump all the things, and remove enzyme (#93)
* bump * Update useRefWithInitialValueFactory.ts * feat: add useIsInitialRenderRef * Update test.yml
1 parent 7bb6d5a commit e84ef60

31 files changed

+4142
-4089
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"modules": false
1010
}
1111
]
12+
1213
]
1314
},
1415
"test": {
15-
"presets": [["@4c", { "development": true }]]
16+
"presets": [["@4c", { "development": true }], "@babel/typescript"]
1617
}
1718
}
1819
}

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup Node.js
1717
uses: actions/setup-node@v1
1818
with:
19-
node-version: 12.x
19+
node-version: 18.x
2020
- name: Install Dependencies
2121
run: yarn bootstrap
2222
- name: Run Tests

package.json

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
},
4242
"jest": {
4343
"preset": "@4c",
44-
"rootDir": "./test",
44+
"testEnvironment": "jsdom",
4545
"setupFilesAfterEnv": [
46-
"./setup.js"
46+
"./test/setup.js"
4747
]
4848
},
4949
"prettier": {
@@ -62,38 +62,37 @@
6262
"react": ">=16.8.0"
6363
},
6464
"devDependencies": {
65-
"@4c/babel-preset": "^7.3.3",
66-
"@4c/cli": "^2.1.12",
67-
"@4c/jest-preset": "^1.5.4",
68-
"@4c/rollout": "^2.1.11",
69-
"@4c/tsconfig": "^0.3.1",
70-
"@babel/cli": "^7.12.10",
71-
"@babel/core": "^7.12.10",
72-
"@babel/preset-typescript": "^7.12.7",
65+
"@4c/babel-preset": "^10.2.1",
66+
"@4c/cli": "^4.0.4",
67+
"@4c/jest-preset": "^1.8.1",
68+
"@4c/rollout": "^4.0.2",
69+
"@4c/tsconfig": "^0.4.1",
70+
"@babel/cli": "^7.22.9",
71+
"@babel/core": "^7.22.9",
72+
"@babel/preset-typescript": "^7.22.5",
73+
"@testing-library/react": "^12.1.5",
7374
"@testing-library/react-hooks": "^7.0.0",
74-
"@types/enzyme": "^3.10.8",
75-
"@types/jest": "^26.0.19",
76-
"@types/lodash": "^4.14.167",
77-
"@types/react": "^17.0.0",
78-
"babel-jest": "^26.6.3",
75+
"@types/jest": "^29.5.3",
76+
"@types/lodash": "^4.14.195",
77+
"@types/react": "^18.2.15",
78+
"babel-jest": "^29.6.1",
7979
"babel-plugin-transform-rename-import": "^2.3.0",
8080
"cherry-pick": "^0.5.0",
81-
"codecov": "^3.8.1",
82-
"enzyme": "^3.10.0",
83-
"enzyme-adapter-react-16": "^1.15.5",
84-
"eslint": "^7.17.0",
81+
"codecov": "^3.8.3",
82+
"eslint": "^8.44.0",
8583
"gh-pages": "^3.1.0",
8684
"husky": "^4.3.6",
87-
"jest": "^26.6.3",
88-
"lint-staged": "^10.5.3",
85+
"jest": "^29.6.1",
86+
"jest-environment-jsdom": "^29.6.1",
87+
"lint-staged": "^13.2.3",
8988
"mq-polyfill": "^1.1.8",
90-
"prettier": "^2.2.1",
89+
"prettier": "^3.0.0",
9190
"react": "^16.13.0",
9291
"react-dom": "^16.13.0",
93-
"rimraf": "^3.0.2",
94-
"typescript": "^4.1.3"
92+
"rimraf": "^5.0.1",
93+
"typescript": "^5.1.6"
9594
},
9695
"dependencies": {
97-
"dequal": "^2.0.2"
96+
"dequal": "^2.0.3"
9897
}
9998
}

src/useForceUpdate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useReducer } from 'react'
1818
*/
1919
export default function useForceUpdate(): () => void {
2020
// The toggling state value is designed to defeat React optimizations for skipping
21-
// updates when they are stricting equal to the last state value
21+
// updates when they are strictly equal to the last state value
2222
const [, dispatch] = useReducer((state: boolean) => !state, false)
2323
return dispatch as () => void
2424
}

src/useIsInitialRenderRef.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useEffect, useLayoutEffect, useRef } from 'react'
2+
3+
/**
4+
* Returns ref that is `true` on the initial render and `false` on subsequent renders. It
5+
* is StrictMode safe, so will reset correctly if the component is unmounted and remounted
6+
*/
7+
export default function useIsInitialRenderRef() {
8+
const isInitialRenderRef = useRef(true)
9+
10+
useLayoutEffect(() => {
11+
isInitialRenderRef.current = false
12+
})
13+
14+
// Strict mode handling in React 18
15+
useEffect(
16+
() => () => {
17+
isInitialRenderRef.current = true
18+
},
19+
[],
20+
)
21+
22+
return isInitialRenderRef
23+
}

src/useMergeStateFromProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type Mapper<TProps, TState> = (
55
state: TState,
66
) => null | Partial<TState>
77

8-
export default function useMergeStateFromProps<TProps, TState>(
8+
export default function useMergeStateFromProps<TProps, TState extends {}>(
99
props: TProps,
1010
gDSFP: Mapper<TProps, TState>,
1111
initialState: TState,

src/useRefWithInitialValueFactory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useRef } from 'react'
22

3-
const dft: any = Symbol('default value sigil')
3+
const dft: unique symbol = Symbol('default value sigil')
44

55
/**
66
* Exactly the same as `useRef` except that the initial value is set via a
7-
* factroy function. Useful when the default is relatively costly to construct.
7+
* factory function. Useful when the default is relatively costly to construct.
88
*
99
* ```ts
1010
* const ref = useRefWithInitialValueFactory<ExpensiveValue>(() => constructExpensiveValue())
@@ -17,7 +17,7 @@ const dft: any = Symbol('default value sigil')
1717
export default function useRefWithInitialValueFactory<T>(
1818
initialValueFactory: () => T,
1919
) {
20-
const ref = useRef<T>(dft)
20+
const ref = useRef<T>(dft as T)
2121
if (ref.current === dft) {
2222
ref.current = initialValueFactory()
2323
}

src/useThrottledEventHandler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export type ThrottledHandler<TEvent> = ((event: TEvent) => void) & {
3838
* @returns The event handler with a `clear` method attached for clearing any in-flight handler calls
3939
*
4040
*/
41-
export default function useThrottledEventHandler<TEvent = SyntheticEvent>(
42-
handler: (event: TEvent) => void,
43-
): ThrottledHandler<TEvent> {
41+
export default function useThrottledEventHandler<
42+
TEvent extends object = SyntheticEvent
43+
>(handler: (event: TEvent) => void): ThrottledHandler<TEvent> {
4444
const isMounted = useMounted()
4545
const eventHandler = useEventCallback(handler)
4646

test/helpers.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { ReactWrapper, mount } from 'enzyme'
1+
import { renderHook as baseRenderHook } from '@testing-library/react-hooks'
22
import React from 'react'
33

4+
type ReactWrapper<P> = {
5+
setProps(props: Partial<P>): void
6+
unmount(): void
7+
}
8+
49
export function renderHook<T extends (props: P) => any, P = any>(
510
fn: T,
611
initialProps?: P,
712
): [ReturnType<T>, ReactWrapper<P>] {
8-
const result = Array(2) as any
9-
10-
function Wrapper(props: any) {
11-
result[0] = fn(props)
12-
return <span />
13-
}
14-
15-
result[1] = mount(<Wrapper {...initialProps} />)
13+
const { rerender, result, unmount } = baseRenderHook(fn, { initialProps })
1614

17-
return result
15+
return [
16+
result.current,
17+
{
18+
unmount,
19+
setProps(props: P) {
20+
rerender({ ...initialProps, ...props })
21+
},
22+
},
23+
]
1824
}

test/setup.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import Enzyme from 'enzyme'
2-
import Adapter from 'enzyme-adapter-react-16'
31
import matchMediaPolyfill from 'mq-polyfill'
42

5-
Enzyme.configure({ adapter: new Adapter() })
6-
73
// https://github.com/bigslycat/mq-polyfill
84

95
if (typeof window !== 'undefined') {
@@ -32,7 +28,7 @@ function onError(e) {
3228
actualErrors += 1
3329
}
3430

35-
expect.errors = num => {
31+
expect.errors = (num) => {
3632
expectedErrors = num
3733
}
3834

0 commit comments

Comments
 (0)