Skip to content

Commit

Permalink
😭😭😭
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Mar 24, 2017
1 parent 4691521 commit 7dba33b
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions scripts/rollup/shims/facebook-www/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,49 @@

'use strict';

const {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
} = require('ReactDOM-fb');
function getTestUtils() {
const ReactDOM = require('ReactDOM-fb');
return ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactTestUtils;
}

module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactTestUtils;
const TestUtils = {...getTestUtils()};

if (__DEV__) {
// Lasciate ogni speranza, voi ch'entrate.
//
// Some www tests currently rely on require('ReactTestUtils') acting as a lazy
// require for the whole ReactDOM implementation. However this is no longer
// the case with flat bundles since the implementation doesn't get transformed
// by www lazy requires. As a result, if test calls jest.resetModuleRegistry()
// in beforeEach(), Enzyme's ReactDOM reference will be stale and won't be
// able to share any global state (such as current owner) with the newly reset
// React singleton that would be used in classes inside the test cases.
// To work around it, I'm making any TestUtils method call proxy to the latest
// ReactDOM implementation. There might be a better way to do it but my brain
// is fried. If you have ideas, please change it to something more reasonable.
//
// https://fburl.com/jgn0nh70
Object.keys(TestUtils).forEach(key => {
Object.defineProperty(TestUtils, key, {
get() {
return getTestUtils()[key];
},
});
})
Object.keys(TestUtils.Simulate).forEach(key => {
Object.defineProperty(TestUtils.Simulate, key, {
get() {
return getTestUtils().Simulate[key];
},
});
});
Object.keys(TestUtils.SimulateNative).forEach(key => {
Object.defineProperty(TestUtils.SimulateNative, key, {
get() {
return getTestUtils().SimulateNative[key];
},
});
});
}

module.exports = TestUtils;

0 comments on commit 7dba33b

Please sign in to comment.