Skip to content

Commit d79b4fe

Browse files
authored
Upgrade jest (#4401)
* Upgrade testing tools
1 parent fb79bc0 commit d79b4fe

File tree

44 files changed

+1978
-1163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1978
-1163
lines changed

lib/jestResolver.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ try {
2424
}
2525

2626
module.exports = (request, options) => {
27-
let resolved = options.defaultResolver(request, options);
27+
let resolved = options.defaultResolver(request, {
28+
...options,
29+
// https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149
30+
packageFilter: pkg => {
31+
delete pkg['exports'];
32+
delete pkg['module'];
33+
return pkg;
34+
}
35+
});
2836
if (/packages\/.*\/.*\/intl\/.*\.json$/.test(resolved)) {
2937
let sourceText = fs.readFileSync(resolved, 'utf8');
3038
let json = JSON.parse(sourceText);

package.json

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
},
1010
"scripts": {
1111
"check-types": "tsc && tsc-strict",
12-
"install-16": "yarn add -W react@^16.8.0 react-dom@^16.8.0 @testing-library/react@^12 @testing-library/react-hooks@^8",
13-
"install-17": "yarn add -W react@^17 react-dom@^17 @testing-library/react@^12 @testing-library/react-hooks@^8",
12+
"install-16": "yarn add -W react@^16.8.0 react-dom@^16.8.0 @testing-library/react@^12 @testing-library/react-hooks@^8 @testing-library/dom@^8",
13+
"install-17": "yarn add -W react@^17 react-dom@^17 @testing-library/react@^12 @testing-library/react-hooks@^8 @testing-library/dom@^8",
1414
"start": "cross-env NODE_ENV=storybook start-storybook -p 9003 --ci -c '.storybook'",
1515
"build:storybook": "build-storybook -c .storybook -o dist/$(git rev-parse HEAD)/storybook",
1616
"build:storybook-16": "build-storybook -c .storybook -o dist/$(git rev-parse HEAD)/storybook-16",
@@ -83,9 +83,9 @@
8383
"@storybook/components": "^6.5.12",
8484
"@storybook/react": "^6.5.12",
8585
"@storybook/testing-react": "^1.3.0",
86-
"@testing-library/dom": "^8.0.0",
87-
"@testing-library/jest-dom": "^5.14.1",
88-
"@testing-library/react": "^13.2.0",
86+
"@testing-library/dom": "^9.2.0",
87+
"@testing-library/jest-dom": "^5.16.5",
88+
"@testing-library/react": "^14.0.0",
8989
"@testing-library/user-event": "^12.1.3",
9090
"@types/react": "^17.0.37",
9191
"@types/storybook__react": "^5.2.1",
@@ -109,26 +109,25 @@
109109
"css-parse": "^2.0.0",
110110
"delta-e": "^0.0.8",
111111
"diff": "^5.1.0",
112-
"eslint": "^8.25.0",
113-
"eslint-plugin-import": "^2.26.0",
114-
"eslint-plugin-jest": "^27.1.1",
115-
"eslint-plugin-jsdoc": "^39.3.6",
116-
"eslint-plugin-jsx-a11y": "^6.6.1",
112+
"eslint": "^8.38.0",
113+
"eslint-plugin-import": "^2.27.5",
114+
"eslint-plugin-jest": "^27.2.1",
115+
"eslint-plugin-jsdoc": "^40.3.0",
116+
"eslint-plugin-jsx-a11y": "^6.7.1",
117117
"eslint-plugin-monorepo": "^0.3.2",
118-
"eslint-plugin-react": "^7.31.10",
118+
"eslint-plugin-react": "^7.32.2",
119119
"eslint-plugin-react-hooks": "^4.6.0",
120-
"eslint-plugin-rulesdir": "^0.2.1",
120+
"eslint-plugin-rulesdir": "^0.2.2",
121121
"fast-check": "^2.19.0",
122122
"fast-glob": "^3.1.0",
123123
"fs-extra": "^10.0.0",
124124
"full-icu": "^1.3.0",
125125
"identity-obj-proxy": "^3.0.0",
126126
"ignore-styles": "^5.0.1",
127-
"jest": "^27.4.3",
128-
"jest-environment-jsdom": "^27.4.3",
129-
"jest-junit": "^12.0.0",
130-
"jest-matchmedia-mock": "^1.0.0",
131-
"jsdom": "^16.7.0",
127+
"jest": "^29.5.0",
128+
"jest-environment-jsdom": "^29.5.0",
129+
"jest-junit": "^15.0.0",
130+
"jest-matchmedia-mock": "^1.1.0",
132131
"lerna": "^3.13.2",
133132
"lfcdn": "^0.4.2",
134133
"md5": "^2.2.1",
@@ -174,7 +173,6 @@
174173
"resolutions": {
175174
"@babel/core": "7.12.10",
176175
"postcss-calc": "6.0.2",
177-
"jsdom": "16.7.0",
178176
"postcss-modules": "^3.2.2",
179177
"react-refresh": "0.9.0",
180178
"browserslist": "4.20.3"

packages/@react-aria/calendar/test/useCalendar.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import React from 'react';
1717

1818
describe('useCalendar', () => {
1919
beforeAll(() => {
20-
jest.useFakeTimers('legacy');
21-
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => cb());
20+
jest.useFakeTimers();
2221
});
2322

2423
afterEach(() => {

packages/@react-aria/checkbox/test/useCheckboxGroup.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('useCheckboxGroup', () => {
5050
]} />
5151
);
5252

53-
let checkboxGroup = getByRole('group', {exact: true});
53+
let checkboxGroup = getByRole('group');
5454
let checkboxes = getAllByRole('checkbox') as HTMLInputElement[];
5555
expect(checkboxGroup).toBeInTheDocument();
5656
expect(checkboxes.length).toBe(3);
@@ -119,7 +119,7 @@ describe('useCheckboxGroup', () => {
119119
{value: 'dragons', children: 'Dragons'}
120120
]} />
121121
);
122-
let checkboxGroup = getByRole('group', {exact: true});
122+
let checkboxGroup = getByRole('group');
123123

124124
let labelId = checkboxGroup.getAttribute('aria-labelledby');
125125
expect(labelId).toBeDefined();
@@ -137,7 +137,7 @@ describe('useCheckboxGroup', () => {
137137
{value: 'dragons', children: 'Dragons'}
138138
]} />
139139
);
140-
let checkboxGroup = getByRole('group', {exact: true});
140+
let checkboxGroup = getByRole('group');
141141

142142
expect(checkboxGroup).toHaveAttribute('aria-label', 'My Favorite Pet');
143143
});
@@ -153,7 +153,7 @@ describe('useCheckboxGroup', () => {
153153
{value: 'dragons', children: 'Dragons'}
154154
]} />
155155
);
156-
let checkboxGroup = getByRole('group', {exact: true});
156+
let checkboxGroup = getByRole('group');
157157

158158
expect(checkboxGroup).toHaveAttribute('data-testid', 'favorite-pet');
159159
});
@@ -171,7 +171,7 @@ describe('useCheckboxGroup', () => {
171171
]} />
172172
);
173173

174-
let checkboxGroup = getByRole('group', {exact: true});
174+
let checkboxGroup = getByRole('group');
175175
expect(checkboxGroup).toHaveAttribute('aria-disabled', 'true');
176176

177177
let checkboxes = getAllByRole('checkbox') as HTMLInputElement[];
@@ -198,7 +198,7 @@ describe('useCheckboxGroup', () => {
198198
]} />
199199
);
200200

201-
let checkboxGroup = getByRole('group', {exact: true});
201+
let checkboxGroup = getByRole('group');
202202
expect(checkboxGroup).not.toHaveAttribute('aria-disabled');
203203

204204
let checkboxes = getAllByRole('checkbox') as HTMLInputElement[];
@@ -218,7 +218,7 @@ describe('useCheckboxGroup', () => {
218218
]} />
219219
);
220220

221-
let checkboxGroup = getByRole('group', {exact: true});
221+
let checkboxGroup = getByRole('group');
222222
expect(checkboxGroup).not.toHaveAttribute('aria-disabled');
223223

224224
let checkboxes = getAllByRole('checkbox') as HTMLInputElement[];

packages/@react-aria/color/test/useColorWheel.test.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ describe('useColorWheel', () => {
5252
let onChangeSpy = jest.fn();
5353

5454
beforeAll(() => {
55-
// @ts-ignore
56-
jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => cb());
57-
// @ts-ignore
58-
jest.useFakeTimers('legacy');
55+
jest.useFakeTimers();
5956
});
6057

6158
afterEach(() => {

packages/@react-aria/dnd/src/useAutoScroll.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ export function useAutoScroll(ref: RefObject<Element>) {
2929
dy: 0
3030
}).current;
3131

32+
useEffect(() => {
33+
return () => {
34+
if (state.timer) {
35+
cancelAnimationFrame(state.timer);
36+
state.timer = null;
37+
}
38+
};
39+
// state will become a new object, so it's ok to use in the dependency array for unmount
40+
}, [state]);
41+
3242
let scroll = useCallback(() => {
3343
scrollableRef.current.scrollLeft += state.dx;
3444
scrollableRef.current.scrollTop += state.dy;

packages/@react-aria/dnd/test/useDraggableCollection.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import userEvent from '@testing-library/user-event';
2323

2424
describe('useDraggableCollection', () => {
2525
beforeEach(() => {
26-
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => setTimeout(cb, 0));
2726
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(() => ({
2827
left: 0,
2928
top: 0,
@@ -33,7 +32,7 @@ describe('useDraggableCollection', () => {
3332
height: 50
3433
}));
3534

36-
jest.useFakeTimers('legacy');
35+
jest.useFakeTimers();
3736
});
3837

3938
afterEach(() => {

packages/@react-aria/dnd/test/useDroppableCollection.test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import userEvent from '@testing-library/user-event';
1919

2020
describe('useDroppableCollection', () => {
2121
beforeEach(() => {
22-
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => setTimeout(cb, 0));
2322
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
2423
let y = 0;
2524
let height = 50;
@@ -63,7 +62,7 @@ describe('useDroppableCollection', () => {
6362
return this.getBoundingClientRect().height;
6463
});
6564

66-
jest.useFakeTimers('legacy');
65+
jest.useFakeTimers();
6766
});
6867

6968
afterEach(() => {
@@ -224,35 +223,35 @@ describe('useDroppableCollection', () => {
224223

225224
let dataTransfer = new DataTransfer();
226225
fireEvent(draggable, new DragEvent('dragstart', {dataTransfer, clientX: 0, clientY: 0}));
227-
act(() => jest.runAllTimers());
226+
act(() => jest.advanceTimersToNextTimer());
228227
expect(draggable).toHaveAttribute('data-dragging', 'true');
229228

230229
fireEvent(cells[0], new DragEvent('dragenter', {dataTransfer, clientX: 30, clientY: 30}));
231-
act(() => jest.runOnlyPendingTimers());
230+
act(() => jest.advanceTimersToNextTimer());
232231
expect(scrollTop).not.toHaveBeenCalled();
233232

234233
fireEvent(cells[2], new DragEvent('dragover', {dataTransfer, clientX: 30, clientY: 100}));
235-
act(() => jest.runOnlyPendingTimers());
234+
act(() => jest.advanceTimersToNextTimer());
236235
expect(scrollTop).not.toHaveBeenCalled();
237236

238237
fireEvent(cells[4], new DragEvent('dragover', {dataTransfer, clientX: 30, clientY: 135}));
239-
act(() => jest.runOnlyPendingTimers());
238+
act(() => jest.advanceTimersToNextTimer());
240239
expect(scrollTop).toHaveBeenCalledTimes(1);
241-
act(() => jest.runOnlyPendingTimers());
240+
act(() => jest.advanceTimersToNextTimer());
242241
expect(scrollTop).toHaveBeenCalledTimes(2);
243242
jest.clearAllTimers();
244243

245244
fireEvent(cells[2], new DragEvent('dragover', {dataTransfer, clientX: 30, clientY: 100}));
246-
act(() => jest.runAllTimers());
245+
act(() => jest.advanceTimersToNextTimer());
247246
expect(scrollTop).toHaveBeenCalledTimes(2);
248247

249248
fireEvent(cells[2], new DragEvent('dragover', {dataTransfer, clientX: 30, clientY: 15}));
250-
act(() => jest.runOnlyPendingTimers());
249+
act(() => jest.advanceTimersToNextTimer());
251250
expect(scrollTop).toHaveBeenCalledTimes(3);
252251
jest.clearAllTimers();
253252

254253
fireEvent(cells[2], new DragEvent('dragover', {dataTransfer, clientX: 30, clientY: 30}));
255-
act(() => jest.runAllTimers());
254+
act(() => jest.advanceTimersToNextTimer());
256255
expect(scrollTop).toHaveBeenCalledTimes(3);
257256
});
258257

packages/@react-aria/grid/test/useGrid.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function renderGrid(props = {}) {
3939

4040
describe('useGrid', () => {
4141
beforeAll(() => {
42-
jest.useFakeTimers('modern');
42+
jest.useFakeTimers();
4343
});
4444
afterEach(() => {
4545
// run out notifications

packages/@react-aria/interactions/test/useHover.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function pointerEvent(type, opts) {
3737

3838
describe('useHover', function () {
3939
beforeAll(() => {
40-
jest.useFakeTimers('legacy');
40+
jest.useFakeTimers();
4141
});
4242

4343
it('does not handle hover events if disabled', function () {
@@ -530,10 +530,7 @@ describe('useHover', function () {
530530
}
531531

532532
beforeAll(() => {
533-
jest.useFakeTimers('legacy');
534-
});
535-
afterAll(() => {
536-
jest.useRealTimers();
533+
jest.useFakeTimers();
537534
});
538535

539536
let matchMedia;

0 commit comments

Comments
 (0)