Skip to content

Commit

Permalink
Migrate testRunner from jasmine2 to jest-circus (#26144)
Browse files Browse the repository at this point in the history
## Summary

In jest v27, jest-circus as default test runner
(jestjs/jest#10686)

## How did you test this change?

ci green
  • Loading branch information
ymqy authored Feb 10, 2023
1 parent b8ae89f commit 71cace4
Show file tree
Hide file tree
Showing 43 changed files with 264 additions and 263 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ module.exports = {
es6: true,
node: true,
jest: true,
jasmine: true,
},

globals: {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@
"gzip-size": "^5.1.1",
"hermes-eslint": "^0.9.0",
"hermes-parser": "^0.9.0",
"jasmine-check": "^1.0.0-rc.0",
"jest": "^29.4.1",
"jest-cli": "^29.4.1",
"jest-diff": "^29.4.1",
"jest-environment-jsdom": "^29.4.1",
"jest-jasmine2": "^29.4.1",
"jest-snapshot-serializer-raw": "^1.1.0",
"minimatch": "^3.0.4",
"minimist": "^1.2.3",
Expand Down
8 changes: 6 additions & 2 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ describe('ReactFlight', () => {
};
});

afterEach(() => {
jest.restoreAllMocks();
});

function clientReference(value) {
return Object.defineProperties(
function () {
Expand Down Expand Up @@ -240,7 +244,7 @@ describe('ReactFlight', () => {
ReactNoop.render(rootModel);
});
expect(ReactNoop).toMatchRenderedOutput('Loading...');
spyOnDevAndProd(console, 'error');
spyOnDevAndProd(console, 'error').mockImplementation(() => {});
await load();
expect(console.error).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -322,7 +326,7 @@ describe('ReactFlight', () => {
ReactNoop.render(rootModel);
});
expect(ReactNoop).toMatchRenderedOutput('Loading...');
spyOnDevAndProd(console, 'error');
spyOnDevAndProd(console, 'error').mockImplementation(() => {});
await load();
expect(console.error).toHaveBeenCalledTimes(1);
});
Expand Down
23 changes: 0 additions & 23 deletions packages/react-devtools-extensions/flow-typed/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1172,28 +1172,5 @@ declare var expect: {
},
};

// TODO handle return type
// https://jasmine.github.io/2.4/introduction.html#section-Spies
declare function spyOn(value: mixed, method: string): Object;

/** Holds all functions related to manipulating test runner */
declare var jest: JestObjectType;

/**
* The global Jasmine object, this is generally not exposed as the public API,
* using features inside here could break in later versions of Jest.
*/
declare var jasmine: {
DEFAULT_TIMEOUT_INTERVAL: number,
any(value: mixed): JestAsymmetricEqualityType,
anything(): any,
arrayContaining(value: Array<mixed>): Array<mixed>,
clock(): JestClockType,
createSpy(name: string): JestSpyType,
createSpyObj(
baseName: string,
methodNames: Array<string>
): {[methodName: string]: JestSpyType},
objectContaining(value: Object): Object,
stringMatching(value: string): string,
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ describe('Timeline profiler', () => {
store = global.store;
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('User Timing API', () => {
let clearedMarks;
let featureDetectionMarkName = null;
Expand Down Expand Up @@ -517,7 +521,7 @@ describe('Timeline profiler', () => {
clearPendingMarks();

let errorMessage;
spyOn(console, 'error').and.callFake(message => {
jest.spyOn(console, 'error').mockImplementation(message => {
errorMessage = message;
});

Expand Down Expand Up @@ -571,7 +575,7 @@ describe('Timeline profiler', () => {
clearPendingMarks();

let errorMessage;
spyOn(console, 'error').and.callFake(message => {
jest.spyOn(console, 'error').mockImplementation(message => {
errorMessage = message;
});

Expand Down Expand Up @@ -740,7 +744,7 @@ describe('Timeline profiler', () => {
});

it('should mark sync render that throws', async () => {
spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

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

it('should mark concurrent render that throws', async () => {
spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

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

let errorMessage;
spyOn(console, 'error').and.callFake(message => {
jest.spyOn(console, 'error').mockImplementation(message => {
errorMessage = message;
});

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

let errorMessage;
spyOn(console, 'error').and.callFake(message => {
jest.spyOn(console, 'error').mockImplementation(message => {
errorMessage = message;
});

Expand Down Expand Up @@ -1993,7 +1997,7 @@ describe('Timeline profiler', () => {
});

it('should mark sync render that throws', async () => {
spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

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

it('should mark concurrent render that throws', async () => {
spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

class ErrorBoundary extends React.Component {
state = {error: null};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Bridge', () => {
expect(wall.send).toHaveBeenCalledWith('shutdown');

// Verify that the Bridge doesn't send messages after shutdown.
spyOn(console, 'warn');
jest.spyOn(console, 'warn').mockImplementation(() => {});
wall.send.mockClear();
bridge.send('should not send');
jest.runAllTimers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ describe('InspectedElement', () => {
});

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

let shouldThrow = false;

Expand Down Expand Up @@ -2738,7 +2738,7 @@ describe('InspectedElement', () => {

it('inspecting nested renderers should not throw', async () => {
// Ignoring react art warnings
spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});
const ReactArt = require('react-art');
const ArtSVGMode = require('art/modes/svg');
const ARTCurrentMode = require('art/modes/current');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ describe('InspectedElementContext', () => {
const rendererID = ((store.getRendererIDForElement(id): any): number);

const logSpy = jest.fn();
spyOn(console, 'log').and.callFake(logSpy);
jest.spyOn(console, 'log').mockImplementation(logSpy);

// Should store the whole value (not just the hydrated parts)
backendAPI.storeAsGlobal({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ describe('Timeline profiler', () => {
);
const invalidUserTimingData = createUserTimingData(invalidMarks);

const error = spyOn(console, 'error');
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
preprocessData([
...createBoilerplateEntries(),
...invalidUserTimingData,
Expand All @@ -1153,7 +1153,7 @@ describe('Timeline profiler', () => {
);
const invalidUserTimingData = createUserTimingData(invalidMarks);

const error = spyOn(console, 'error');
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
preprocessData([
...createBoilerplateEntries(),
...invalidUserTimingData,
Expand Down Expand Up @@ -1748,7 +1748,7 @@ describe('Timeline profiler', () => {
describe('errors thrown while rendering', () => {
// @reactVersion >= 18.0
it('shoult parse Errors thrown during render', async () => {
spyOn(console, 'error');
jest.spyOn(console, 'error');

class ErrorBoundary extends React.Component {
state = {error: null};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('ProfilerStore', () => {
const fauxProfilingData = {
dataForRoots: new Map(),
};
spyOn(console, 'warn');
jest.spyOn(console, 'warn').mockImplementation(() => {});
store.profilerStore.profilingData = fauxProfilingData;
expect(store.profilerStore.profilingData).not.toBe(fauxProfilingData);
expect(console.warn).toHaveBeenCalledTimes(1);
Expand Down
5 changes: 2 additions & 3 deletions packages/react-devtools-shared/src/__tests__/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ if (compactConsole) {
global.console = new CustomConsole(process.stdout, process.stderr, formatter);
}

const env = jasmine.getEnv();
env.beforeEach(() => {
beforeEach(() => {
global.mockClipboardCopy = jest.fn();

// Test environment doesn't support document methods like execCommand()
Expand Down Expand Up @@ -169,7 +168,7 @@ env.beforeEach(() => {
}
global.fetch = mockFetch;
});
env.afterEach(() => {
afterEach(() => {
delete global.__REACT_DEVTOOLS_GLOBAL_HOOK__;

// It's important to reset modules between test runs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('InvalidEventListeners', () => {

if (!__DEV__) {
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error.calls.argsFor(0)[0]).toEqual(
expect(console.error.mock.calls[0][0]).toEqual(
expect.objectContaining({
detail: expect.objectContaining({
message:
Expand Down
12 changes: 8 additions & 4 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ describe('ReactDOMComponent', () => {
ReactTestUtils = require('react-dom/test-utils');
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('updateDOM', () => {
it('should handle className', () => {
const container = document.createElement('div');
Expand Down Expand Up @@ -1239,7 +1243,7 @@ describe('ReactDOMComponent', () => {

if (__DEV__) {
expect(console.log).toHaveBeenCalledTimes(1);
expect(console.log.calls.argsFor(0)[0]).toContain('onError called');
expect(console.log.mock.calls[0][0]).toContain('onError called');
}
});

Expand Down Expand Up @@ -1464,7 +1468,7 @@ describe('ReactDOMComponent', () => {

it('should support custom elements which extend native elements', () => {
const container = document.createElement('div');
spyOnDevAndProd(document, 'createElement').and.callThrough();
spyOnDevAndProd(document, 'createElement');
ReactDOM.render(<div is="custom-div" />, container);
expect(document.createElement).toHaveBeenCalledWith('div', {
is: 'custom-div',
Expand Down Expand Up @@ -1496,8 +1500,8 @@ describe('ReactDOMComponent', () => {

if (__DEV__) {
expect(console.log).toHaveBeenCalledTimes(2);
expect(console.log.calls.argsFor(0)[0]).toContain('onError called');
expect(console.log.calls.argsFor(1)[0]).toContain('onLoad called');
expect(console.log.mock.calls[0][0]).toContain('onError called');
expect(console.log.mock.calls[1][0]).toContain('onLoad called');
}
});

Expand Down
Loading

0 comments on commit 71cace4

Please sign in to comment.