Skip to content

Commit 71cace4

Browse files
authored
Migrate testRunner from jasmine2 to jest-circus (#26144)
## Summary In jest v27, jest-circus as default test runner (jestjs/jest#10686) ## How did you test this change? ci green
1 parent b8ae89f commit 71cace4

Some content is hidden

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

43 files changed

+264
-263
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ module.exports = {
434434
es6: true,
435435
node: true,
436436
jest: true,
437-
jasmine: true,
438437
},
439438

440439
globals: {

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@
6969
"gzip-size": "^5.1.1",
7070
"hermes-eslint": "^0.9.0",
7171
"hermes-parser": "^0.9.0",
72-
"jasmine-check": "^1.0.0-rc.0",
7372
"jest": "^29.4.1",
7473
"jest-cli": "^29.4.1",
7574
"jest-diff": "^29.4.1",
7675
"jest-environment-jsdom": "^29.4.1",
77-
"jest-jasmine2": "^29.4.1",
7876
"jest-snapshot-serializer-raw": "^1.1.0",
7977
"minimatch": "^3.0.4",
8078
"minimist": "^1.2.3",

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ describe('ReactFlight', () => {
9191
};
9292
});
9393

94+
afterEach(() => {
95+
jest.restoreAllMocks();
96+
});
97+
9498
function clientReference(value) {
9599
return Object.defineProperties(
96100
function () {
@@ -240,7 +244,7 @@ describe('ReactFlight', () => {
240244
ReactNoop.render(rootModel);
241245
});
242246
expect(ReactNoop).toMatchRenderedOutput('Loading...');
243-
spyOnDevAndProd(console, 'error');
247+
spyOnDevAndProd(console, 'error').mockImplementation(() => {});
244248
await load();
245249
expect(console.error).toHaveBeenCalledTimes(1);
246250
});
@@ -322,7 +326,7 @@ describe('ReactFlight', () => {
322326
ReactNoop.render(rootModel);
323327
});
324328
expect(ReactNoop).toMatchRenderedOutput('Loading...');
325-
spyOnDevAndProd(console, 'error');
329+
spyOnDevAndProd(console, 'error').mockImplementation(() => {});
326330
await load();
327331
expect(console.error).toHaveBeenCalledTimes(1);
328332
});

packages/react-devtools-extensions/flow-typed/jest.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,28 +1172,5 @@ declare var expect: {
11721172
},
11731173
};
11741174

1175-
// TODO handle return type
1176-
// https://jasmine.github.io/2.4/introduction.html#section-Spies
1177-
declare function spyOn(value: mixed, method: string): Object;
1178-
11791175
/** Holds all functions related to manipulating test runner */
11801176
declare var jest: JestObjectType;
1181-
1182-
/**
1183-
* The global Jasmine object, this is generally not exposed as the public API,
1184-
* using features inside here could break in later versions of Jest.
1185-
*/
1186-
declare var jasmine: {
1187-
DEFAULT_TIMEOUT_INTERVAL: number,
1188-
any(value: mixed): JestAsymmetricEqualityType,
1189-
anything(): any,
1190-
arrayContaining(value: Array<mixed>): Array<mixed>,
1191-
clock(): JestClockType,
1192-
createSpy(name: string): JestSpyType,
1193-
createSpyObj(
1194-
baseName: string,
1195-
methodNames: Array<string>
1196-
): {[methodName: string]: JestSpyType},
1197-
objectContaining(value: Object): Object,
1198-
stringMatching(value: string): string,
1199-
};

packages/react-devtools-shared/src/__tests__/TimelineProfiler-test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ describe('Timeline profiler', () => {
4747
store = global.store;
4848
});
4949

50+
afterEach(() => {
51+
jest.restoreAllMocks();
52+
});
53+
5054
describe('User Timing API', () => {
5155
let clearedMarks;
5256
let featureDetectionMarkName = null;
@@ -517,7 +521,7 @@ describe('Timeline profiler', () => {
517521
clearPendingMarks();
518522

519523
let errorMessage;
520-
spyOn(console, 'error').and.callFake(message => {
524+
jest.spyOn(console, 'error').mockImplementation(message => {
521525
errorMessage = message;
522526
});
523527

@@ -571,7 +575,7 @@ describe('Timeline profiler', () => {
571575
clearPendingMarks();
572576

573577
let errorMessage;
574-
spyOn(console, 'error').and.callFake(message => {
578+
jest.spyOn(console, 'error').mockImplementation(message => {
575579
errorMessage = message;
576580
});
577581

@@ -740,7 +744,7 @@ describe('Timeline profiler', () => {
740744
});
741745

742746
it('should mark sync render that throws', async () => {
743-
spyOn(console, 'error');
747+
jest.spyOn(console, 'error').mockImplementation(() => {});
744748

745749
class ErrorBoundary extends React.Component {
746750
state = {error: null};
@@ -802,7 +806,7 @@ describe('Timeline profiler', () => {
802806
});
803807

804808
it('should mark concurrent render that throws', async () => {
805-
spyOn(console, 'error');
809+
jest.spyOn(console, 'error').mockImplementation(() => {});
806810

807811
class ErrorBoundary extends React.Component {
808812
state = {error: null};
@@ -1697,7 +1701,7 @@ describe('Timeline profiler', () => {
16971701
renderRootHelper(<Example />);
16981702

16991703
let errorMessage;
1700-
spyOn(console, 'error').and.callFake(message => {
1704+
jest.spyOn(console, 'error').mockImplementation(message => {
17011705
errorMessage = message;
17021706
});
17031707

@@ -1766,7 +1770,7 @@ describe('Timeline profiler', () => {
17661770
renderRootHelper(<Example />);
17671771

17681772
let errorMessage;
1769-
spyOn(console, 'error').and.callFake(message => {
1773+
jest.spyOn(console, 'error').mockImplementation(message => {
17701774
errorMessage = message;
17711775
});
17721776

@@ -1993,7 +1997,7 @@ describe('Timeline profiler', () => {
19931997
});
19941998

19951999
it('should mark sync render that throws', async () => {
1996-
spyOn(console, 'error');
2000+
jest.spyOn(console, 'error').mockImplementation(() => {});
19972001

19982002
class ErrorBoundary extends React.Component {
19992003
state = {error: null};
@@ -2088,7 +2092,7 @@ describe('Timeline profiler', () => {
20882092
});
20892093

20902094
it('should mark concurrent render that throws', async () => {
2091-
spyOn(console, 'error');
2095+
jest.spyOn(console, 'error').mockImplementation(() => {});
20922096

20932097
class ErrorBoundary extends React.Component {
20942098
state = {error: null};

packages/react-devtools-shared/src/__tests__/bridge-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Bridge', () => {
3838
expect(wall.send).toHaveBeenCalledWith('shutdown');
3939

4040
// Verify that the Bridge doesn't send messages after shutdown.
41-
spyOn(console, 'warn');
41+
jest.spyOn(console, 'warn').mockImplementation(() => {});
4242
wall.send.mockClear();
4343
bridge.send('should not send');
4444
jest.runAllTimers();

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ describe('InspectedElement', () => {
21212121
});
21222122

21232123
it('should gracefully surface backend errors on the frontend rather than timing out', async () => {
2124-
spyOn(console, 'error');
2124+
jest.spyOn(console, 'error').mockImplementation(() => {});
21252125

21262126
let shouldThrow = false;
21272127

@@ -2738,7 +2738,7 @@ describe('InspectedElement', () => {
27382738

27392739
it('inspecting nested renderers should not throw', async () => {
27402740
// Ignoring react art warnings
2741-
spyOn(console, 'error');
2741+
jest.spyOn(console, 'error').mockImplementation(() => {});
27422742
const ReactArt = require('react-art');
27432743
const ArtSVGMode = require('art/modes/svg');
27442744
const ARTCurrentMode = require('art/modes/current');

packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ describe('InspectedElementContext', () => {
760760
const rendererID = ((store.getRendererIDForElement(id): any): number);
761761

762762
const logSpy = jest.fn();
763-
spyOn(console, 'log').and.callFake(logSpy);
763+
jest.spyOn(console, 'log').mockImplementation(logSpy);
764764

765765
// Should store the whole value (not just the hydrated parts)
766766
backendAPI.storeAsGlobal({

packages/react-devtools-shared/src/__tests__/preprocessData-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ describe('Timeline profiler', () => {
11351135
);
11361136
const invalidUserTimingData = createUserTimingData(invalidMarks);
11371137

1138-
const error = spyOn(console, 'error');
1138+
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
11391139
preprocessData([
11401140
...createBoilerplateEntries(),
11411141
...invalidUserTimingData,
@@ -1153,7 +1153,7 @@ describe('Timeline profiler', () => {
11531153
);
11541154
const invalidUserTimingData = createUserTimingData(invalidMarks);
11551155

1156-
const error = spyOn(console, 'error');
1156+
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
11571157
preprocessData([
11581158
...createBoilerplateEntries(),
11591159
...invalidUserTimingData,
@@ -1748,7 +1748,7 @@ describe('Timeline profiler', () => {
17481748
describe('errors thrown while rendering', () => {
17491749
// @reactVersion >= 18.0
17501750
it('shoult parse Errors thrown during render', async () => {
1751-
spyOn(console, 'error');
1751+
jest.spyOn(console, 'error');
17521752

17531753
class ErrorBoundary extends React.Component {
17541754
state = {error: null};

packages/react-devtools-shared/src/__tests__/profilerStore-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('ProfilerStore', () => {
7373
const fauxProfilingData = {
7474
dataForRoots: new Map(),
7575
};
76-
spyOn(console, 'warn');
76+
jest.spyOn(console, 'warn').mockImplementation(() => {});
7777
store.profilerStore.profilingData = fauxProfilingData;
7878
expect(store.profilerStore.profilingData).not.toBe(fauxProfilingData);
7979
expect(console.warn).toHaveBeenCalledTimes(1);

packages/react-devtools-shared/src/__tests__/setupTests.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ if (compactConsole) {
3232
global.console = new CustomConsole(process.stdout, process.stderr, formatter);
3333
}
3434

35-
const env = jasmine.getEnv();
36-
env.beforeEach(() => {
35+
beforeEach(() => {
3736
global.mockClipboardCopy = jest.fn();
3837

3938
// Test environment doesn't support document methods like execCommand()
@@ -169,7 +168,7 @@ env.beforeEach(() => {
169168
}
170169
global.fetch = mockFetch;
171170
});
172-
env.afterEach(() => {
171+
afterEach(() => {
173172
delete global.__REACT_DEVTOOLS_GLOBAL_HOOK__;
174173

175174
// It's important to reset modules between test runs;

packages/react-dom/src/__tests__/InvalidEventListeners-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('InvalidEventListeners', () => {
6565

6666
if (!__DEV__) {
6767
expect(console.error).toHaveBeenCalledTimes(1);
68-
expect(console.error.calls.argsFor(0)[0]).toEqual(
68+
expect(console.error.mock.calls[0][0]).toEqual(
6969
expect.objectContaining({
7070
detail: expect.objectContaining({
7171
message:

packages/react-dom/src/__tests__/ReactDOMComponent-test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ describe('ReactDOMComponent', () => {
2424
ReactTestUtils = require('react-dom/test-utils');
2525
});
2626

27+
afterEach(() => {
28+
jest.restoreAllMocks();
29+
});
30+
2731
describe('updateDOM', () => {
2832
it('should handle className', () => {
2933
const container = document.createElement('div');
@@ -1239,7 +1243,7 @@ describe('ReactDOMComponent', () => {
12391243

12401244
if (__DEV__) {
12411245
expect(console.log).toHaveBeenCalledTimes(1);
1242-
expect(console.log.calls.argsFor(0)[0]).toContain('onError called');
1246+
expect(console.log.mock.calls[0][0]).toContain('onError called');
12431247
}
12441248
});
12451249

@@ -1464,7 +1468,7 @@ describe('ReactDOMComponent', () => {
14641468

14651469
it('should support custom elements which extend native elements', () => {
14661470
const container = document.createElement('div');
1467-
spyOnDevAndProd(document, 'createElement').and.callThrough();
1471+
spyOnDevAndProd(document, 'createElement');
14681472
ReactDOM.render(<div is="custom-div" />, container);
14691473
expect(document.createElement).toHaveBeenCalledWith('div', {
14701474
is: 'custom-div',
@@ -1496,8 +1500,8 @@ describe('ReactDOMComponent', () => {
14961500

14971501
if (__DEV__) {
14981502
expect(console.log).toHaveBeenCalledTimes(2);
1499-
expect(console.log.calls.argsFor(0)[0]).toContain('onError called');
1500-
expect(console.log.calls.argsFor(1)[0]).toContain('onLoad called');
1503+
expect(console.log.mock.calls[0][0]).toContain('onError called');
1504+
expect(console.log.mock.calls[1][0]).toContain('onLoad called');
15011505
}
15021506
});
15031507

0 commit comments

Comments
 (0)