Skip to content

Commit

Permalink
[FIX] middleware/testRunner: Update resources from OpenUI5
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte authored and matz3 committed Sep 2, 2020
1 parent 8864ed4 commit 55b1fe7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 27 deletions.
94 changes: 82 additions & 12 deletions lib/middleware/testRunner/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,52 @@
this.aPages.push(sTestPage);
};

function XHRQueue(iMaxParallelRequests, iWaitTime) {
this.iLimit = iMaxParallelRequests === undefined ? Infinity : iMaxParallelRequests;
this.iWaitTime = iWaitTime === undefined ? 0 : iWaitTime;
this.aPendingTasks = [];
this.oRunningTasks = new Set();
this.iLastTaskExecution = -Infinity;
}

XHRQueue.prototype.ajax = function(sUrl, options) {
var oTask = {
url: sUrl,
options: options
};
oTask.promise = new Promise(function(resolve, reject) {
oTask.resolve = resolve;
oTask.reject = reject;
});
this.aPendingTasks.push(oTask);
this._processNext();
return oTask.promise;
};

XHRQueue.prototype._processNext = function() {
var iNow = Date.now();
var iDelay = iNow - this.iLastTaskExecution;
if ( iDelay < this.iWaitTime ) {
setTimeout(function() {
this._processNext();
}.bind(this), iDelay);
return;
}
if ( this.aPendingTasks.length > 0 && this.oRunningTasks.size < this.iLimit ) {
var oTask = this.aPendingTasks.shift();
this.oRunningTasks.add(oTask);
this.iLastTaskExecution = iNow;
Promise.resolve(jQuery.ajax(oTask.url, oTask.options))
.then(oTask.resolve, oTask.reject)
.finally(function() {
this.oRunningTasks.delete(oTask);
this._processNext();
}.bind(this));
}
};

var oXHRQueue = new XHRQueue(50, 2);

/*
* Template for test results
*/
Expand Down Expand Up @@ -62,6 +108,21 @@
window.sap.ui.qunit.TestRunner = {

checkTestPage: function(sTestPage, bSequential) {
var t0 = Date.now();
var oPromise =
this._checkTestPage(sTestPage, bSequential)
.then(function(aTestPages) {
var t1 = Date.now();
window.console.log("[DEBUG] checkTestPage(\"" + sTestPage + "\") found " + aTestPages.length + " pages in " + (t1 - t0) + "msec.");
window.console.log("[DEBUG] checkTestPage(\"" + sTestPage + "\") currently running IFrames: " + window.frames.length);
return aTestPages;
});
oPromise.done = oPromise.then; // compat for Deferred
oPromise.fail = oPromise.catch; // compat for Deferred
return oPromise;
},

_checkTestPage: function(sTestPage, bSequential) {

var oPromise = new Promise(function(resolve, reject) {

Expand All @@ -70,25 +131,28 @@
reject("QUnit: invalid test page specified");
}

/*
if (window.console && typeof window.console.log === "function") {
window.console.log("QUnit: checking test page: " + sTestPage);
}
}*/

// check for an existing test page and check for test suite or page
jQuery.get(sTestPage).done(function(sData) {
oXHRQueue.ajax(sTestPage).then(function(sData) {
if (/(?:window\.suite\s*=|function\s*suite\s*\(\s*\)\s*{)/.test(sData)
|| (/data-sap-ui-testsuite/.test(sData) && !/sap\/ui\/test\/starter\/runTest/.test(sData)) ) {
// window.console.log("[DEBUG] _checkTestPage checking testsuite page: " + sTestPage);
var $frame = jQuery("<iframe>");
var that = this;

var onSuiteReady = function(oIFrame) {
that.findTestPages(oIFrame, bSequential).then(function(aTestPages) {
var aTestPagesFiltered = aTestPages.filter(function(e, i, a) { return a.indexOf(e) === i; });
$frame.remove();
// avoid duplicates in test pages
resolve(aTestPages.filter(function(e, i, a) { return a.indexOf(e) === i; }));
resolve(aTestPagesFiltered);
}, function(oError) {
if (window.console && typeof window.console.error === "function") {
window.console.error("QUnit: failed to load page '" + sTestPage + "'");
window.console.error("QUnit: failed to load page '" + sTestPage + "'" + " Error: " + oError);
}
$frame.remove();
resolve([]);
Expand All @@ -111,7 +175,7 @@
} else {
resolve([sTestPage]);
}
}.bind(this)).fail(function(xhr,status,msg) {
}.bind(this)).catch(function(xhr,status,msg) {
var text = (xhr ? xhr.status + " " : "") + (msg || status || 'unspecified error');
if (window.console && typeof window.console.error === "function") {
window.console.error("QUnit: failed to load page '" + sTestPage + "': " + text);
Expand All @@ -123,17 +187,18 @@

}.bind(this));

oPromise.done = oPromise.then; // compat for Deferred
oPromise.fail = oPromise.catch; // compat for Deferred

return oPromise;

},

findTestPages: function(oIFrame, bSequential) {

return Promise.resolve(oIFrame.contentWindow.suite()).then(function(oSuite) {
window.console.log("[DEBUG] findTestPages oIFrame source: " + oIFrame.src);
var aPages = oSuite && oSuite.getTestPages() || [];
for (var i = 0; i < aPages.length; i++) {
window.console.log("[DEBUG] findTestPages oIFrame source " + oIFrame.src + ": " + aPages[i]);
}
return new Promise(function(resolve, reject) {

try {
Expand All @@ -146,7 +211,7 @@

var aTestPages = [];
aTestPagePromises.push(aPages.reduce(function(oPromise, sTestPage) {
return oPromise.then(this.checkTestPage.bind(this, sTestPage, bSequential)).then(function(aFoundTestPages) {
return oPromise.then(this._checkTestPage.bind(this, sTestPage, bSequential)).then(function(aFoundTestPages) {
aTestPages = aTestPages.concat(aFoundTestPages);
});
}.bind(this), Promise.resolve([])).then(function() {
Expand All @@ -157,7 +222,7 @@

for (var i = 0, l = aPages.length; i < l; i++) {
var sTestPage = aPages[i];
aTestPagePromises.push(this.checkTestPage(sTestPage, bSequential));
aTestPagePromises.push(this._checkTestPage(sTestPage, bSequential));
}

}
Expand All @@ -169,6 +234,11 @@
aTestPages = aTestPages.concat(aFoundTestPages[i]);
}
resolve(aTestPages);
})
.catch(function(oError){
if (window.console && typeof window.console.error === "function") {
window.console.error("[DEBUG] findTestPages Promise.all error: " + oError);
}
});
}

Expand Down Expand Up @@ -267,10 +337,10 @@
var sHTML = fnTemplate(oContext);
var $testResult = jQuery(sHTML);
var $children = $testResult.children();
jQuery($children[0]).click(function() {
jQuery($children[0]).on("click", function() {
jQuery(this.nextSibling).toggle();
});
jQuery($children[1]).find("li.test > p").click(function() {
jQuery($children[1]).find("li.test > p").on("click", function() {
jQuery(this.parentElement.children[2]).toggle();
});
$testResult.appendTo("div.test-reporting");
Expand Down
30 changes: 15 additions & 15 deletions lib/middleware/testRunner/testrunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
});
jQuery(selectbox).data("options", options);

jQuery(textbox).bind("change keyup", function() {
jQuery(textbox).on("change keyup", function() {
var options = jQuery(selectbox).empty().data("options");
var search = jQuery(this).val().trim();
var regex = new RegExp(search, "gi");

jQuery.each(options, function(i) {
var option = options[i];
if(option.text.match(regex) !== null) {
jQuery(selectbox).append(jQuery("<option>").text(option.text).val(option.value).dblclick(function() {
jQuery(selectbox).append(jQuery("<option>").text(option.text).val(option.value).on("dblclick", function() {
jQuery("#selectedTests").append(jQuery(this).clone());
}));
}
Expand Down Expand Up @@ -77,7 +77,7 @@
$this.val("Show all results");
}
}
jQuery("#showResults").click(showResults);
jQuery("#showResults").on("click", showResults);

jQuery("#testPage").val(sap.ui.qunit.TestRunner.getTestPageUrl());

Expand All @@ -92,7 +92,7 @@
var fnTemplate = Handlebars.compile(jQuery("#qunitResults").html());
var sHTML = fnTemplate(oContext);
jQuery("#testPageSelectDiv").html(sHTML);
jQuery("#testPageSelect > option").dblclick(function () {
jQuery("#testPageSelect > option").on("dblclick", function () {
jQuery("#selectedTests").append(jQuery("#find").clone());
});
jQuery("#copyButtons").show();
Expand All @@ -103,34 +103,34 @@
jQuery("#console").val(aTestPages.join("\n"));
});
}
jQuery("#find").click(find);
jQuery("#find").on("click", find);

function copy() {
var aSelectedTests = jQuery("#testPageSelect")[0].selectedOptions;
for (var i = 0; i < aSelectedTests.length; i++) {
jQuery("#selectedTests").append(jQuery("<option>").text(jQuery(aSelectedTests[i]).text()).val(jQuery(aSelectedTests[i]).text()));
}
}jQuery("#copy").click(copy);
}jQuery("#copy").on("click", copy);

function copyAll() {
jQuery("#selectedTests").append(jQuery("#testPageSelect > option").clone());
}
jQuery("#copyall").click(copyAll);
jQuery("#copyall").on("click", copyAll);

function remove() {
var aSelectedTests = jQuery("#selectedTests")[0].selectedOptions;
for (var i = aSelectedTests.length-1; i >= 0; i--) {
jQuery(aSelectedTests[i]).remove();
}
}jQuery("#remove").click(remove);
}jQuery("#remove").on("click", remove);

function removeAll() {
jQuery("#selectedTests > option").remove();
}
jQuery("#removeall").click(removeAll);
jQuery("#removeall").on("click", removeAll);

function run() {
jQuery("#open").click();
jQuery("#open").trigger("click");
window.oStartTime = new Date();
var $this = jQuery("#run");
if ($this.val() === "Run") {
Expand Down Expand Up @@ -160,7 +160,7 @@
}
}

jQuery("#run").click(function () {
jQuery("#run").on("click", function () {
if(jQuery("#selectedTests>option").length === 0) {
alert("Please select at least on test to execute");
} else {
Expand All @@ -184,7 +184,7 @@
jQuery("#open").attr("style", "width:0px;height:0px;margin:5px;border-style:solid;border-width:0 12px 12px 12px;border-color:transparent transparent #007dc0 transparent;float: right;position: relative;left: -10px;cursor: pointer;");
}
}
jQuery("#open").click(open);
jQuery("#open").on("click", open);


function openCoverage() {
Expand All @@ -196,7 +196,7 @@
jQuery("#openCoverage").attr("style", "width:0px;height:0px;margin:5px;border-style:solid;border-width:0 12px 12px 12px;border-color:transparent transparent #007dc0 transparent;float: right;position: relative;left: -10px;cursor: pointer;");
}
}
jQuery("#openCoverage").click(openCoverage);
jQuery("#openCoverage").on("click", openCoverage);

function openReporting() {
jQuery("#showResults").toggle();
Expand All @@ -211,12 +211,12 @@
jQuery("#openReporting").attr("style", "width:0px;height:0px;margin:5px;border-style:solid;border-width:0 12px 12px 12px;border-color:transparent transparent #007dc0 transparent;float: right;position: relative;left: -10px;cursor: pointer;");
}
}
jQuery("#openReporting").click(openReporting);
jQuery("#openReporting").on("click", openReporting);

function stop() {
sap.ui.qunit.TestRunner.stopTests();
}
jQuery("#stop").click(stop);
jQuery("#stop").on("click", stop);

setInterval(function() {
if (window.aTestPages) {
Expand Down

0 comments on commit 55b1fe7

Please sign in to comment.