|
24 | 24 | this.aPages.push(sTestPage);
|
25 | 25 | };
|
26 | 26 |
|
| 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 | + |
27 | 73 | /*
|
28 | 74 | * Template for test results
|
29 | 75 | */
|
|
62 | 108 | window.sap.ui.qunit.TestRunner = {
|
63 | 109 |
|
64 | 110 | 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) { |
65 | 126 |
|
66 | 127 | var oPromise = new Promise(function(resolve, reject) {
|
67 | 128 |
|
|
70 | 131 | reject("QUnit: invalid test page specified");
|
71 | 132 | }
|
72 | 133 |
|
| 134 | + /* |
73 | 135 | if (window.console && typeof window.console.log === "function") {
|
74 | 136 | window.console.log("QUnit: checking test page: " + sTestPage);
|
75 |
| - } |
| 137 | + }*/ |
76 | 138 |
|
77 | 139 | // 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) { |
79 | 141 | if (/(?:window\.suite\s*=|function\s*suite\s*\(\s*\)\s*{)/.test(sData)
|
80 | 142 | || (/data-sap-ui-testsuite/.test(sData) && !/sap\/ui\/test\/starter\/runTest/.test(sData)) ) {
|
| 143 | + // window.console.log("[DEBUG] _checkTestPage checking testsuite page: " + sTestPage); |
81 | 144 | var $frame = jQuery("<iframe>");
|
82 | 145 | var that = this;
|
83 | 146 |
|
84 | 147 | var onSuiteReady = function(oIFrame) {
|
85 | 148 | that.findTestPages(oIFrame, bSequential).then(function(aTestPages) {
|
| 149 | + var aTestPagesFiltered = aTestPages.filter(function(e, i, a) { return a.indexOf(e) === i; }); |
86 | 150 | $frame.remove();
|
87 | 151 | // avoid duplicates in test pages
|
88 |
| - resolve(aTestPages.filter(function(e, i, a) { return a.indexOf(e) === i; })); |
| 152 | + resolve(aTestPagesFiltered); |
89 | 153 | }, function(oError) {
|
90 | 154 | 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); |
92 | 156 | }
|
93 | 157 | $frame.remove();
|
94 | 158 | resolve([]);
|
|
111 | 175 | } else {
|
112 | 176 | resolve([sTestPage]);
|
113 | 177 | }
|
114 |
| - }.bind(this)).fail(function(xhr,status,msg) { |
| 178 | + }.bind(this)).catch(function(xhr,status,msg) { |
115 | 179 | var text = (xhr ? xhr.status + " " : "") + (msg || status || 'unspecified error');
|
116 | 180 | if (window.console && typeof window.console.error === "function") {
|
117 | 181 | window.console.error("QUnit: failed to load page '" + sTestPage + "': " + text);
|
|
123 | 187 |
|
124 | 188 | }.bind(this));
|
125 | 189 |
|
126 |
| - oPromise.done = oPromise.then; // compat for Deferred |
127 |
| - oPromise.fail = oPromise.catch; // compat for Deferred |
128 |
| - |
129 | 190 | return oPromise;
|
130 | 191 |
|
131 | 192 | },
|
132 | 193 |
|
133 | 194 | findTestPages: function(oIFrame, bSequential) {
|
134 | 195 |
|
135 | 196 | return Promise.resolve(oIFrame.contentWindow.suite()).then(function(oSuite) {
|
| 197 | + window.console.log("[DEBUG] findTestPages oIFrame source: " + oIFrame.src); |
136 | 198 | 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 | + } |
137 | 202 | return new Promise(function(resolve, reject) {
|
138 | 203 |
|
139 | 204 | try {
|
|
146 | 211 |
|
147 | 212 | var aTestPages = [];
|
148 | 213 | 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) { |
150 | 215 | aTestPages = aTestPages.concat(aFoundTestPages);
|
151 | 216 | });
|
152 | 217 | }.bind(this), Promise.resolve([])).then(function() {
|
|
157 | 222 |
|
158 | 223 | for (var i = 0, l = aPages.length; i < l; i++) {
|
159 | 224 | var sTestPage = aPages[i];
|
160 |
| - aTestPagePromises.push(this.checkTestPage(sTestPage, bSequential)); |
| 225 | + aTestPagePromises.push(this._checkTestPage(sTestPage, bSequential)); |
161 | 226 | }
|
162 | 227 |
|
163 | 228 | }
|
|
169 | 234 | aTestPages = aTestPages.concat(aFoundTestPages[i]);
|
170 | 235 | }
|
171 | 236 | 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 | + } |
172 | 242 | });
|
173 | 243 | }
|
174 | 244 |
|
|
267 | 337 | var sHTML = fnTemplate(oContext);
|
268 | 338 | var $testResult = jQuery(sHTML);
|
269 | 339 | var $children = $testResult.children();
|
270 |
| - jQuery($children[0]).click(function() { |
| 340 | + jQuery($children[0]).on("click", function() { |
271 | 341 | jQuery(this.nextSibling).toggle();
|
272 | 342 | });
|
273 |
| - jQuery($children[1]).find("li.test > p").click(function() { |
| 343 | + jQuery($children[1]).find("li.test > p").on("click", function() { |
274 | 344 | jQuery(this.parentElement.children[2]).toggle();
|
275 | 345 | });
|
276 | 346 | $testResult.appendTo("div.test-reporting");
|
|
0 commit comments