Skip to content

Commit

Permalink
Convert the rest of react-dom and react-test-renderer to Named Exports (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
sebmarkbage authored Feb 27, 2020
1 parent 2738b6d commit f9c0a45
Show file tree
Hide file tree
Showing 22 changed files with 412 additions and 471 deletions.
14 changes: 7 additions & 7 deletions packages/react-dom/server.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* @flow
*/

'use strict';

const ReactDOMServer = require('./src/server/ReactDOMServerBrowser');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
module.exports = ReactDOMServer.default || ReactDOMServer;
export {
renderToString,
renderToStaticMarkup,
renderToNodeStream,
renderToStaticNodeStream,
version,
} from './src/server/ReactDOMServerBrowser';
4 changes: 1 addition & 3 deletions packages/react-dom/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./server.node');
export * from './server.node';
15 changes: 8 additions & 7 deletions packages/react-dom/server.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
* @flow
*/

'use strict';

const ReactDOMServer = require('./src/server/ReactDOMServerNode');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest
module.exports = ReactDOMServer.default || ReactDOMServer;
// For some reason Flow doesn't like export * in this file. I don't know why.
export {
renderToString,
renderToStaticMarkup,
renderToNodeStream,
renderToStaticNodeStream,
version,
} from './src/server/ReactDOMServerNode';
20 changes: 6 additions & 14 deletions packages/react-dom/src/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

'use strict';

let createRenderer;
let React;
let ReactDOM;
let ReactDOMServer;
let ReactTestUtils;
import ReactShallowRenderer from 'react-test-renderer/shallow';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as ReactDOMServer from 'react-dom/server';
import * as ReactTestUtils from 'react-dom/test-utils';

function getTestDocument(markup) {
const doc = document.implementation.createHTMLDocument('');
Expand All @@ -27,14 +27,6 @@ function getTestDocument(markup) {
}

describe('ReactTestUtils', () => {
beforeEach(() => {
createRenderer = require('react-test-renderer/shallow').createRenderer;
React = require('react');
ReactDOM = require('react-dom');
ReactDOMServer = require('react-dom/server');
ReactTestUtils = require('react-dom/test-utils');
});

it('Simulate should have locally attached media events', () => {
expect(Object.keys(ReactTestUtils.Simulate).sort()).toMatchSnapshot();
});
Expand Down Expand Up @@ -403,7 +395,7 @@ describe('ReactTestUtils', () => {
}

const handler = jest.fn().mockName('spy');
const shallowRenderer = createRenderer();
const shallowRenderer = ReactShallowRenderer.createRenderer();
const result = shallowRenderer.render(
<SomeComponent handleClick={handler} />,
);
Expand Down
4 changes: 1 addition & 3 deletions packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ function renderToReadableStream(children: ReactNodeList): ReadableStream {
});
}

export default {
renderToReadableStream,
};
export {renderToReadableStream};
4 changes: 1 addition & 3 deletions packages/react-dom/src/server/ReactDOMFizzServerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ function pipeToNodeWritable(
startWork(request);
}

export default {
pipeToNodeWritable,
};
export {pipeToNodeWritable};
5 changes: 2 additions & 3 deletions packages/react-dom/src/server/ReactDOMServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ function renderToStaticNodeStream() {
);
}

// Note: when changing this, also consider https://github.com/facebook/react/issues/11526
export default {
export {
renderToString,
renderToStaticMarkup,
renderToNodeStream,
renderToStaticNodeStream,
version: ReactVersion,
ReactVersion as version,
};
5 changes: 2 additions & 3 deletions packages/react-dom/src/server/ReactDOMServerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import {
renderToStaticNodeStream,
} from './ReactDOMNodeStreamRenderer';

// Note: when changing this, also consider https://github.com/facebook/react/issues/11526
export default {
export {
renderToString,
renderToStaticMarkup,
renderToNodeStream,
renderToStaticNodeStream,
version: ReactVersion,
ReactVersion as version,
};
Loading

0 comments on commit f9c0a45

Please sign in to comment.