Bug 1321518 - Fix requireHelper for enzyme. r=bgrins
authorNicolas Chevobbe <chevobbe.nicolas@gmail.com>
Thu, 01 Dec 2016 19:47:36 +0100
changeset 325047 7068e81c96ae3c61940313fef3835afff3829fcc
parent 325046 402535c480347e46f743ba6b96d25298bdf07651
child 325048 78e5f82eb83aad9c34c047f63927cbf5b1143a1f
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersbgrins
bugs1321518, 1312236
milestone53.0a1
Bug 1321518 - Fix requireHelper for enzyme. r=bgrins Bug 1312236 updated React to v15.3.2 which was making webconsole's mocha test fail. An error was thrown because the path and export we do in requireHelper to make enzyme able to call React functions was changed. We fix the require to ReactDOM by using the react-dom.js file, and we add the similar react-dom-server.js for ReactDOMServer functions. Tests now run like they used to. MozReview-Commit-ID: GXIQJPlqp4A
devtools/client/shared/vendor/REACT_UPGRADING
devtools/client/shared/vendor/moz.build
devtools/client/shared/vendor/react-dom-server.js
devtools/client/webconsole/new-console-output/test/require-helper.js
--- a/devtools/client/shared/vendor/REACT_UPGRADING
+++ b/devtools/client/shared/vendor/REACT_UPGRADING
@@ -46,14 +46,16 @@ Unfortunately, you need to manually repl
 calls in this version again. We know this is not ideal but WE NEED TO
 MOVE OFF XUL and we don't need to do this anymore once that happens.
 
 After patching `build/react-with-addons.js` again, copy the production
 version over:
 
 * cp build/react-with-addons.js <gecko-dev>/devtools/client/shared/vendor/react.js
 
-You also need to copy the ReactDOM package. It requires React, so
+You also need to copy the ReactDOM and ReactDOMServer package. It requires React, so
 right now we are just manually changing the path from `react` to
 `devtools/client/shared/vendor/react`.
 
 * cp build/react-dom.js <gecko-dev>/devtools/client/shared/vendor/react-dom.js
 * (change `require('react')` at the top of the file to the right path)
+* cp build/react-dom.js <gecko-dev>/devtools/client/shared/vendor/react-dom-server.js
+* (change `require('react')` at the top of the file to the right path)
--- a/devtools/client/shared/vendor/moz.build
+++ b/devtools/client/shared/vendor/moz.build
@@ -11,16 +11,17 @@ modules += [
 ]
 
 # react-dev is used if either debug mode is enabled,
 # so include it for both
 if CONFIG['DEBUG_JS_MODULES'] or CONFIG['MOZ_DEBUG']:
     modules += ['react-dev.js']
 
 modules += [
+    'react-dom-server.js',
     'react-dom.js',
     'react-proxy.js',
     'react-redux.js',
     'react-virtualized.js',
     'react.js',
     'redux.js',
     'reselect.js',
     'seamless-immutable.js',
new file mode 100644
--- /dev/null
+++ b/devtools/client/shared/vendor/react-dom-server.js
@@ -0,0 +1,42 @@
+/**
+ * ReactDOMServer v15.3.2
+ *
+ * Copyright 2013-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ *
+ */
+// Based off https://github.com/ForbesLindesay/umd/blob/master/template.js
+;(function(f) {
+  // CommonJS
+  if (typeof exports === "object" && typeof module !== "undefined") {
+    module.exports = f(require('react'));
+
+  // RequireJS
+  } else if (typeof define === "function" && define.amd) {
+    define(['react'], f);
+
+  // <script>
+  } else {
+    var g;
+    if (typeof window !== "undefined") {
+      g = window;
+    } else if (typeof global !== "undefined") {
+      g = global;
+    } else if (typeof self !== "undefined") {
+      g = self;
+    } else {
+      // works providing we're not in "use strict";
+      // needed for Java 8 Nashorn
+      // see https://github.com/facebook/react/issues/3037
+      g = this;
+    }
+    g.ReactDOMServer = f(g.React);
+  }
+
+})(function(React) {
+  return React.__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
+});
--- a/devtools/client/webconsole/new-console-output/test/require-helper.js
+++ b/devtools/client/webconsole/new-console-output/test/require-helper.js
@@ -3,18 +3,19 @@
 "use strict";
 
 const requireHacker = require("require-hacker");
 
 requireHacker.global_hook("default", path => {
   switch (path) {
     // For Enzyme
     case "react-dom":
+      return `const ReactDOM = require('devtools/client/shared/vendor/react-dom'); module.exports = ReactDOM`;
     case "react-dom/server":
-      return `const React = require('devtools/client/shared/vendor/react-dev'); module.exports = React`;
+      return `const ReactDOMServer = require('devtools/client/shared/vendor/react-dom-server'); module.exports = ReactDOMServer`;
     case "react-addons-test-utils":
       return `const React = require('devtools/client/shared/vendor/react-dev'); module.exports = React.addons.TestUtils`;
     case "react-redux":
       return `const ReactRedux = require('devtools/client/shared/vendor/react-redux'); module.exports = ReactRedux`;
     // Use react-dev. This would be handled by browserLoader in Firefox.
     case "react":
     case "devtools/client/shared/vendor/react":
       return `const React = require('devtools/client/shared/vendor/react-dev'); module.exports = React`;