Skip to content

Commit

Permalink
[Tests] Reset modules by default
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Feb 6, 2024
1 parent 95ec128 commit 8c35c8c
Show file tree
Hide file tree
Showing 197 changed files with 67 additions and 379 deletions.
1 change: 0 additions & 1 deletion packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ let assertLog;

describe('ReactFlight', () => {
beforeEach(() => {
jest.resetModules();
jest.mock('react', () => require('react/react.react-server'));
ReactServer = require('react');
ReactNoopFlightServer = require('react-noop-renderer/flight-server');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ describe('React hooks DevTools integration', () => {
onCommitFiberUnmount: () => {},
};

jest.resetModules();

React = require('react');
ReactDebugTools = require('react-debug-tools');
ReactTestRenderer = require('react-test-renderer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let ReactDebugTools;

describe('ReactHooksInspection', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDebugTools = require('react-debug-tools');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ let useMemoCache;

describe('ReactHooksInspectionIntegration', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactTestRenderer = require('react-test-renderer');
ReactDOM = require('react-dom');
Expand Down
2 changes: 0 additions & 2 deletions packages/react-devtools-shared/src/__tests__/console-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,6 @@ describe('console', () => {

describe('console error', () => {
beforeEach(() => {
jest.resetModules();

const Console = require('react-devtools-shared/src/backend/console');
patchConsole = Console.patch;
unpatchConsole = Console.unpatch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ describe('parseHookNames', () => {
let parseHookNames;

beforeEach(() => {
jest.resetModules();

jest.mock('source-map-support', () => {
console.trace('source-map-support');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('DOMPropertyOperations', () => {
let act;

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMClient = require('react-dom/client');
({act} = require('internal-test-utils'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('InvalidEventListeners', () => {
let container;

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ let container;
// It should probably be rewritten but we're keeping it for some extra coverage.
describe('ReactBrowserEventEmitter', () => {
beforeEach(() => {
jest.resetModules();
LISTENER.mockClear();

React = require('react');
Expand Down
2 changes: 0 additions & 2 deletions packages/react-dom/src/__tests__/ReactChildReconciler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ let act;

describe('ReactChildReconciler', () => {
beforeEach(() => {
jest.resetModules();

React = require('react');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;
Expand Down
2 changes: 0 additions & 2 deletions packages/react-dom/src/__tests__/ReactComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ let act;

describe('ReactComponent', () => {
beforeEach(() => {
jest.resetModules();

React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ function getLifeCycleState(instance): ComponentLifeCycle {
*/
describe('ReactComponentLifeCycle', () => {
beforeEach(() => {
jest.resetModules();

act = require('internal-test-utils').act;

React = require('react');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('ReactCompositeComponent', () => {
}

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Expand Down
124 changes: 64 additions & 60 deletions packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,78 +520,82 @@ describe('ReactCompositeComponent-state', () => {
assertLog([
'render -- step: 3, extra: false',
'callback -- step: 3, extra: false',

// A second time for the retry.
'render -- step: 3, extra: false',
'callback -- step: 3, extra: false',
]);
});

if (!require('shared/ReactFeatureFlags').disableModulePatternComponents) {
it('should support stateful module pattern components', async () => {
function Child() {
return {
state: {
count: 123,
},
render() {
return <div>{`count:${this.state.count}`}</div>;
},
};
}

const el = document.createElement('div');
const root = ReactDOMClient.createRoot(el);
expect(() => {
ReactDOM.flushSync(() => {
root.render(<Child />);
});
}).toErrorDev(
'Warning: The <Child /> component appears to be a function component that returns a class instance. ' +
'Change Child to a class that extends React.Component instead. ' +
"If you can't use a class try assigning the prototype on the function as a workaround. " +
'`Child.prototype = React.Component.prototype`. ' +
"Don't use an arrow function since it cannot be called with `new` by React.",
);
// @gate !disableModulePatternComponents
it('should support stateful module pattern components', async () => {
function Child() {
return {
state: {
count: 123,
},
render() {
return <div>{`count:${this.state.count}`}</div>;
},
};
}

expect(el.textContent).toBe('count:123');
});
const el = document.createElement('div');
const root = ReactDOMClient.createRoot(el);
expect(() => {
ReactDOM.flushSync(() => {
root.render(<Child />);
});
}).toErrorDev(
'Warning: The <Child /> component appears to be a function component that returns a class instance. ' +
'Change Child to a class that extends React.Component instead. ' +
"If you can't use a class try assigning the prototype on the function as a workaround. " +
'`Child.prototype = React.Component.prototype`. ' +
"Don't use an arrow function since it cannot be called with `new` by React.",
);

expect(el.textContent).toBe('count:123');
});

it('should support getDerivedStateFromProps for module pattern components', async () => {
function Child() {
return {
state: {
count: 1,
},
render() {
return <div>{`count:${this.state.count}`}</div>;
},
};
}
Child.getDerivedStateFromProps = (props, prevState) => {
return {
count: prevState.count + props.incrementBy,
};
// @gate !disableModulePatternComponents
it('should support getDerivedStateFromProps for module pattern components', async () => {
function Child() {
return {
state: {
count: 1,
},
render() {
return <div>{`count:${this.state.count}`}</div>;
},
};
}
Child.getDerivedStateFromProps = (props, prevState) => {
return {
count: prevState.count + props.incrementBy,
};
};

const el = document.createElement('div');
const root = ReactDOMClient.createRoot(el);
await act(() => {
const el = document.createElement('div');
const root = ReactDOMClient.createRoot(el);
expect(() => {
ReactDOM.flushSync(() => {
root.render(<Child incrementBy={0} />);
});
}).toErrorDev(
'Warning: The <Child /> component appears to be a function component that returns a class instance. ' +
'Change Child to a class that extends React.Component instead. ' +
"If you can't use a class try assigning the prototype on the function as a workaround. " +
'`Child.prototype = React.Component.prototype`. ' +
"Don't use an arrow function since it cannot be called with `new` by React.",
);

expect(el.textContent).toBe('count:1');
await act(() => {
root.render(<Child incrementBy={2} />);
});
expect(el.textContent).toBe('count:3');
expect(el.textContent).toBe('count:1');
await act(() => {
root.render(<Child incrementBy={2} />);
});
expect(el.textContent).toBe('count:3');

await act(() => {
root.render(<Child incrementBy={1} />);
});
expect(el.textContent).toBe('count:4');
await act(() => {
root.render(<Child incrementBy={1} />);
});
}
expect(el.textContent).toBe('count:4');
});

it('should not support setState in componentWillUnmount', async () => {
let subscription;
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/src/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ let act;

describe('ReactDOM', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/src/__tests__/ReactDOMAttribute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('ReactDOM unknown attribute', () => {
let act;

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('ReactDOMComponent', () => {
let act;

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('ReactDOMConsoleErrorReporting', () => {
let waitForThrow;

beforeEach(() => {
jest.resetModules();
act = require('internal-test-utils').act;
React = require('react');
ReactDOMClient = require('react-dom/client');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('ReactDOMConsoleErrorReporting', () => {
let waitForThrow;

beforeEach(() => {
jest.resetModules();
act = require('internal-test-utils').act;
React = require('react');
ReactDOM = require('react-dom');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('ReactDOMEventListener', () => {
let act;

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('ReactDOMEventListener', () => {

beforeEach(() => {
window.TextEvent = function () {};
jest.resetModules();
jest.isolateModules(() => {
React = require('react');
act = require('internal-test-utils').act;
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/src/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('ReactDOMFiber', () => {
let container;

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
PropTypes = require('prop-types');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ let Suspense;

describe('ReactDOMFizzForm', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
Scheduler = require('scheduler');
ReactDOMServer = require('react-dom/server.browser');
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/src/__tests__/ReactDOMFizzForm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ let useFormState;

describe('ReactDOMFizzForm', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMServer = require('react-dom/server.browser');
ReactDOMClient = require('react-dom/client');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ let streamingContainer;

describe('ReactDOMFizzServer', () => {
beforeEach(() => {
jest.resetModules();
JSDOM = require('jsdom').JSDOM;

const jsdom = new JSDOM(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ let Suspense;

describe('ReactDOMFizzServerBrowser', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMFizzServer = require('react-dom/server.browser');
Suspense = React.Suspense;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ let ReactDOMFizzServer;

describe('ReactDOMFizzServerEdge', () => {
beforeEach(() => {
jest.resetModules();
jest.useRealTimers();
React = require('react');
ReactDOM = require('react-dom');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ let Suspense;

describe('ReactDOMFizzServerNode', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMFizzServer = require('react-dom/server');
Stream = require('stream');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ let assertLog;

describe('ReactDOMFizzShellHydration', () => {
beforeEach(() => {
jest.resetModules();
JSDOM = require('jsdom').JSDOM;
React = require('react');
ReactDOMClient = require('react-dom/client');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ let fatalError = undefined;

describe('ReactDOMFizzStatic', () => {
beforeEach(() => {
jest.resetModules();
JSDOM = require('jsdom').JSDOM;
React = require('react');
ReactDOM = require('react-dom');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ let container;

describe('ReactDOMFizzStaticBrowser', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactDOMFizzServer = require('react-dom/server.browser');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ let container;

describe('ReactDOMFizzStaticFloat', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactDOMFizzServer = require('react-dom/server.browser');
Expand Down
Loading

0 comments on commit 8c35c8c

Please sign in to comment.