<commit_before>/*global console:true*/
(function(global) {

	var testRunner = {
		accessibilityTests : {},

		qunitCallbacks : {},

		run: function() {
			var that = this;
			if(typeof QUnit === 'undefined') {
				global.QUnit = {
					moduleStart: function(callback) {
						that.qunitCallbacks.moduleStart = callback;
					},
					testStart: function(callback) {
						that.qunitCallbacks.testStart = callback;
					},
					testDone: function(callback) {
						that.qunitCallbacks.testDone = callback;
					},
					log: function(callback) {
						that.qunitCallbacks.log = callback;
					},
					done: function(callback) {
						that.qunitCallbacks.done = callback;
					}
				};
			}
			this.includejQuery();
		},

		includejQuery: function() {
			var em = document.createElement('script');
		  em.type = 'text/javascript';
		  if (em.readyState) {
		      em.onreadystatechange = function () {
		          if (em.readyState == "loaded" || em.readyState == "complete") {
		              em.onreadystatechange = null;
				         testRunner.includeScripts();
		          }
		      };
		  } else {
		      em.onload = function () {
		         testRunner.includeScripts();
		      };
		  }
		  em.src = '../../lib/jquery/jquery.js';
		  var s = document.getElementsByTagName('script')[0];
		  s.parentNode.insertBefore(em, s);
		},

		includeScripts: function() {
			var that = this;
			$('head').append('<link rel="stylesheet" href="../../lib/qunit/qunit.css" media="screen">');
			$('head').append('<link rel="stylesheet" href="../test.css" media="screen">');
			$('body').prepend('<div role="status" id="qunit"></div><div role="status" id="qunit-fixture"></div>');
			$.getScript('../../dist/quail.jquery.js', function() {
				$.getScript('../../lib/qunit/qunit.js', function() {
					$.ajax({ url: '../../dist/tests.json',
						      cache: false,
						      dataType: 'json',
						      success: function(data) {
										that.accessibilityTests = data;
										that.buildQUnit();
										QUnit.init();
										setTimeout(function() {
											start();
											if(typeof global.quailTest !== 'undefined') {
												global.quailTest();
											}
											else {
												that.runTests();
											}
										}, 250);
									}
					});
				});
			});
		},

		buildQUnit: function() {
			if(typeof this.qunitCallbacks.moduleStart === 'undefined') {
				return;
			}
			QUnit.moduleStart = this.qunitCallbacks.moduleStart;
			QUnit.testStart = this.qunitCallbacks.testStart;
			QUnit.testDone = this.qunitCallbacks.testDone;
			QUnit.log = this.qunitCallbacks.log;
			QUnit.done = this.qunitCallbacks.done;
		},

		runTests: function() {
			var that = this;
			$('.quail-test').each(function(index) {
				var thisTest = {
					title : ($(this).attr('title')) ? ': ' + $(this).attr('title') : '',
					accessibilityTest: $(this).data('accessibility-test'),
					expectedPass: ($(this).data('expected') === 'pass'),
				};
				if(typeof thisTest.accessibilityTest === 'undefined' ||
					 !thisTest.accessibilityTest) {
					test('Accessibility test is defined', function() {
						ok(false, 'Accessibility test is not defined.');
					});
				}
				var $that = $(this), expected, label, title;
				testTitle = (typeof that.accessibilityTests[thisTest.accessibilityTest].title !== 'undefined') ?
											that.accessibilityTests[thisTest.accessibilityTest].title.en :
											'No test title defined';<commit_msg>Added comments to testrunner.js.<commit_after>/**
 * The test runner will take a properly-formatted page and 
 * run accessibility tests against it. To learn more about how to use
 * the test runner, read the wiki at:
 * https://github.com/kevee/quail/wiki/New-test-file-format
 */

/*global console:true*/
(function(global) {

	var testRunner = {
		accessibilityTests : {},

		qunitCallbacks : {},

		/**
		 * Run qunit tests against the page. We first capture any
		 * test callbacks into our own object so we can call them later.
		 * This is necessary to keep composite tests with long page
		 * times working.
		 */
		run: function() {
			var that = this;
			if(typeof QUnit === 'undefined') {
				global.QUnit = {
					moduleStart: function(callback) {
						that.qunitCallbacks.moduleStart = callback;
					},
					testStart: function(callback) {
						that.qunitCallbacks.testStart = callback;
					},
					testDone: function(callback) {
						that.qunitCallbacks.testDone = callback;
					},
					log: function(callback) {
						that.qunitCallbacks.log = callback;
					},
					done: function(callback) {
						that.qunitCallbacks.done = callback;
					}
				};
			}
			this.includejQuery();
		},

		/**
		 * Include jQuery on the page using vanilla JS, including differences
		 * in script ready events.
		 */
		includejQuery: function() {
			var em = document.createElement('script');
		  em.type = 'text/javascript';
		  if (em.readyState) {
		      em.onreadystatechange = function () {
		          if (em.readyState == "loaded" || em.readyState == "complete") {
		              em.onreadystatechange = null;
				         testRunner.includeScripts();
		          }
		      };
		  } else {
		      em.onload = function () {
		         testRunner.includeScripts();
		      };
		  }
		  em.src = '../../lib/jquery/jquery.js';
		  var s = document.getElementsByTagName('script')[0];
		  s.parentNode.insertBefore(em, s);
		},

		/**
		 * Once jQuery is available, insert Qunit styles, the placeholder for
		 * the Qunit fixture, and load the rest of the needed JS on the page.
		 * At the end, we request tests.json and set a 250ms timeout to prevent
		 * the parent composite tester from timing out.
		 * 
		 * If the page has defined a global.quailTest function, we then run it, if
		 * not, we run the runTests method.
		 */
		includeScripts: function() {
			var that = this;
			$('head').append('<link rel="stylesheet" href="../../lib/qunit/qunit.css" media="screen">');
			$('head').append('<link rel="stylesheet" href="../test.css" media="screen">');
			$('body').prepend('<div role="status" id="qunit"></div><div role="status" id="qunit-fixture"></div>');
			$.getScript('../../dist/quail.jquery.js', function() {
				$.getScript('../../lib/qunit/qunit.js', function() {
					$.ajax({ url: '../../dist/tests.json',
						      cache: false,
						      dataType: 'json',
						      success: function(data) {
										that.accessibilityTests = data;
										that.buildQUnit();
										QUnit.init();
										setTimeout(function() {
											start();
											if(typeof global.quailTest !== 'undefined') {
												global.quailTest();
											}
											else {
												that.runTests();
											}
										}, 250);
									}
					});
				});
			});
		},

		/**
		 * Assign callbacks for QUnit after the timeout has completed.
		 */
		buildQUnit: function() {
			if(typeof this.qunitCallbacks.moduleStart === 'undefined') {
				return;
			}
			QUnit.moduleStart = this.qunitCallbacks.moduleStart;
			QUnit.testStart = this.qunitCallbacks.testStart;
			QUnit.testDone = this.qunitCallbacks.testDone;
			QUnit.log = this.qunitCallbacks.log;
			QUnit.done = this.qunitCallbacks.done;
		},

		/**
		 * For accessibility tests, we can (for most tests) just use markup on the page
		 * to determine what test to run, where to run it, and whether to expect a failure.
		 * This runs quail against all .quail-test elements, determines pass/fail, and
		 * then runs comparisons into QUnit assertions.
		 */
		runTests: function() {
			var that = this;
			$('.quail-test').each(function(index) {
				var thisTest = {
					title : ($(this).attr('title')) ? ': ' + $(this).attr('title') : '',
					accessibilityTest: $(this).data('accessibility-test'),
					expectedPass: ($(this).data('expected') === 'pass'),
				};
				if(typeof thisTest.accessibilityTest === 'undefined' ||
					 !thisTest.accessibilityTest) {
					test('Accessibility test is defined', function() {
						ok(false, 'Accessibility test is not defined.');
					});
				}
				var $that = $(this), expected, label, title;
				testTitle = (typeof that.accessibilityTests[thisTest.accessibilityTest].title !== 'undefined') ?
											that.accessibilityTests[thisTest.accessibilityTest].title.en :
											'No test title defined';
{'fraction_non_alphanumeric': 0.15476621964479884, 'fraction_numerical': 0.0013289839313761025, 'mean_word_length': 2.5421480530594778, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 1, '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': '3993295', 'n_tokens_mistral': 3275, 'n_tokens_neox': 2438, 'n_words': 544}