Skip to content

Commit 55b1fe7

Browse files
RandomBytematz3
authored andcommitted
[FIX] middleware/testRunner: Update resources from OpenUI5
Based on: UI5/openui5@454a282
1 parent 8864ed4 commit 55b1fe7

File tree

2 files changed

+97
-27
lines changed

2 files changed

+97
-27
lines changed

lib/middleware/testRunner/TestRunner.js

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,52 @@
2424
this.aPages.push(sTestPage);
2525
};
2626

27+
function XHRQueue(iMaxParallelRequests, iWaitTime) {
28+
this.iLimit = iMaxParallelRequests === undefined ? Infinity : iMaxParallelRequests;
29+
this.iWaitTime = iWaitTime === undefined ? 0 : iWaitTime;
30+
this.aPendingTasks = [];
31+
this.oRunningTasks = new Set();
32+
this.iLastTaskExecution = -Infinity;
33+
}
34+
35+
XHRQueue.prototype.ajax = function(sUrl, options) {
36+
var oTask = {
37+
url: sUrl,
38+
options: options
39+
};
40+
oTask.promise = new Promise(function(resolve, reject) {
41+
oTask.resolve = resolve;
42+
oTask.reject = reject;
43+
});
44+
this.aPendingTasks.push(oTask);
45+
this._processNext();
46+
return oTask.promise;
47+
};
48+
49+
XHRQueue.prototype._processNext = function() {
50+
var iNow = Date.now();
51+
var iDelay = iNow - this.iLastTaskExecution;
52+
if ( iDelay < this.iWaitTime ) {
53+
setTimeout(function() {
54+
this._processNext();
55+
}.bind(this), iDelay);
56+
return;
57+
}
58+
if ( this.aPendingTasks.length > 0 && this.oRunningTasks.size < this.iLimit ) {
59+
var oTask = this.aPendingTasks.shift();
60+
this.oRunningTasks.add(oTask);
61+
this.iLastTaskExecution = iNow;
62+
Promise.resolve(jQuery.ajax(oTask.url, oTask.options))
63+
.then(oTask.resolve, oTask.reject)
64+
.finally(function() {
65+
this.oRunningTasks.delete(oTask);
66+
this._processNext();
67+
}.bind(this));
68+
}
69+
};
70+
71+
var oXHRQueue = new XHRQueue(50, 2);
72+
2773
/*
2874
* Template for test results
2975
*/
@@ -62,6 +108,21 @@
62108
window.sap.ui.qunit.TestRunner = {
63109

64110
checkTestPage: function(sTestPage, bSequential) {
111+
var t0 = Date.now();
112+
var oPromise =
113+
this._checkTestPage(sTestPage, bSequential)
114+
.then(function(aTestPages) {
115+
var t1 = Date.now();
116+
window.console.log("[DEBUG] checkTestPage(\"" + sTestPage + "\") found " + aTestPages.length + " pages in " + (t1 - t0) + "msec.");
117+
window.console.log("[DEBUG] checkTestPage(\"" + sTestPage + "\") currently running IFrames: " + window.frames.length);
118+
return aTestPages;
119+
});
120+
oPromise.done = oPromise.then; // compat for Deferred
121+
oPromise.fail = oPromise.catch; // compat for Deferred
122+
return oPromise;
123+
},
124+
125+
_checkTestPage: function(sTestPage, bSequential) {
65126

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

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

134+
/*
73135
if (window.console && typeof window.console.log === "function") {
74136
window.console.log("QUnit: checking test page: " + sTestPage);
75-
}
137+
}*/
76138

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

84147
var onSuiteReady = function(oIFrame) {
85148
that.findTestPages(oIFrame, bSequential).then(function(aTestPages) {
149+
var aTestPagesFiltered = aTestPages.filter(function(e, i, a) { return a.indexOf(e) === i; });
86150
$frame.remove();
87151
// avoid duplicates in test pages
88-
resolve(aTestPages.filter(function(e, i, a) { return a.indexOf(e) === i; }));
152+
resolve(aTestPagesFiltered);
89153
}, function(oError) {
90154
if (window.console && typeof window.console.error === "function") {
91-
window.console.error("QUnit: failed to load page '" + sTestPage + "'");
155+
window.console.error("QUnit: failed to load page '" + sTestPage + "'" + " Error: " + oError);
92156
}
93157
$frame.remove();
94158
resolve([]);
@@ -111,7 +175,7 @@
111175
} else {
112176
resolve([sTestPage]);
113177
}
114-
}.bind(this)).fail(function(xhr,status,msg) {
178+
}.bind(this)).catch(function(xhr,status,msg) {
115179
var text = (xhr ? xhr.status + " " : "") + (msg || status || 'unspecified error');
116180
if (window.console && typeof window.console.error === "function") {
117181
window.console.error("QUnit: failed to load page '" + sTestPage + "': " + text);
@@ -123,17 +187,18 @@
123187

124188
}.bind(this));
125189

126-
oPromise.done = oPromise.then; // compat for Deferred
127-
oPromise.fail = oPromise.catch; // compat for Deferred
128-
129190
return oPromise;
130191

131192
},
132193

133194
findTestPages: function(oIFrame, bSequential) {
134195

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

139204
try {
@@ -146,7 +211,7 @@
146211

147212
var aTestPages = [];
148213
aTestPagePromises.push(aPages.reduce(function(oPromise, sTestPage) {
149-
return oPromise.then(this.checkTestPage.bind(this, sTestPage, bSequential)).then(function(aFoundTestPages) {
214+
return oPromise.then(this._checkTestPage.bind(this, sTestPage, bSequential)).then(function(aFoundTestPages) {
150215
aTestPages = aTestPages.concat(aFoundTestPages);
151216
});
152217
}.bind(this), Promise.resolve([])).then(function() {
@@ -157,7 +222,7 @@
157222

158223
for (var i = 0, l = aPages.length; i < l; i++) {
159224
var sTestPage = aPages[i];
160-
aTestPagePromises.push(this.checkTestPage(sTestPage, bSequential));
225+
aTestPagePromises.push(this._checkTestPage(sTestPage, bSequential));
161226
}
162227

163228
}
@@ -169,6 +234,11 @@
169234
aTestPages = aTestPages.concat(aFoundTestPages[i]);
170235
}
171236
resolve(aTestPages);
237+
})
238+
.catch(function(oError){
239+
if (window.console && typeof window.console.error === "function") {
240+
window.console.error("[DEBUG] findTestPages Promise.all error: " + oError);
241+
}
172242
});
173243
}
174244

@@ -267,10 +337,10 @@
267337
var sHTML = fnTemplate(oContext);
268338
var $testResult = jQuery(sHTML);
269339
var $children = $testResult.children();
270-
jQuery($children[0]).click(function() {
340+
jQuery($children[0]).on("click", function() {
271341
jQuery(this.nextSibling).toggle();
272342
});
273-
jQuery($children[1]).find("li.test > p").click(function() {
343+
jQuery($children[1]).find("li.test > p").on("click", function() {
274344
jQuery(this.parentElement.children[2]).toggle();
275345
});
276346
$testResult.appendTo("div.test-reporting");

lib/middleware/testRunner/testrunner.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
});
3333
jQuery(selectbox).data("options", options);
3434

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

4040
jQuery.each(options, function(i) {
4141
var option = options[i];
4242
if(option.text.match(regex) !== null) {
43-
jQuery(selectbox).append(jQuery("<option>").text(option.text).val(option.value).dblclick(function() {
43+
jQuery(selectbox).append(jQuery("<option>").text(option.text).val(option.value).on("dblclick", function() {
4444
jQuery("#selectedTests").append(jQuery(this).clone());
4545
}));
4646
}
@@ -77,7 +77,7 @@
7777
$this.val("Show all results");
7878
}
7979
}
80-
jQuery("#showResults").click(showResults);
80+
jQuery("#showResults").on("click", showResults);
8181

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

@@ -92,7 +92,7 @@
9292
var fnTemplate = Handlebars.compile(jQuery("#qunitResults").html());
9393
var sHTML = fnTemplate(oContext);
9494
jQuery("#testPageSelectDiv").html(sHTML);
95-
jQuery("#testPageSelect > option").dblclick(function () {
95+
jQuery("#testPageSelect > option").on("dblclick", function () {
9696
jQuery("#selectedTests").append(jQuery("#find").clone());
9797
});
9898
jQuery("#copyButtons").show();
@@ -103,34 +103,34 @@
103103
jQuery("#console").val(aTestPages.join("\n"));
104104
});
105105
}
106-
jQuery("#find").click(find);
106+
jQuery("#find").on("click", find);
107107

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

115115
function copyAll() {
116116
jQuery("#selectedTests").append(jQuery("#testPageSelect > option").clone());
117117
}
118-
jQuery("#copyall").click(copyAll);
118+
jQuery("#copyall").on("click", copyAll);
119119

120120
function remove() {
121121
var aSelectedTests = jQuery("#selectedTests")[0].selectedOptions;
122122
for (var i = aSelectedTests.length-1; i >= 0; i--) {
123123
jQuery(aSelectedTests[i]).remove();
124124
}
125-
}jQuery("#remove").click(remove);
125+
}jQuery("#remove").on("click", remove);
126126

127127
function removeAll() {
128128
jQuery("#selectedTests > option").remove();
129129
}
130-
jQuery("#removeall").click(removeAll);
130+
jQuery("#removeall").on("click", removeAll);
131131

132132
function run() {
133-
jQuery("#open").click();
133+
jQuery("#open").trigger("click");
134134
window.oStartTime = new Date();
135135
var $this = jQuery("#run");
136136
if ($this.val() === "Run") {
@@ -160,7 +160,7 @@
160160
}
161161
}
162162

163-
jQuery("#run").click(function () {
163+
jQuery("#run").on("click", function () {
164164
if(jQuery("#selectedTests>option").length === 0) {
165165
alert("Please select at least on test to execute");
166166
} else {
@@ -184,7 +184,7 @@
184184
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;");
185185
}
186186
}
187-
jQuery("#open").click(open);
187+
jQuery("#open").on("click", open);
188188

189189

190190
function openCoverage() {
@@ -196,7 +196,7 @@
196196
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;");
197197
}
198198
}
199-
jQuery("#openCoverage").click(openCoverage);
199+
jQuery("#openCoverage").on("click", openCoverage);
200200

201201
function openReporting() {
202202
jQuery("#showResults").toggle();
@@ -211,12 +211,12 @@
211211
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;");
212212
}
213213
}
214-
jQuery("#openReporting").click(openReporting);
214+
jQuery("#openReporting").on("click", openReporting);
215215

216216
function stop() {
217217
sap.ui.qunit.TestRunner.stopTests();
218218
}
219-
jQuery("#stop").click(stop);
219+
jQuery("#stop").on("click", stop);
220220

221221
setInterval(function() {
222222
if (window.aTestPages) {

0 commit comments

Comments
 (0)