<commit_before>/*global QUnit */

sap.ui.define([
	"sap/base/Log",
	"sap/ui/core/Component",
	"sap/ui/core/ComponentContainer",
	"sap/ui/core/util/LibraryInfo",
	"sap/ui/model/odata/ODataModel",
	"sap/m/App",
	"sap/m/Page",
	"sap/ui/thirdparty/jquery",
	"sap/ui/thirdparty/URI",
	"sap/ui/core/Core",
	"sap/ui/thirdparty/sinon",
	"sap/ui/thirdparty/sinon-qunit"
], function(
	Log,
	Component,
	ComponentContainer,
	LibraryInfo,
	ODataModel,
	App,
	Page,
	jQuery,
	URI,
	oCore
) {

	"use strict";

	var oLog = Log.getLogger("SampleTester");

	function wait(iDelay) {
		return new Promise(function(resolve) {
			setTimeout(function() {
				resolve();
			}, iDelay);
		});
	}

	function fetchHEAD(url) {
		return Promise.resolve(
			jQuery.ajax({
				url: url,
				type: 'HEAD'
			})
		).then(function() {
			return true;
		}, function() {
			return false;
		});
	}

	/* converts a global name to a resource (module) name */
	function toResourceName(name) {
		return name.replace(/\./g, "/");
	}

	function isLocaleSpecificResource(sResource) {
		// check for a locale-like name suffix and the extension .properties
		return /_[a-zA-Z]{2}(?:_[^/]+)?\.properties$/.test(sResource);
	}

	function RequestCollector(sandbox, baseUrl) {
		var oRequireLoadSpy = sandbox.spy(sap.ui.require, "load");
		var oAsyncRequestSpy = sandbox.spy(jQuery, "ajax");

		this.resources = function() {
			var aResources = [].concat(
					oAsyncRequestSpy.getCalls().map(function(oCall) {
						return typeof oCall.args[0] === "string" ? oCall.args[0] : oCall.args[0].url;
					}),
					oRequireLoadSpy.getCalls().map(function(oCall) {
						return oCall.args[1];
					})
				);

			var aSampleRequests = [];
			aResources.forEach(function(sResourceUrl) {
				sResourceUrl = new URI(sResourceUrl, document.baseURI).search("").hash("").toString();
				// only add requests from within the sample and no duplicates
				if ( sResourceUrl.startsWith(baseUrl) ) {
					sResourceUrl = sResourceUrl.slice(baseUrl.length);
					if ( aSampleRequests.indexOf(sResourceUrl) < 0 && sResourceUrl !== "Component.js" ) {
						aSampleRequests.push(sResourceUrl);
					}
				}
			});

			return aSampleRequests;
		};
	}

	var SampleTester = function(sLibraryName, aExcludes) {
		this._sLibraryName = sLibraryName;
		this._aExcludes = aExcludes || [];
		this._iTimeout = 200;
		this._iModulus = 1;
		this._iRemainder = 0;

		if ( window["sap-ui-config"] && Array.isArray(window["sap-ui-config"].modulus) ) {
			this._iModulus = window["sap-ui-config"].modulus[1];
			this._iRemainder = window["sap-ui-config"].modulus[0];
		}

		this._oApp = new App({
			initialPage: "page",
			pages: [
				this._oPage = new Page("page", {
					title: "Page under Test"
				})
			]
		});

		var oLibInfo = new LibraryInfo();
		oLibInfo._getDocuIndex(sLibraryName, function(oData) {

			// wait with test creation until all libs are loaded
			oCore.attachInit(function() {
				this._createTests(oData && oData.explored);
			}.bind(this));

		}.bind(this));

	};

	SampleTester.prototype.setTimeout = function(iTimeout) {
		this._iTimeout = iTimeout;
		return this;
	};

	SampleTester.prototype.placeAt = function(sId) {
		this._oApp.placeAt(sId);
		return this;
	};

	SampleTester.prototype._createTests = function(oExploredIndex) {

		var iTimeout = this._iTimeout;
		var oApp = this._oApp;
		var oPage = this._oPage;
		var sLibraryName = this._sLibraryName;

		oLog.info("starting to define tests for the samples of '" + this._sLibraryName + "'");

		QUnit.module(this._sLibraryName, {
			beforeEach: function() {
				// clear metadata cache
				ODataModel.mServiceData = {};
			},
			afterEach : function(assert) {
				// empty the page after each test, even in case of failures
				oPage.setTitle("---");
				oPage.destroyContent();
			}
		});

		function shorten(id) {
			return id.replace(sLibraryName + ".", "");
		}

		function makeTest(sampleConfig) {

			QUnit.test("Launch " + sampleConfig.name + " (" + shorten(sampleConfig.id) + ")", function(assert) {

				// display the sample name
				oPage.setTitle(sampleConfig.name);

				var sComponentBaseUrl = new URI(sap.ui.require.toUrl(toResourceName(sampleConfig.id)) + "/", document.baseURI).toString();
				var oCollector = new RequestCollector(this, sComponentBaseUrl);
				var done = assert.async();

				Component.create({
					name: sampleConfig.id,
					manifest: false
				}).then(function(oComponent) {
					// if root control is a view, wait for it being loaded
					if ( oComponent.getRootControl() && typeof oComponent.getRootControl().loaded === "function" ) {
						return oComponent.getRootControl().loaded().then(function() {
							return oComponent;
						});
					}
					return oComponent;
				}).then(function(oComponent) {

					// load and create content
					oPage.addContent(
						new ComponentContainer({
							component: oComponent
						})
					);<commit_msg>[INTERNAL] sap.ui.documentation: reduce dependencies of SampleTester<commit_after>/*global QUnit */

sap.ui.define([
	"sap/base/Log",
	"sap/m/App",
	"sap/m/Page",
	"sap/ui/core/Component",
	"sap/ui/core/ComponentContainer",
	"sap/ui/core/Core",
	"sap/ui/core/util/LibraryInfo",
	"sap/ui/thirdparty/jquery",
	"sap/ui/thirdparty/sinon",
	"sap/ui/thirdparty/sinon-qunit"
], function(
	Log,
	App,
	Page,
	Component,
	ComponentContainer,
	oCore,
	LibraryInfo,
	jQuery
) {

	"use strict";

	var oLog = Log.getLogger("SampleTester");

	function wait(iDelay) {
		return new Promise(function(resolve) {
			setTimeout(function() {
				resolve();
			}, iDelay);
		});
	}

	function fetchHEAD(url) {
		return Promise.resolve(
			jQuery.ajax({
				url: url,
				type: 'HEAD'
			})
		).then(function() {
			return true;
		}, function() {
			return false;
		});
	}

	/* converts a global name to a resource (module) name */
	function toResourceName(name) {
		return name.replace(/\./g, "/");
	}

	function isLocaleSpecificResource(sResource) {
		// check for a locale-like name suffix and the extension .properties
		return /_[a-zA-Z]{2}(?:_[^/]+)?\.properties$/.test(sResource);
	}

	function toAbsoluteURL(sRelativeURL) {
		var oURL = new URL(sRelativeURL, document.baseURI);
		oURL.search = oURL.hash = "";
		return oURL.href;
	}

	function RequestCollector(sandbox, baseUrl) {
		var oRequireLoadSpy = sandbox.spy(sap.ui.require, "load");
		var oAsyncRequestSpy = sandbox.spy(jQuery, "ajax");

		this.resources = function() {
			var aResources = [].concat(
					oAsyncRequestSpy.getCalls().map(function(oCall) {
						return typeof oCall.args[0] === "string" ? oCall.args[0] : oCall.args[0].url;
					}),
					oRequireLoadSpy.getCalls().map(function(oCall) {
						return oCall.args[1];
					})
				);

			var aSampleRequests = [];
			aResources.forEach(function(sResourceUrl) {
				sResourceUrl = toAbsoluteURL(sResourceUrl);
				// only add requests from within the sample and no duplicates
				if ( sResourceUrl.startsWith(baseUrl) ) {
					sResourceUrl = sResourceUrl.slice(baseUrl.length);
					if ( aSampleRequests.indexOf(sResourceUrl) < 0 && sResourceUrl !== "Component.js" ) {
						aSampleRequests.push(sResourceUrl);
					}
				}
			});

			return aSampleRequests;
		};
	}

	var SampleTester = function(sLibraryName, aExcludes) {
		this._sLibraryName = sLibraryName;
		this._aExcludes = aExcludes || [];
		this._iTimeout = 200;
		this._iModulus = 1;
		this._iRemainder = 0;

		if ( window["sap-ui-config"] && Array.isArray(window["sap-ui-config"].modulus) ) {
			this._iModulus = window["sap-ui-config"].modulus[1];
			this._iRemainder = window["sap-ui-config"].modulus[0];
		}

		this._oApp = new App({
			initialPage: "page",
			pages: [
				this._oPage = new Page("page", {
					title: "Page under Test"
				})
			]
		});

		var oLibInfo = new LibraryInfo();
		oLibInfo._getDocuIndex(sLibraryName, function(oData) {

			// wait with test creation until all libs are loaded
			oCore.attachInit(function() {
				this._createTests(oData && oData.explored);
			}.bind(this));

		}.bind(this));

	};

	SampleTester.prototype.setTimeout = function(iTimeout) {
		this._iTimeout = iTimeout;
		return this;
	};

	SampleTester.prototype.placeAt = function(sId) {
		this._oApp.placeAt(sId);
		return this;
	};

	SampleTester.prototype._createTests = function(oExploredIndex) {

		var iTimeout = this._iTimeout;
		var oApp = this._oApp;
		var oPage = this._oPage;
		var sLibraryName = this._sLibraryName;

		oLog.info("starting to define tests for the samples of '" + this._sLibraryName + "'");

		QUnit.module(this._sLibraryName, {
			beforeEach: function() {
				// clear metadata cache, if ODataModel is used
				var ODataModel = sap.ui.require("sap/ui/model/odata/ODataModel");
				if ( ODataModel ) {
					ODataModel.mServiceData = {};
				}
			},
			afterEach : function(assert) {
				// empty the page after each test, even in case of failures
				oPage.setTitle("---");
				oPage.destroyContent();
			}
		});

		function shorten(id) {
			return id.replace(sLibraryName + ".", "");
		}

		function makeTest(sampleConfig) {

			QUnit.test("Launch " + sampleConfig.name + " (" + shorten(sampleConfig.id) + ")", function(assert) {

				// display the sample name
				oPage.setTitle(sampleConfig.name);

				var sComponentBaseUrl = toAbsoluteURL(sap.ui.require.toUrl(toResourceName(sampleConfig.id)) + "/");
				var oCollector = new RequestCollector(this, sComponentBaseUrl);
				var done = assert.async();

				Component.create({
					name: sampleConfig.id,
					manifest: false
				}).then(function(oComponent) {
					// if root control is a view, wait for it being loaded
					if ( oComponent.getRootControl() && typeof oComponent.getRootControl().loaded === "function" ) {
						return oComponent.getRootControl().loaded().then(function() {
							return oComponent;
						});
					}
					return oComponent;
				}).then(function(oComponent) {

					// load and create content
					oPage.addContent(
						new ComponentContainer({
							component: oComponent
						})
					);
{'fraction_non_alphanumeric': 0.1495983935742972, 'fraction_numerical': 0.0026104417670682733, 'mean_word_length': 3.411426040744021, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6543773', 'n_tokens_mistral': 3982, 'n_tokens_neox': 3362, 'n_words': 641}