Skip to content

Commit 212802d

Browse files
committed
upgrade jest, replace deprecated api
update edge runtime fix json format
1 parent e0426a9 commit 212802d

20 files changed

+1017
-713
lines changed

jest.config.build.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
const config = require("./jest.config");
2-
module.exports = {
1+
import config from './jest.config.js'
2+
3+
const useBuildConfig = {
34
...config,
45
// override to use build files
56
moduleNameMapper: {}
67
}
8+
9+
export default useBuildConfig

jest.config.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
const config = {
22
testEnvironment: 'jsdom',
33
testRegex: '/test/.*\\.test\\.tsx?$',
44
testPathIgnorePatterns: ['/node_modules/', '/e2e/'],
@@ -10,17 +10,20 @@ module.exports = {
1010
'^swr/immutable$': '<rootDir>/src/immutable/index.ts',
1111
'^swr/subscription$': '<rootDir>/src/subscription/index.ts',
1212
'^swr/mutation$': '<rootDir>/src/mutation/index.ts',
13-
'^swr/_internal$': '<rootDir>/src/_internal/index.ts',
13+
'^swr/_internal$': '<rootDir>/src/_internal/index.ts'
1414
},
1515
transform: {
16-
'^.+\\.(t|j)sx?$': ['@swc/jest']
16+
'^.+\\.(t|j)sx?$': '@swc/jest'
1717
},
1818
coveragePathIgnorePatterns: [
1919
'/node_modules/',
2020
'/dist/',
2121
'/test/',
22-
'<rootDir>/src/_internal/utils/env.ts',
22+
'<rootDir>/src/_internal/utils/env.ts'
2323
],
2424
coverageReporters: ['text', 'html'],
2525
reporters: [['github-actions', { silent: false }], 'summary']
2626
}
27+
28+
29+
export default config

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,18 @@
122122
},
123123
"devDependencies": {
124124
"@arethetypeswrong/cli": "^0.18.2",
125-
"@edge-runtime/jest-environment": "^3.0.4",
125+
"@edge-runtime/jest-environment": "^4.0.0",
126126
"@eslint/compat": "^2.0.0",
127127
"@eslint/eslintrc": "^3.3.1",
128128
"@eslint/js": "^9.39.1",
129129
"@playwright/test": "1.57.0",
130130
"@swc/core": "^1.15.3",
131131
"@swc/jest": "0.2.39",
132-
"@testing-library/jest-dom": "^5.16.5",
133-
"@testing-library/react": "^14.2.1",
132+
"@testing-library/dom": "^10.4.1",
133+
"@testing-library/jest-dom": "^6.9.1",
134+
"@testing-library/react": "^16.3.0",
134135
"@type-challenges/utils": "0.1.1",
135-
"@types/jest": "^29.5.2",
136+
"@types/jest": "^30.0.0",
136137
"@types/node": "^22.19.1",
137138
"@types/react": "^19.2.7",
138139
"@types/use-sync-external-store": "^1.5.0",
@@ -147,10 +148,10 @@
147148
"eslint-plugin-testing-library": "7.13.5",
148149
"globals": "^16.5.0",
149150
"husky": "9.1.7",
150-
"jest": "29.7.0",
151-
"jest-environment-jsdom": "29.7.0",
151+
"jest": "30.2.0",
152+
"jest-environment-jsdom": "29.7.0",
152153
"lint-staged": "16.2.7",
153-
"next": "16.0.10",
154+
"next": "16.1.1",
154155
"prettier": "2.8.8",
155156
"react": "^18.2.0",
156157
"react-dom": "^18.2.0",

pnpm-lock.yaml

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

test/unit/web-preset.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ function runTests(propertyName) {
5151
const release = initFocus(fn) as () => void
5252

5353
target.emit(eventName)
54-
expect(fn).toBeCalledTimes(1)
54+
expect(fn).toHaveBeenCalledTimes(1)
5555

5656
release()
5757
target.emit(eventName)
58-
expect(fn).toBeCalledTimes(1)
58+
expect(fn).toHaveBeenCalledTimes(1)
5959
})
6060

6161
it(`should not trigger listener when ${propertyName} is falsy`, async () => {
@@ -79,13 +79,13 @@ function runTests(propertyName) {
7979

8080
target?.emit?.(eventName)
8181

82-
expect(fn).toBeCalledTimes(0)
82+
expect(fn).toHaveBeenCalledTimes(0)
8383

8484
release()
8585
if (target && target.emit) {
8686
target.emit(eventName)
8787
}
88-
expect(fn).toBeCalledTimes(0)
88+
expect(fn).toHaveBeenCalledTimes(0)
8989
})
9090
})
9191
}

test/use-swr-cache.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ describe('useSWR - cache provider', () => {
170170
// revalidateOnFocus won't work
171171
screen.getByText('1')
172172
unmount()
173-
expect(focusFn).toBeCalled()
174-
expect(unsubscribeFocusFn).toBeCalledTimes(1)
175-
expect(unsubscribeReconnectFn).toBeCalledTimes(1)
173+
expect(focusFn).toHaveBeenCalled()
174+
expect(unsubscribeFocusFn).toHaveBeenCalledTimes(1)
175+
expect(unsubscribeReconnectFn).toHaveBeenCalledTimes(1)
176176
})
177177

178178
it('should work with revalidateOnFocus', async () => {
@@ -336,9 +336,9 @@ describe('useSWR - cache provider', () => {
336336
}
337337

338338
renderWithConfig(<Page />)
339-
expect(createCacheProvider).toBeCalledTimes(1)
339+
expect(createCacheProvider).toHaveBeenCalledTimes(1)
340340
act(() => rerender({}))
341-
expect(createCacheProvider).toBeCalledTimes(1)
341+
expect(createCacheProvider).toHaveBeenCalledTimes(1)
342342
})
343343
})
344344

test/use-swr-error.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,11 @@ describe('useSWR - error', () => {
589589
}
590590
renderWithConfig(<App />)
591591
await act(() => sleep(320))
592-
expect(fn).toBeCalledTimes(1)
592+
expect(fn).toHaveBeenCalledTimes(1)
593593
fireEvent.click(screen.getByText('toggle'))
594594
await act(() => sleep(320))
595-
expect(fn).toBeCalledTimes(2)
595+
expect(fn).toHaveBeenCalledTimes(2)
596596
await act(() => sleep(320))
597-
expect(fn).toBeCalledTimes(3)
597+
expect(fn).toHaveBeenCalledTimes(3)
598598
})
599599
})

test/use-swr-immutable.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ describe('useSWR - immutable', () => {
237237
await sleep(20)
238238

239239
// `fetcher` should only be called twice, with each key.
240-
expect(fetcher).toBeCalledTimes(2)
241-
expect(fetcher).nthCalledWith(1, key + '0')
242-
expect(fetcher).nthCalledWith(2, key + '1')
240+
expect(fetcher).toHaveBeenCalledTimes(2)
241+
expect(fetcher).toHaveBeenNthCalledWith(1, key + '0')
242+
expect(fetcher).toHaveBeenNthCalledWith(2, key + '1')
243243
})
244244
})

test/use-swr-infinite-preload.test.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ describe('useSWRInfinite - preload', () => {
3434
}
3535

3636
preload(getKey(0), fetcher)
37-
expect(fetcher).toBeCalledTimes(1)
37+
expect(fetcher).toHaveBeenCalledTimes(1)
3838

3939
renderWithConfig(<Page />)
4040
await screen.findByText('data:foo')
41-
expect(fetcher).toBeCalledTimes(1)
41+
expect(fetcher).toHaveBeenCalledTimes(1)
4242
})
4343

4444
it('should avoid preloading the resource multiple times', async () => {
@@ -54,11 +54,11 @@ describe('useSWRInfinite - preload', () => {
5454
preload(getKey(0), fetcher)
5555
preload(getKey(0), fetcher)
5656
preload(getKey(0), fetcher)
57-
expect(fetcher).toBeCalledTimes(1)
57+
expect(fetcher).toHaveBeenCalledTimes(1)
5858

5959
renderWithConfig(<Page />)
6060
await screen.findByText('data:foo')
61-
expect(fetcher).toBeCalledTimes(1)
61+
expect(fetcher).toHaveBeenCalledTimes(1)
6262
})
6363

6464
it('should be able to prealod resources in effects', async () => {
@@ -84,12 +84,12 @@ describe('useSWRInfinite - preload', () => {
8484
}
8585

8686
renderWithConfig(<Page />)
87-
expect(fetcher).toBeCalledTimes(1)
87+
expect(fetcher).toHaveBeenCalledTimes(1)
8888

8989
fireEvent.click(screen.getByText('click'))
9090

9191
await screen.findByText('data:foo')
92-
expect(fetcher).toBeCalledTimes(1)
92+
expect(fetcher).toHaveBeenCalledTimes(1)
9393
})
9494

9595
it('preload the fetcher function with the suspense mode', async () => {
@@ -103,7 +103,7 @@ describe('useSWRInfinite - preload', () => {
103103
}
104104

105105
preload(getKey(0), fetcher)
106-
expect(fetcher).toBeCalledTimes(1)
106+
expect(fetcher).toHaveBeenCalledTimes(1)
107107

108108
renderWithConfig(
109109
<Suspense
@@ -117,8 +117,8 @@ describe('useSWRInfinite - preload', () => {
117117
</Suspense>
118118
)
119119
await screen.findByText('data:foo')
120-
expect(onRender).toBeCalledTimes(1)
121-
expect(fetcher).toBeCalledTimes(1)
120+
expect(onRender).toHaveBeenCalledTimes(1)
121+
expect(fetcher).toHaveBeenCalledTimes(1)
122122
})
123123

124124
it.skip('avoid suspense waterfall by prefetching the resources', async () => {
@@ -222,18 +222,18 @@ describe('useSWRInfinite - preload', () => {
222222
}
223223

224224
preload(getKey(0), fetcher)
225-
expect(fetcher).toBeCalledTimes(1)
225+
expect(fetcher).toHaveBeenCalledTimes(1)
226226

227227
const { rerender } = renderWithConfig(<Page />)
228-
expect(onRender).toBeCalledTimes(1)
228+
expect(onRender).toHaveBeenCalledTimes(1)
229229
// rerender when the preloading is in-flight, and the deduping interval is over
230230
await act(() => sleep(10))
231231
rerender(<Page />)
232-
expect(onRender).toBeCalledTimes(2)
232+
expect(onRender).toHaveBeenCalledTimes(2)
233233

234234
await screen.findByText('data:foo')
235-
expect(fetcher).toBeCalledTimes(1)
236-
expect(onRender).toBeCalledTimes(3)
235+
expect(fetcher).toHaveBeenCalledTimes(1)
236+
expect(onRender).toHaveBeenCalledTimes(3)
237237
})
238238

239239
it('should pass serialize key to fetcher', async () => {

test/use-swr-infinite.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ describe('useSWRInfinite', () => {
11151115

11161116
fireEvent.click(screen.getByText('mutate'))
11171117
await screen.findByText('data: foo-1')
1118-
expect(fetcher).toBeCalledTimes(2)
1118+
expect(fetcher).toHaveBeenCalledTimes(2)
11191119

11201120
expect(logger).toEqual([undefined, ['foo-0'], ['foo-1']])
11211121
})
@@ -1268,7 +1268,7 @@ describe('useSWRInfinite', () => {
12681268

12691269
fireEvent.click(screen.getByText('mutate'))
12701270
await screen.findByText('data: foo-1')
1271-
expect(fetcher).toBeCalledTimes(2)
1271+
expect(fetcher).toHaveBeenCalledTimes(2)
12721272

12731273
expect(logger).toEqual([undefined, ['foo-0'], ['foo-1']])
12741274
})
@@ -1300,7 +1300,7 @@ describe('useSWRInfinite', () => {
13001300
await screen.findByText('data: foo-0')
13011301

13021302
fireEvent.click(screen.getByText('mutate'))
1303-
expect(fetcher).toBeCalledTimes(1)
1303+
expect(fetcher).toHaveBeenCalledTimes(1)
13041304

13051305
expect(logger).toEqual([undefined, ['foo-0']])
13061306
})

0 commit comments

Comments
 (0)