Skip to content

Commit

Permalink
DevTools: Update tests to fix warnings/errors (#21748)
Browse files Browse the repository at this point in the history
Some new ones had slipped in (e.g. deprecated ReactDOM.render message from 18)
  • Loading branch information
Brian Vaughn authored Jun 25, 2021
1 parent 534c9c5 commit 73ffce1
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 363 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

describe('Fast Refresh', () => {
let React;
let ReactDOM;
let ReactFreshRuntime;
let act;
let babel;
let container;
let exportsObj;
let freshPlugin;
let legacyRender;
let store;
let withErrorsOrWarningsIgnored;

Expand All @@ -37,10 +37,9 @@ describe('Fast Refresh', () => {
ReactFreshRuntime = require('react-refresh/runtime');
ReactFreshRuntime.injectIntoGlobalHook(global);

ReactDOM = require('react-dom');

const utils = require('./utils');
act = utils.act;
legacyRender = utils.legacyRender;
withErrorsOrWarningsIgnored = utils.withErrorsOrWarningsIgnored;
});

Expand Down Expand Up @@ -74,7 +73,7 @@ describe('Fast Refresh', () => {
function render(source) {
const Component = execute(source);
act(() => {
ReactDOM.render(<Component />, container);
legacyRender(<Component />, container);
});
// Module initialization shouldn't be counted as a hot update.
expect(ReactFreshRuntime.performReactRefresh()).toBe(null);
Expand All @@ -99,7 +98,7 @@ describe('Fast Refresh', () => {
// Here, we'll just force a re-render using the newer type to emulate this.
const NextComponent = nextExports.default;
act(() => {
ReactDOM.render(<NextComponent />, container);
legacyRender(<NextComponent />, container);
});
}
act(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function normalizeCodeLocInfo(str) {

describe('component stack', () => {
let React;
let ReactDOM;
let act;
let legacyRender;
let mockError;
let mockWarn;

Expand All @@ -44,9 +44,9 @@ describe('component stack', () => {

const utils = require('./utils');
act = utils.act;
legacyRender = utils.legacyRender;

React = require('react');
ReactDOM = require('react-dom');
});

it('should log the current component stack along with an error or warning', () => {
Expand All @@ -60,7 +60,7 @@ describe('component stack', () => {

const container = document.createElement('div');

act(() => ReactDOM.render(<Grandparent />, container));
act(() => legacyRender(<Grandparent />, container));

expect(mockError).toHaveBeenCalledWith(
'Test error.',
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('component stack', () => {
};

const container = document.createElement('div');
act(() => ReactDOM.render(<Example test="abc" />, container));
act(() => legacyRender(<Example test="abc" />, container));

expect(useEffectCount).toBe(1);

Expand Down
24 changes: 12 additions & 12 deletions packages/react-devtools-shared/src/__tests__/console-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

describe('console', () => {
let React;
let ReactDOM;
let act;
let fakeConsole;
let legacyRender;
let mockError;
let mockInfo;
let mockLog;
Expand Down Expand Up @@ -58,10 +58,10 @@ describe('console', () => {
};

React = require('react');
ReactDOM = require('react-dom');

const utils = require('./utils');
act = utils.act;
legacyRender = utils.legacyRender;
});

function normalizeCodeLocInfo(str) {
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('console', () => {
return null;
};

act(() => ReactDOM.render(<Child />, document.createElement('div')));
act(() => legacyRender(<Child />, document.createElement('div')));

expect(mockWarn).toHaveBeenCalledTimes(1);
expect(mockWarn.mock.calls[0]).toHaveLength(1);
Expand All @@ -203,7 +203,7 @@ describe('console', () => {
return null;
};

act(() => ReactDOM.render(<Parent />, document.createElement('div')));
act(() => legacyRender(<Parent />, document.createElement('div')));

expect(mockLog).toHaveBeenCalledTimes(1);
expect(mockLog.mock.calls[0]).toHaveLength(1);
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('console', () => {
return null;
};

act(() => ReactDOM.render(<Parent />, document.createElement('div')));
act(() => legacyRender(<Parent />, document.createElement('div')));

expect(mockLog).toHaveBeenCalledTimes(2);
expect(mockLog.mock.calls[0]).toHaveLength(1);
Expand Down Expand Up @@ -298,8 +298,8 @@ describe('console', () => {
}

const container = document.createElement('div');
act(() => ReactDOM.render(<Parent />, container));
act(() => ReactDOM.render(<Parent />, container));
act(() => legacyRender(<Parent />, container));
act(() => legacyRender(<Parent />, container));

expect(mockLog).toHaveBeenCalledTimes(2);
expect(mockLog.mock.calls[0]).toHaveLength(1);
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('console', () => {
}
}

act(() => ReactDOM.render(<Parent />, document.createElement('div')));
act(() => legacyRender(<Parent />, document.createElement('div')));

expect(mockLog).toHaveBeenCalledTimes(1);
expect(mockLog.mock.calls[0]).toHaveLength(1);
Expand All @@ -377,7 +377,7 @@ describe('console', () => {
};

unpatchConsole();
act(() => ReactDOM.render(<Child />, document.createElement('div')));
act(() => legacyRender(<Child />, document.createElement('div')));

expect(mockWarn).toHaveBeenCalledTimes(1);
expect(mockWarn.mock.calls[0]).toHaveLength(1);
Expand All @@ -391,7 +391,7 @@ describe('console', () => {
breakOnWarn: false,
showInlineWarningsAndErrors: false,
});
act(() => ReactDOM.render(<Child />, document.createElement('div')));
act(() => legacyRender(<Child />, document.createElement('div')));

expect(mockWarn).toHaveBeenCalledTimes(2);
expect(mockWarn.mock.calls[1]).toHaveLength(2);
Expand Down Expand Up @@ -435,7 +435,7 @@ describe('console', () => {
return null;
};

act(() => ReactDOM.render(<Parent />, document.createElement('div')));
act(() => legacyRender(<Parent />, document.createElement('div')));

expect(mockLog).toHaveBeenCalledTimes(1);
expect(mockLog.mock.calls[0]).toHaveLength(1);
Expand All @@ -460,7 +460,7 @@ describe('console', () => {
return null;
};

act(() => ReactDOM.render(<Component />, document.createElement('div')));
act(() => legacyRender(<Component />, document.createElement('div')));

expect(mockWarn).toHaveBeenCalledTimes(1);
expect(mockWarn.mock.calls[0][0]).toBe('Symbol:');
Expand Down
13 changes: 7 additions & 6 deletions packages/react-devtools-shared/src/__tests__/editing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type Store from 'react-devtools-shared/src/devtools/store';
describe('editing interface', () => {
let PropTypes;
let React;
let ReactDOM;
let bridge: FrontendBridge;
let legacyRender;
let store: Store;
let utils;

Expand All @@ -25,14 +25,15 @@ describe('editing interface', () => {
beforeEach(() => {
utils = require('./utils');

legacyRender = utils.legacyRender;

bridge = global.bridge;
store = global.store;
store.collapseNodesByDefault = false;
store.componentFilters = [];

PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
});

describe('props', () => {
Expand Down Expand Up @@ -67,7 +68,7 @@ describe('editing interface', () => {

const container = document.createElement('div');
await utils.actAsync(() =>
ReactDOM.render(
legacyRender(
<>
<ClassComponent
array={[1, 2, 3]}
Expand Down Expand Up @@ -435,7 +436,7 @@ describe('editing interface', () => {

const container = document.createElement('div');
await utils.actAsync(() =>
ReactDOM.render(
legacyRender(
<ClassComponent object={{nested: 'initial'}} shallow="initial" />,
container,
),
Expand Down Expand Up @@ -652,7 +653,7 @@ describe('editing interface', () => {

const container = document.createElement('div');
await utils.actAsync(() =>
ReactDOM.render(<FunctionComponent />, container),
legacyRender(<FunctionComponent />, container),
);

hookID = 0; // index
Expand Down Expand Up @@ -902,7 +903,7 @@ describe('editing interface', () => {

const container = document.createElement('div');
await utils.actAsync(() =>
ReactDOM.render(
legacyRender(
<LegacyContextProvider>
<ClassComponent />
</LegacyContextProvider>,
Expand Down
Loading

0 comments on commit 73ffce1

Please sign in to comment.