Bug 1552420 - Add a mock for ChromeUtils in mocha tests. r=jdescottes.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Fri, 17 May 2019 12:36:12 +0000
changeset 533154 5a1c37d11ebc5ced51587ed936abb38ff788ec43
parent 533153 fb21a998b3272f9947df63ba9acd9cd016571371
child 533155 8952fe75cb7a65e4f8d718439f6e156ed179c66f
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1552420
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1552420 - Add a mock for ChromeUtils in mocha tests. r=jdescottes. This fixes the test failures. We remove the requireHacker case for ChromeUtils, since it's never required. Differential Revision: https://phabricator.services.mozilla.com/D31583
devtools/client/webconsole/test/mocha-test-setup.js
--- a/devtools/client/webconsole/test/mocha-test-setup.js
+++ b/devtools/client/webconsole/test/mocha-test-setup.js
@@ -62,16 +62,22 @@ global.isWorker = false;
 global.indexedDB = {open: () => ({})};
 
 // URLSearchParams was added to the global object in Node 10.0.0. To not cause any issue
 // with prior versions, we add it to the global object if it is not defined there.
 if (!global.URLSearchParams) {
   global.URLSearchParams = require("url").URLSearchParams;
 }
 
+// Mock ChromeUtils.
+global.ChromeUtils = {
+  import: () => {},
+  defineModuleGetter: () => {},
+};
+
 // Point to vendored-in files and mocks when needed.
 const requireHacker = require("require-hacker");
 requireHacker.global_hook("default", (path, module) => {
   switch (path) {
     // For Enzyme
     case "react-dom":
       return getModule("devtools/client/shared/vendor/react-dom");
     case "react-dom/server":
@@ -81,18 +87,16 @@ requireHacker.global_hook("default", (pa
     case "react-redux":
       return getModule("devtools/client/shared/vendor/react-redux");
     // Use react-dev. This would be handled by browserLoader in Firefox.
     case "react":
     case "devtools/client/shared/vendor/react":
       return getModule("devtools/client/shared/vendor/react-dev");
     case "chrome":
       return `module.exports = { Cc: {}, Ci: {}, Cu: {} }`;
-    case "ChromeUtils":
-      return `module.exports = { import: () => {} }`;
   }
 
   // Some modules depend on Chrome APIs which don't work in mocha. When such a module
   // is required, replace it with a mock version.
   switch (path) {
     case "devtools/shared/l10n":
       return getModule(
         "devtools/client/webconsole/test/fixtures/LocalizationHelper");