Bug 1430925 - Avoid JSON Viewer test timeouts when RequireJS fails
MozReview-Commit-ID: AEawTHPW2Fn
--- 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) {