Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eagerly evaluate inline requires in Jest #7245

Merged
merged 2 commits into from
Jul 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/isomorphic/classic/types/checkReactTypeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ var ReactPropTypesSecret = require('ReactPropTypesSecret');
var invariant = require('invariant');
var warning = require('warning');

var ReactComponentTreeDevtool;

if (process.env.NODE_ENV === 'test') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully expect this to break internally unless we check if (process && process.env && process.env.NODE_ENV = 'test').

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah, __DEV__ “works” because it’s how it’s called internally! :steve_jobs_fireworks:

// Temporary hack.
// Inline requires don't work well with Jest:
// https://github.com/facebook/react/issues/7240
// Remove the inline requires when we don't need them anymore:
// https://github.com/facebook/react/pull/7178
ReactComponentTreeDevtool = require('ReactComponentTreeDevtool')
}

var loggedTypeFailures = {};

/**
Expand Down Expand Up @@ -73,7 +84,9 @@ function checkReactTypeSpec(typeSpecs, values, location, componentName, element,
var componentStackInfo = '';

if (__DEV__) {
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
if (!ReactComponentTreeDevtool) {
ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
}
if (debugID !== null) {
componentStackInfo = ReactComponentTreeDevtool.getStackAddendumByID(debugID);
} else if (element !== null) {
Expand Down
15 changes: 14 additions & 1 deletion src/renderers/shared/stack/reconciler/ReactChildReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
var traverseAllChildren = require('traverseAllChildren');
var warning = require('warning');

var ReactComponentTreeDevtool;

if (process.env.NODE_ENV === 'test') {
// Temporary hack.
// Inline requires don't work well with Jest:
// https://github.com/facebook/react/issues/7240
// Remove the inline requires when we don't need them anymore:
// https://github.com/facebook/react/pull/7178
ReactComponentTreeDevtool = require('ReactComponentTreeDevtool')
}

function instantiateChild(childInstances, child, name, selfDebugID) {
// We found a component instance.
var keyUnique = (childInstances[name] === undefined);
if (__DEV__) {
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
if (!ReactComponentTreeDevtool) {
ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
}
warning(
keyUnique,
'flattenChildren(...): Encountered two children with the same key, ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,6 @@ function testPropsSequence(sequence) {
describe('ReactMultiChildReconcile', function() {
beforeEach(function() {
jest.resetModuleRegistry();

React = require('React');
ReactDOM = require('ReactDOM');
ReactDOMComponentTree = require('ReactDOMComponentTree');
ReactInstanceMap = require('ReactInstanceMap');
mapObject = require('mapObject');
});

it('should reset internal state if removed then readded', function() {
Expand Down
8 changes: 0 additions & 8 deletions src/renderers/shared/stack/reconciler/__tests__/refs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ var expectClickLogsLengthToBe = function(instance, length) {
describe('reactiverefs', function() {
beforeEach(function() {
jest.resetModuleRegistry();

React = require('React');
ReactTestUtils = require('ReactTestUtils');
reactComponentExpect = require('reactComponentExpect');
});

/**
Expand Down Expand Up @@ -163,10 +159,6 @@ describe('reactiverefs', function() {
describe('ref swapping', function() {
beforeEach(function() {
jest.resetModuleRegistry();

React = require('React');
ReactTestUtils = require('ReactTestUtils');
reactComponentExpect = require('reactComponentExpect');
});

var RefHopsAround = React.createClass({
Expand Down
15 changes: 14 additions & 1 deletion src/shared/utils/flattenChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ var KeyEscapeUtils = require('KeyEscapeUtils');
var traverseAllChildren = require('traverseAllChildren');
var warning = require('warning');

var ReactComponentTreeDevtool;

if (process.env.NODE_ENV === 'test') {
// Temporary hack.
// Inline requires don't work well with Jest:
// https://github.com/facebook/react/issues/7240
// Remove the inline requires when we don't need them anymore:
// https://github.com/facebook/react/pull/7178
ReactComponentTreeDevtool = require('ReactComponentTreeDevtool')
}

/**
* @param {function} traverseContext Context passed through traversal.
* @param {?ReactComponent} child React child component.
Expand All @@ -33,7 +44,9 @@ function flattenSingleChildIntoContext(
const result = traverseContext;
const keyUnique = (result[name] === undefined);
if (__DEV__) {
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
if (!ReactComponentTreeDevtool) {
ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
}
warning(
keyUnique,
'flattenChildren(...): Encountered two children with the same key, ' +
Expand Down