Skip to content
Permalink
Browse files

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.
  • Loading branch information
sebmarkbage committed Feb 27, 2020
1 parent 2738b6d commit f9c0a454415172433b8b94eec94fc36b2461065c
@@ -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';
@@ -7,6 +7,4 @@
* @flow
*/

'use strict';

module.exports = require('./server.node');
export * from './server.node';
@@ -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';
@@ -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('');
@@ -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();
});
@@ -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} />,
);
@@ -29,6 +29,4 @@ function renderToReadableStream(children: ReactNodeList): ReadableStream {
});
}

export default {
renderToReadableStream,
};
export {renderToReadableStream};
@@ -25,6 +25,4 @@ function pipeToNodeWritable(
startWork(request);
}

export default {
pipeToNodeWritable,
};
export {pipeToNodeWritable};
@@ -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,
};
@@ -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,
};

0 comments on commit f9c0a45

Please sign in to comment.
You can’t perform that action at this time.