Bug 1430925 - Avoid JSON Viewer test timeouts when RequireJS fails draft
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Mon, 15 Jan 2018 03:45:36 +0100
changeset 721589 724dfb33df76b4f7835f6e34614a7f6a65b5051a
parent 721495 4e429d313fd2e0f9202271ee8f3fb798817ec3e7
child 746374 57c023d6fac772f1373fbd02d9bc06248993e603
push id95880
push userbmo:oriol-bugzilla@hotmail.com
push dateWed, 17 Jan 2018 14:13:51 +0000
bugs1430925
milestone59.0a1
Bug 1430925 - Avoid JSON Viewer test timeouts when RequireJS fails MozReview-Commit-ID: AEawTHPW2Fn
devtools/client/jsonview/test/head.js
--- a/devtools/client/jsonview/test/head.js
+++ b/devtools/client/jsonview/test/head.js
@@ -64,19 +64,31 @@ async function addJsonViewTab(url, {
       },
     }, Ci.nsIWebProgress.NOTIFY_LOCATION);
   })]);
 
   // Load devtools/shared/frame-script-utils.js
   getFrameScript();
   let rootDir = getRootDirectory(gTestPath);
 
+  // Catch RequireJS errors (usually timeouts)
+  let error = tabLoaded.then(() => new Promise((resolve, reject) => {
+    let {requirejs} = content.wrappedJSObject;
+    if (requirejs) {
+      requirejs.onError = err => {
+        info(err);
+        ok(false, "RequireJS error");
+        reject(err);
+      };
+    }
+  }));
+
   let data = {rootDir, appReadyState, docReadyState};
   // eslint-disable-next-line no-shadow
-  await ContentTask.spawn(browser, data, async function (data) {
+  await Promise.race([error, ContentTask.spawn(browser, data, async function (data) {
     // Check if there is a JSONView object.
     let {JSONView} = content.window.wrappedJSObject;
     if (!JSONView) {
       throw new Error("The JSON Viewer did not load.");
     }
 
     // Load frame script with helpers for JSON View tests.
     let frameScriptUrl = data.rootDir + "doc_frame_script.js";
@@ -101,17 +113,17 @@ async function addJsonViewTab(url, {
 
     // Wait until the app readyState suffices.
     while (appReadyStates.indexOf(JSONView.readyState) < appReadyIndex) {
       info(`AppReadyState is "${JSONView.readyState}". Await "${data.appReadyState}"`);
       await new Promise(resolve => {
         content.addEventListener("AppReadyStateChange", resolve, {once: true});
       });
     }
-  });
+  })]);
 
   return tab;
 }
 
 /**
  * Expanding a node in the JSON tree
  */
 function clickJsonNode(selector) {