Skip to content

Commit f9c0a45

Browse files
authored
Convert the rest of react-dom and react-test-renderer to Named Exports (#18145)
Nothing interesting here except that ReactShallowRenderer currently exports a class with a static method instead of an object. I think the public API is probably just meant to be createRenderer but currently the whole class is exposed. So this means that we have to keep it as default export. We could potentially also expose a named export for createRenderer but that's going to cause compatibility issues. So I'm just going to make that export default. Unfortunately Rollup and Babel (which powers Jest) disagree on how to import this. So to make it work I had to move the jest tests to imports. This doesn't work with module resetting. Some tests weren't doing that anyway and the rest is just testing ReactShallowRenderer so meh.
1 parent 2738b6d commit f9c0a45

22 files changed

+412
-471
lines changed

packages/react-dom/server.browser.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactDOMServer = require('./src/server/ReactDOMServerBrowser');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest
16-
module.exports = ReactDOMServer.default || ReactDOMServer;
10+
export {
11+
renderToString,
12+
renderToStaticMarkup,
13+
renderToNodeStream,
14+
renderToStaticNodeStream,
15+
version,
16+
} from './src/server/ReactDOMServerBrowser';

packages/react-dom/server.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
module.exports = require('./server.node');
10+
export * from './server.node';

packages/react-dom/server.node.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
* @flow
88
*/
99

10-
'use strict';
11-
12-
const ReactDOMServer = require('./src/server/ReactDOMServerNode');
13-
14-
// TODO: decide on the top-level export form.
15-
// This is hacky but makes it work with both Rollup and Jest
16-
module.exports = ReactDOMServer.default || ReactDOMServer;
10+
// For some reason Flow doesn't like export * in this file. I don't know why.
11+
export {
12+
renderToString,
13+
renderToStaticMarkup,
14+
renderToNodeStream,
15+
renderToStaticNodeStream,
16+
version,
17+
} from './src/server/ReactDOMServerNode';

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
'use strict';
1111

12-
let createRenderer;
13-
let React;
14-
let ReactDOM;
15-
let ReactDOMServer;
16-
let ReactTestUtils;
12+
import ReactShallowRenderer from 'react-test-renderer/shallow';
13+
import * as React from 'react';
14+
import * as ReactDOM from 'react-dom';
15+
import * as ReactDOMServer from 'react-dom/server';
16+
import * as ReactTestUtils from 'react-dom/test-utils';
1717

1818
function getTestDocument(markup) {
1919
const doc = document.implementation.createHTMLDocument('');
@@ -27,14 +27,6 @@ function getTestDocument(markup) {
2727
}
2828

2929
describe('ReactTestUtils', () => {
30-
beforeEach(() => {
31-
createRenderer = require('react-test-renderer/shallow').createRenderer;
32-
React = require('react');
33-
ReactDOM = require('react-dom');
34-
ReactDOMServer = require('react-dom/server');
35-
ReactTestUtils = require('react-dom/test-utils');
36-
});
37-
3830
it('Simulate should have locally attached media events', () => {
3931
expect(Object.keys(ReactTestUtils.Simulate).sort()).toMatchSnapshot();
4032
});
@@ -403,7 +395,7 @@ describe('ReactTestUtils', () => {
403395
}
404396

405397
const handler = jest.fn().mockName('spy');
406-
const shallowRenderer = createRenderer();
398+
const shallowRenderer = ReactShallowRenderer.createRenderer();
407399
const result = shallowRenderer.render(
408400
<SomeComponent handleClick={handler} />,
409401
);

packages/react-dom/src/server/ReactDOMFizzServerBrowser.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ function renderToReadableStream(children: ReactNodeList): ReadableStream {
2929
});
3030
}
3131

32-
export default {
33-
renderToReadableStream,
34-
};
32+
export {renderToReadableStream};

packages/react-dom/src/server/ReactDOMFizzServerNode.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ function pipeToNodeWritable(
2525
startWork(request);
2626
}
2727

28-
export default {
29-
pipeToNodeWritable,
30-
};
28+
export {pipeToNodeWritable};

packages/react-dom/src/server/ReactDOMServerBrowser.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ function renderToStaticNodeStream() {
2626
);
2727
}
2828

29-
// Note: when changing this, also consider https://github.com/facebook/react/issues/11526
30-
export default {
29+
export {
3130
renderToString,
3231
renderToStaticMarkup,
3332
renderToNodeStream,
3433
renderToStaticNodeStream,
35-
version: ReactVersion,
34+
ReactVersion as version,
3635
};

packages/react-dom/src/server/ReactDOMServerNode.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import {
1313
renderToStaticNodeStream,
1414
} from './ReactDOMNodeStreamRenderer';
1515

16-
// Note: when changing this, also consider https://github.com/facebook/react/issues/11526
17-
export default {
16+
export {
1817
renderToString,
1918
renderToStaticMarkup,
2019
renderToNodeStream,
2120
renderToStaticNodeStream,
22-
version: ReactVersion,
21+
ReactVersion as version,
2322
};

0 commit comments

Comments
 (0)