From 55b1fe742be29b176e55985a0315dcead684d257 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Thu, 13 Aug 2020 16:48:30 +0200 Subject: [PATCH] [FIX] middleware/testRunner: Update resources from OpenUI5 Based on: https://github.com/SAP/openui5/commit/454a28274b9b409981fa0ee17021202d3ec29dd1 --- lib/middleware/testRunner/TestRunner.js | 94 ++++++++++++++++++++--- lib/middleware/testRunner/testrunner.html | 30 ++++---- 2 files changed, 97 insertions(+), 27 deletions(-) diff --git a/lib/middleware/testRunner/TestRunner.js b/lib/middleware/testRunner/TestRunner.js index 15bd83c8..b9954443 100644 --- a/lib/middleware/testRunner/TestRunner.js +++ b/lib/middleware/testRunner/TestRunner.js @@ -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 */ @@ -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) { @@ -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("