annotate iframe-resizer/test/resources/qunit.js @ 9:7300ed4c1481 draft default tip

Uploaded
author saskia-hiltemann
date Mon, 04 Sep 2017 10:49:00 -0400
parents ac5f9272033b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2 * QUnit v1.12.0 - A JavaScript Unit Testing Framework
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * http://qunitjs.com
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 * Copyright 2013 jQuery Foundation and other contributors
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 * Released under the MIT license.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 * https://jquery.org/license/
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 (function( window ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 var QUnit,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 assert,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 config,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 onErrorFnPrev,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 testId = 0,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 toString = Object.prototype.toString,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 hasOwn = Object.prototype.hasOwnProperty,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 // Keep a local reference to Date (GH-283)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 Date = window.Date,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 setTimeout = window.setTimeout,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 defined = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 setTimeout: typeof window.setTimeout !== "undefined",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 sessionStorage: (function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 var x = "qunit-test-string";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 try {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 sessionStorage.setItem( x, x );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 sessionStorage.removeItem( x );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 } catch( e ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 }())
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 * Provides a normalized error string, correcting an issue
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 * with IE 7 (and prior) where Error.prototype.toString is
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 * not properly implemented
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 * Based on http://es5.github.com/#x15.11.4.4
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 * @param {String|Error} error
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 * @return {String} error message
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 errorString = function( error ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 var name, message,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 errorString = error.toString();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 if ( errorString.substring( 0, 7 ) === "[object" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 name = error.name ? error.name.toString() : "Error";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 message = error.message ? error.message.toString() : "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 if ( name && message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 return name + ": " + message;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 } else if ( name ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 return name;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 } else if ( message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 return message;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 return "Error";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 return errorString;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 * Makes a clone of an object using only Array or Object as base,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 * and copies over the own enumerable properties.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 * @param {Object} obj
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 * @return {Object} New object with only the own properties (recursively).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 objectValues = function( obj ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 // Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 /*jshint newcap: false */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 var key, val,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 vals = QUnit.is( "array", obj ) ? [] : {};
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 for ( key in obj ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 if ( hasOwn.call( obj, key ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 val = obj[key];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 vals[key] = val === Object(val) ? objectValues(val) : val;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 return vals;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 function Test( settings ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 extend( this, settings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 this.assertions = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 this.testNumber = ++Test.count;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 Test.count = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 Test.prototype = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 init: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 var a, b, li,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 tests = id( "qunit-tests" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 if ( tests ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 b = document.createElement( "strong" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 b.innerHTML = this.nameHtml;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 // `a` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105 a = document.createElement( "a" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 a.innerHTML = "Rerun";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 a.href = QUnit.url({ testNumber: this.testNumber });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 li = document.createElement( "li" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 li.appendChild( b );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 li.appendChild( a );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 li.className = "running";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 li.id = this.id = "qunit-test-output" + testId++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 tests.appendChild( li );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 setup: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119 if (
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 // Emit moduleStart when we're switching from one module to another
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121 this.module !== config.previousModule ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 // They could be equal (both undefined) but if the previousModule property doesn't
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 // yet exist it means this is the first test in a suite that isn't wrapped in a
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 // module, in which case we'll just emit a moduleStart event for 'undefined'.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 // Without this, reporters can get testStart before moduleStart which is a problem.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 !hasOwn.call( config, "previousModule" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128 if ( hasOwn.call( config, "previousModule" ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 runLoggingCallbacks( "moduleDone", QUnit, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 name: config.previousModule,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 failed: config.moduleStats.bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 passed: config.moduleStats.all - config.moduleStats.bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 total: config.moduleStats.all
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136 config.previousModule = this.module;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 config.moduleStats = { all: 0, bad: 0 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 runLoggingCallbacks( "moduleStart", QUnit, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 name: this.module
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 config.current = this;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 this.testEnvironment = extend({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 setup: function() {},
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 teardown: function() {}
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 }, this.moduleTestEnvironment );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 this.started = +new Date();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 runLoggingCallbacks( "testStart", QUnit, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 name: this.testName,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 module: this.module
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 /*jshint camelcase:false */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160 * Expose the current test environment.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 * @deprecated since 1.12.0: Use QUnit.config.current.testEnvironment instead.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 QUnit.current_testEnvironment = this.testEnvironment;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 /*jshint camelcase:true */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 if ( !config.pollution ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 saveGlobal();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 if ( config.notrycatch ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172 this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 try {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 } catch( e ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178 QUnit.pushFailure( "Setup failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 run: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 config.current = this;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 var running = id( "qunit-testresult" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
186 if ( running ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
187 running.innerHTML = "Running: <br/>" + this.nameHtml;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 if ( this.async ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 QUnit.stop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 this.callbackStarted = +new Date();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 if ( config.notrycatch ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 this.callback.call( this.testEnvironment, QUnit.assert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 this.callbackRuntime = +new Date() - this.callbackStarted;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 try {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 this.callback.call( this.testEnvironment, QUnit.assert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 this.callbackRuntime = +new Date() - this.callbackStarted;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 } catch( e ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 this.callbackRuntime = +new Date() - this.callbackStarted;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208 QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 // else next test will carry the responsibility
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 saveGlobal();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 // Restart the tests if they're blocking
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 if ( config.blocking ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 QUnit.start();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218 teardown: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219 config.current = this;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 if ( config.notrycatch ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 if ( typeof this.callbackRuntime === "undefined" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 this.callbackRuntime = +new Date() - this.callbackStarted;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 try {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228 this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229 } catch( e ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230 QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 checkPollution();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 finish: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 config.current = this;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237 if ( config.requireExpects && this.expected === null ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239 } else if ( this.expected !== null && this.expected !== this.assertions.length ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240 QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 } else if ( this.expected === null && !this.assertions.length ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 var i, assertion, a, b, time, li, ol,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246 test = this,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 good = 0,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248 bad = 0,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249 tests = id( "qunit-tests" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 this.runtime = +new Date() - this.started;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
252 config.stats.all += this.assertions.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
253 config.moduleStats.all += this.assertions.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
254
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 if ( tests ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 ol = document.createElement( "ol" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 ol.className = "qunit-assert-list";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 for ( i = 0; i < this.assertions.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 assertion = this.assertions[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 li = document.createElement( "li" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 li.className = assertion.result ? "pass" : "fail";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264 li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265 ol.appendChild( li );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 if ( assertion.result ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 good++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270 bad++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 config.stats.bad++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 config.moduleStats.bad++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
273 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
274 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
275
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 // store result when possible
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277 if ( QUnit.config.reorder && defined.sessionStorage ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 if ( bad ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279 sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 if ( bad === 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 addClass( ol, "qunit-collapsed" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289 // `b` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 b = document.createElement( "strong" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 b.innerHTML = this.nameHtml + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293 addEvent(b, "click", function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 var next = b.parentNode.lastChild,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295 collapsed = hasClass( next, "qunit-collapsed" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 ( collapsed ? removeClass : addClass )( next, "qunit-collapsed" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 addEvent(b, "dblclick", function( e ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
300 var target = e && e.target ? e.target : window.event.srcElement;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
301 if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
302 target = target.parentNode;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
303 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304 if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 window.location = QUnit.url({ testNumber: test.testNumber });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
307 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
308
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
309 // `time` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
310 time = document.createElement( "span" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
311 time.className = "runtime";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
312 time.innerHTML = this.runtime + " ms";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
313
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
314 // `li` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315 li = id( this.id );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316 li.className = bad ? "fail" : "pass";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317 li.removeChild( li.firstChild );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318 a = li.firstChild;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 li.appendChild( b );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 li.appendChild( a );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321 li.appendChild( time );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322 li.appendChild( ol );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325 for ( i = 0; i < this.assertions.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326 if ( !this.assertions[i].result ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 bad++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 config.stats.bad++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329 config.moduleStats.bad++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
334 runLoggingCallbacks( "testDone", QUnit, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
335 name: this.testName,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
336 module: this.module,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
337 failed: bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
338 passed: this.assertions.length - bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339 total: this.assertions.length,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340 duration: this.runtime
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 QUnit.reset();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 config.current = undefined;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
347
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
348 queue: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
349 var bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
350 test = this;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
351
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
352 synchronize(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
353 test.init();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
354 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
355 function run() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
356 // each of these can by async
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
357 synchronize(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
358 test.setup();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
359 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
360 synchronize(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
361 test.run();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
362 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
363 synchronize(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
364 test.teardown();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
365 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
366 synchronize(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
367 test.finish();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
368 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
369 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
370
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
371 // `bad` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
372 // defer when previous test run passed, if storage is available
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
373 bad = QUnit.config.reorder && defined.sessionStorage &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
374 +sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
375
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
376 if ( bad ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
377 run();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
378 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
379 synchronize( run, true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
380 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
381 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
382 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
383
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
384 // Root QUnit object.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
385 // `QUnit` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
386 QUnit = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
387
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
388 // call on start of module test to prepend name to all tests
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
389 module: function( name, testEnvironment ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
390 config.currentModule = name;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
391 config.currentModuleTestEnvironment = testEnvironment;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
392 config.modules[name] = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
393 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
394
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
395 asyncTest: function( testName, expected, callback ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
396 if ( arguments.length === 2 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
397 callback = expected;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
398 expected = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
399 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
400
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
401 QUnit.test( testName, expected, callback, true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
402 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
403
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
404 test: function( testName, expected, callback, async ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
405 var test,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
406 nameHtml = "<span class='test-name'>" + escapeText( testName ) + "</span>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
407
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
408 if ( arguments.length === 2 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
409 callback = expected;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
410 expected = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
411 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
412
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
413 if ( config.currentModule ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
414 nameHtml = "<span class='module-name'>" + escapeText( config.currentModule ) + "</span>: " + nameHtml;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
415 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
416
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
417 test = new Test({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
418 nameHtml: nameHtml,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
419 testName: testName,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
420 expected: expected,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
421 async: async,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
422 callback: callback,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
423 module: config.currentModule,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
424 moduleTestEnvironment: config.currentModuleTestEnvironment,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
425 stack: sourceFromStacktrace( 2 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
426 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
427
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
428 if ( !validTest( test ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
429 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
430 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
431
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
432 test.queue();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
433 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
434
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
435 // Specify the number of expected assertions to guarantee that failed test (no assertions are run at all) don't slip through.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
436 expect: function( asserts ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
437 if (arguments.length === 1) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
438 config.current.expected = asserts;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
439 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
440 return config.current.expected;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
441 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
442 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
443
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
444 start: function( count ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
445 // QUnit hasn't been initialized yet.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
446 // Note: RequireJS (et al) may delay onLoad
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
447 if ( config.semaphore === undefined ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
448 QUnit.begin(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
449 // This is triggered at the top of QUnit.load, push start() to the event loop, to allow QUnit.load to finish first
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
450 setTimeout(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
451 QUnit.start( count );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
452 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
453 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
454 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
455 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
456
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
457 config.semaphore -= count || 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
458 // don't start until equal number of stop-calls
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
459 if ( config.semaphore > 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
460 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
461 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
462 // ignore if start is called more often then stop
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
463 if ( config.semaphore < 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
464 config.semaphore = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
465 QUnit.pushFailure( "Called start() while already started (QUnit.config.semaphore was 0 already)", null, sourceFromStacktrace(2) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
466 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
467 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
468 // A slight delay, to avoid any current callbacks
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
469 if ( defined.setTimeout ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
470 setTimeout(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
471 if ( config.semaphore > 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
472 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
473 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
474 if ( config.timeout ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
475 clearTimeout( config.timeout );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
476 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
477
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
478 config.blocking = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
479 process( true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
480 }, 13);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
481 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
482 config.blocking = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
483 process( true );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
484 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
485 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
486
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
487 stop: function( count ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
488 config.semaphore += count || 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
489 config.blocking = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
490
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
491 if ( config.testTimeout && defined.setTimeout ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
492 clearTimeout( config.timeout );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
493 config.timeout = setTimeout(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
494 QUnit.ok( false, "Test timed out" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
495 config.semaphore = 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
496 QUnit.start();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
497 }, config.testTimeout );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
498 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
499 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
500 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
501
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
502 // `assert` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
503 // Assert helpers
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
504 // All of these must either call QUnit.push() or manually do:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
505 // - runLoggingCallbacks( "log", .. );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
506 // - config.current.assertions.push({ .. });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
507 // We attach it to the QUnit object *after* we expose the public API,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
508 // otherwise `assert` will become a global variable in browsers (#341).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
509 assert = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
510 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
511 * Asserts rough true-ish result.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
512 * @name ok
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
513 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
514 * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
515 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
516 ok: function( result, msg ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
517 if ( !config.current ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
518 throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
519 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
520 result = !!result;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
521 msg = msg || (result ? "okay" : "failed" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
522
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
523 var source,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
524 details = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
525 module: config.current.module,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
526 name: config.current.testName,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
527 result: result,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
528 message: msg
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
529 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
530
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
531 msg = "<span class='test-message'>" + escapeText( msg ) + "</span>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
532
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
533 if ( !result ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
534 source = sourceFromStacktrace( 2 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
535 if ( source ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
536 details.source = source;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
537 msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr></table>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
538 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
539 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
540 runLoggingCallbacks( "log", QUnit, details );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
541 config.current.assertions.push({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
542 result: result,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
543 message: msg
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
544 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
545 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
546
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
547 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
548 * Assert that the first two arguments are equal, with an optional message.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
549 * Prints out both actual and expected values.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
550 * @name equal
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
551 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
552 * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
553 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
554 equal: function( actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
555 /*jshint eqeqeq:false */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
556 QUnit.push( expected == actual, actual, expected, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
557 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
558
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
559 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
560 * @name notEqual
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
561 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
562 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
563 notEqual: function( actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
564 /*jshint eqeqeq:false */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
565 QUnit.push( expected != actual, actual, expected, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
566 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
567
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
568 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
569 * @name propEqual
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
570 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
571 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
572 propEqual: function( actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
573 actual = objectValues(actual);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
574 expected = objectValues(expected);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
575 QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
576 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
577
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
578 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
579 * @name notPropEqual
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
580 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
581 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
582 notPropEqual: function( actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
583 actual = objectValues(actual);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
584 expected = objectValues(expected);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
585 QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
586 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
587
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
588 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
589 * @name deepEqual
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
590 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
591 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
592 deepEqual: function( actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
593 QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
594 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
595
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
596 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
597 * @name notDeepEqual
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
598 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
599 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
600 notDeepEqual: function( actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
601 QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
602 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
603
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
604 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
605 * @name strictEqual
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
606 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
607 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
608 strictEqual: function( actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
609 QUnit.push( expected === actual, actual, expected, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
610 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
611
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
612 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
613 * @name notStrictEqual
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
614 * @function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
615 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
616 notStrictEqual: function( actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
617 QUnit.push( expected !== actual, actual, expected, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
618 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
619
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
620 "throws": function( block, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
621 var actual,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
622 expectedOutput = expected,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
623 ok = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
624
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
625 // 'expected' is optional
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
626 if ( typeof expected === "string" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
627 message = expected;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
628 expected = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
629 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
630
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
631 config.current.ignoreGlobalErrors = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
632 try {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
633 block.call( config.current.testEnvironment );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
634 } catch (e) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
635 actual = e;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
636 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
637 config.current.ignoreGlobalErrors = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
638
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
639 if ( actual ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
640 // we don't want to validate thrown error
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
641 if ( !expected ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
642 ok = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
643 expectedOutput = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
644 // expected is a regexp
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
645 } else if ( QUnit.objectType( expected ) === "regexp" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
646 ok = expected.test( errorString( actual ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
647 // expected is a constructor
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
648 } else if ( actual instanceof expected ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
649 ok = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
650 // expected is a validation function which returns true is validation passed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
651 } else if ( expected.call( {}, actual ) === true ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
652 expectedOutput = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
653 ok = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
654 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
655
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
656 QUnit.push( ok, actual, expectedOutput, message );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
657 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
658 QUnit.pushFailure( message, null, "No exception was thrown." );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
659 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
660 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
661 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
662
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
663 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
664 * @deprecated since 1.8.0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
665 * Kept assertion helpers in root for backwards compatibility.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
666 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
667 extend( QUnit, assert );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
668
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
669 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
670 * @deprecated since 1.9.0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
671 * Kept root "raises()" for backwards compatibility.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
672 * (Note that we don't introduce assert.raises).
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
673 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
674 QUnit.raises = assert[ "throws" ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
675
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
676 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
677 * @deprecated since 1.0.0, replaced with error pushes since 1.3.0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
678 * Kept to avoid TypeErrors for undefined methods.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
679 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
680 QUnit.equals = function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
681 QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
682 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
683 QUnit.same = function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
684 QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
685 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
686
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
687 // We want access to the constructor's prototype
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
688 (function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
689 function F() {}
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
690 F.prototype = QUnit;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
691 QUnit = new F();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
692 // Make F QUnit's constructor so that we can add to the prototype later
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
693 QUnit.constructor = F;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
694 }());
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
695
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
696 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
697 * Config object: Maintain internal state
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
698 * Later exposed as QUnit.config
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
699 * `config` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
700 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
701 config = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
702 // The queue of tests to run
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
703 queue: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
704
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
705 // block until document ready
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
706 blocking: true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
707
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
708 // when enabled, show only failing tests
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
709 // gets persisted through sessionStorage and can be changed in UI via checkbox
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
710 hidepassed: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
711
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
712 // by default, run previously failed tests first
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
713 // very useful in combination with "Hide passed tests" checked
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
714 reorder: true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
715
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
716 // by default, modify document.title when suite is done
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
717 altertitle: true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
718
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
719 // when enabled, all tests must call expect()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
720 requireExpects: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
721
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
722 // add checkboxes that are persisted in the query-string
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
723 // when enabled, the id is set to `true` as a `QUnit.config` property
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
724 urlConfig: [
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
725 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
726 id: "noglobals",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
727 label: "Check for Globals",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
728 tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings."
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
729 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
730 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
731 id: "notrycatch",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
732 label: "No try-catch",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
733 tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings."
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
734 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
735 ],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
736
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
737 // Set of all modules.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
738 modules: {},
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
739
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
740 // logging callback queues
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
741 begin: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
742 done: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
743 log: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
744 testStart: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
745 testDone: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
746 moduleStart: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
747 moduleDone: []
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
748 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
749
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
750 // Export global variables, unless an 'exports' object exists,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
751 // in that case we assume we're in CommonJS (dealt with on the bottom of the script)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
752 if ( typeof exports === "undefined" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
753 extend( window, QUnit.constructor.prototype );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
754
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
755 // Expose QUnit object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
756 window.QUnit = QUnit;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
757 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
758
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
759 // Initialize more QUnit.config and QUnit.urlParams
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
760 (function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
761 var i,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
762 location = window.location || { search: "", protocol: "file:" },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
763 params = location.search.slice( 1 ).split( "&" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
764 length = params.length,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
765 urlParams = {},
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
766 current;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
767
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
768 if ( params[ 0 ] ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
769 for ( i = 0; i < length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
770 current = params[ i ].split( "=" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
771 current[ 0 ] = decodeURIComponent( current[ 0 ] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
772 // allow just a key to turn on a flag, e.g., test.html?noglobals
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
773 current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
774 urlParams[ current[ 0 ] ] = current[ 1 ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
775 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
776 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
777
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
778 QUnit.urlParams = urlParams;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
779
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
780 // String search anywhere in moduleName+testName
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
781 config.filter = urlParams.filter;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
782
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
783 // Exact match of the module name
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
784 config.module = urlParams.module;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
785
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
786 config.testNumber = parseInt( urlParams.testNumber, 10 ) || null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
787
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
788 // Figure out if we're running the tests from a server or not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
789 QUnit.isLocal = location.protocol === "file:";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
790 }());
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
791
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
792 // Extend QUnit object,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
793 // these after set here because they should not be exposed as global functions
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
794 extend( QUnit, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
795 assert: assert,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
796
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
797 config: config,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
798
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
799 // Initialize the configuration options
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
800 init: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
801 extend( config, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
802 stats: { all: 0, bad: 0 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
803 moduleStats: { all: 0, bad: 0 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
804 started: +new Date(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
805 updateRate: 1000,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
806 blocking: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
807 autostart: true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
808 autorun: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
809 filter: "",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
810 queue: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
811 semaphore: 1
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
812 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
813
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
814 var tests, banner, result,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
815 qunit = id( "qunit" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
816
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
817 if ( qunit ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
818 qunit.innerHTML =
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
819 "<h1 id='qunit-header'>" + escapeText( document.title ) + "</h1>" +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
820 "<h2 id='qunit-banner'></h2>" +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
821 "<div id='qunit-testrunner-toolbar'></div>" +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
822 "<h2 id='qunit-userAgent'></h2>" +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
823 "<ol id='qunit-tests'></ol>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
824 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
825
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
826 tests = id( "qunit-tests" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
827 banner = id( "qunit-banner" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
828 result = id( "qunit-testresult" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
829
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
830 if ( tests ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
831 tests.innerHTML = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
832 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
833
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
834 if ( banner ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
835 banner.className = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
836 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
837
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
838 if ( result ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
839 result.parentNode.removeChild( result );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
840 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
841
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
842 if ( tests ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
843 result = document.createElement( "p" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
844 result.id = "qunit-testresult";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
845 result.className = "result";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
846 tests.parentNode.insertBefore( result, tests );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
847 result.innerHTML = "Running...<br/>&nbsp;";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
848 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
849 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
850
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
851 // Resets the test setup. Useful for tests that modify the DOM.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
852 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
853 DEPRECATED: Use multiple tests instead of resetting inside a test.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
854 Use testStart or testDone for custom cleanup.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
855 This method will throw an error in 2.0, and will be removed in 2.1
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
856 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
857 reset: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
858 var fixture = id( "qunit-fixture" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
859 if ( fixture ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
860 fixture.innerHTML = config.fixture;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
861 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
862 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
863
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
864 // Trigger an event on an element.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
865 // @example triggerEvent( document.body, "click" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
866 triggerEvent: function( elem, type, event ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
867 if ( document.createEvent ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
868 event = document.createEvent( "MouseEvents" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
869 event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
870 0, 0, 0, 0, 0, false, false, false, false, 0, null);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
871
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
872 elem.dispatchEvent( event );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
873 } else if ( elem.fireEvent ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
874 elem.fireEvent( "on" + type );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
875 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
876 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
877
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
878 // Safe object type checking
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
879 is: function( type, obj ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
880 return QUnit.objectType( obj ) === type;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
881 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
882
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
883 objectType: function( obj ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
884 if ( typeof obj === "undefined" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
885 return "undefined";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
886 // consider: typeof null === object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
887 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
888 if ( obj === null ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
889 return "null";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
890 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
891
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
892 var match = toString.call( obj ).match(/^\[object\s(.*)\]$/),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
893 type = match && match[1] || "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
894
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
895 switch ( type ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
896 case "Number":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
897 if ( isNaN(obj) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
898 return "nan";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
899 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
900 return "number";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
901 case "String":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
902 case "Boolean":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
903 case "Array":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
904 case "Date":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
905 case "RegExp":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
906 case "Function":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
907 return type.toLowerCase();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
908 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
909 if ( typeof obj === "object" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
910 return "object";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
911 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
912 return undefined;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
913 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
914
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
915 push: function( result, actual, expected, message ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
916 if ( !config.current ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
917 throw new Error( "assertion outside test context, was " + sourceFromStacktrace() );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
918 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
919
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
920 var output, source,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
921 details = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
922 module: config.current.module,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
923 name: config.current.testName,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
924 result: result,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
925 message: message,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
926 actual: actual,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
927 expected: expected
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
928 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
929
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
930 message = escapeText( message ) || ( result ? "okay" : "failed" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
931 message = "<span class='test-message'>" + message + "</span>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
932 output = message;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
933
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
934 if ( !result ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
935 expected = escapeText( QUnit.jsDump.parse(expected) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
936 actual = escapeText( QUnit.jsDump.parse(actual) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
937 output += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + expected + "</pre></td></tr>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
938
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
939 if ( actual !== expected ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
940 output += "<tr class='test-actual'><th>Result: </th><td><pre>" + actual + "</pre></td></tr>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
941 output += "<tr class='test-diff'><th>Diff: </th><td><pre>" + QUnit.diff( expected, actual ) + "</pre></td></tr>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
942 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
943
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
944 source = sourceFromStacktrace();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
945
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
946 if ( source ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
947 details.source = source;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
948 output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
949 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
950
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
951 output += "</table>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
952 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
953
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
954 runLoggingCallbacks( "log", QUnit, details );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
955
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
956 config.current.assertions.push({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
957 result: !!result,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
958 message: output
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
959 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
960 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
961
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
962 pushFailure: function( message, source, actual ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
963 if ( !config.current ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
964 throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
965 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
966
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
967 var output,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
968 details = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
969 module: config.current.module,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
970 name: config.current.testName,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
971 result: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
972 message: message
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
973 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
974
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
975 message = escapeText( message ) || "error";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
976 message = "<span class='test-message'>" + message + "</span>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
977 output = message;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
978
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
979 output += "<table>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
980
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
981 if ( actual ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
982 output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeText( actual ) + "</pre></td></tr>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
983 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
984
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
985 if ( source ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
986 details.source = source;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
987 output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
988 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
989
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
990 output += "</table>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
991
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
992 runLoggingCallbacks( "log", QUnit, details );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
993
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
994 config.current.assertions.push({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
995 result: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
996 message: output
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
997 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
998 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
999
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1000 url: function( params ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1001 params = extend( extend( {}, QUnit.urlParams ), params );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1002 var key,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1003 querystring = "?";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1004
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1005 for ( key in params ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1006 if ( hasOwn.call( params, key ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1007 querystring += encodeURIComponent( key ) + "=" +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1008 encodeURIComponent( params[ key ] ) + "&";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1009 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1010 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1011 return window.location.protocol + "//" + window.location.host +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1012 window.location.pathname + querystring.slice( 0, -1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1013 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1014
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1015 extend: extend,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1016 id: id,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1017 addEvent: addEvent,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1018 addClass: addClass,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1019 hasClass: hasClass,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1020 removeClass: removeClass
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1021 // load, equiv, jsDump, diff: Attached later
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1022 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1023
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1024 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1025 * @deprecated: Created for backwards compatibility with test runner that set the hook function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1026 * into QUnit.{hook}, instead of invoking it and passing the hook function.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1027 * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1028 * Doing this allows us to tell if the following methods have been overwritten on the actual
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1029 * QUnit object.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1030 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1031 extend( QUnit.constructor.prototype, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1032
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1033 // Logging callbacks; all receive a single argument with the listed properties
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1034 // run test/logs.html for any related changes
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1035 begin: registerLoggingCallback( "begin" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1036
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1037 // done: { failed, passed, total, runtime }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1038 done: registerLoggingCallback( "done" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1039
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1040 // log: { result, actual, expected, message }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1041 log: registerLoggingCallback( "log" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1042
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1043 // testStart: { name }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1044 testStart: registerLoggingCallback( "testStart" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1045
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1046 // testDone: { name, failed, passed, total, duration }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1047 testDone: registerLoggingCallback( "testDone" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1048
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1049 // moduleStart: { name }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1050 moduleStart: registerLoggingCallback( "moduleStart" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1051
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1052 // moduleDone: { name, failed, passed, total }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1053 moduleDone: registerLoggingCallback( "moduleDone" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1054 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1055
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1056 if ( typeof document === "undefined" || document.readyState === "complete" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1057 config.autorun = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1058 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1059
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1060 QUnit.load = function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1061 runLoggingCallbacks( "begin", QUnit, {} );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1062
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1063 // Initialize the config, saving the execution queue
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1064 var banner, filter, i, label, len, main, ol, toolbar, userAgent, val,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1065 urlConfigCheckboxesContainer, urlConfigCheckboxes, moduleFilter,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1066 numModules = 0,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1067 moduleNames = [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1068 moduleFilterHtml = "",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1069 urlConfigHtml = "",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1070 oldconfig = extend( {}, config );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1071
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1072 QUnit.init();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1073 extend(config, oldconfig);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1074
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1075 config.blocking = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1076
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1077 len = config.urlConfig.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1078
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1079 for ( i = 0; i < len; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1080 val = config.urlConfig[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1081 if ( typeof val === "string" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1082 val = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1083 id: val,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1084 label: val,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1085 tooltip: "[no tooltip available]"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1086 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1087 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1088 config[ val.id ] = QUnit.urlParams[ val.id ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1089 urlConfigHtml += "<input id='qunit-urlconfig-" + escapeText( val.id ) +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1090 "' name='" + escapeText( val.id ) +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1091 "' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1092 " title='" + escapeText( val.tooltip ) +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1093 "'><label for='qunit-urlconfig-" + escapeText( val.id ) +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1094 "' title='" + escapeText( val.tooltip ) + "'>" + val.label + "</label>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1095 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1096 for ( i in config.modules ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1097 if ( config.modules.hasOwnProperty( i ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1098 moduleNames.push(i);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1099 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1100 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1101 numModules = moduleNames.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1102 moduleNames.sort( function( a, b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1103 return a.localeCompare( b );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1104 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1105 moduleFilterHtml += "<label for='qunit-modulefilter'>Module: </label><select id='qunit-modulefilter' name='modulefilter'><option value='' " +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1106 ( config.module === undefined ? "selected='selected'" : "" ) +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1107 ">< All Modules ></option>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1108
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1109
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1110 for ( i = 0; i < numModules; i++) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1111 moduleFilterHtml += "<option value='" + escapeText( encodeURIComponent(moduleNames[i]) ) + "' " +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1112 ( config.module === moduleNames[i] ? "selected='selected'" : "" ) +
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1113 ">" + escapeText(moduleNames[i]) + "</option>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1114 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1115 moduleFilterHtml += "</select>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1116
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1117 // `userAgent` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1118 userAgent = id( "qunit-userAgent" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1119 if ( userAgent ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1120 userAgent.innerHTML = navigator.userAgent;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1121 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1122
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1123 // `banner` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1124 banner = id( "qunit-header" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1125 if ( banner ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1126 banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined, module: undefined, testNumber: undefined }) + "'>" + banner.innerHTML + "</a> ";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1127 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1128
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1129 // `toolbar` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1130 toolbar = id( "qunit-testrunner-toolbar" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1131 if ( toolbar ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1132 // `filter` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1133 filter = document.createElement( "input" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1134 filter.type = "checkbox";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1135 filter.id = "qunit-filter-pass";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1136
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1137 addEvent( filter, "click", function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1138 var tmp,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1139 ol = document.getElementById( "qunit-tests" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1140
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1141 if ( filter.checked ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1142 ol.className = ol.className + " hidepass";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1143 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1144 tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1145 ol.className = tmp.replace( / hidepass /, " " );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1146 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1147 if ( defined.sessionStorage ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1148 if (filter.checked) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1149 sessionStorage.setItem( "qunit-filter-passed-tests", "true" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1150 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1151 sessionStorage.removeItem( "qunit-filter-passed-tests" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1152 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1153 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1154 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1155
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1156 if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1157 filter.checked = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1158 // `ol` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1159 ol = document.getElementById( "qunit-tests" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1160 ol.className = ol.className + " hidepass";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1161 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1162 toolbar.appendChild( filter );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1163
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1164 // `label` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1165 label = document.createElement( "label" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1166 label.setAttribute( "for", "qunit-filter-pass" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1167 label.setAttribute( "title", "Only show tests and assertions that fail. Stored in sessionStorage." );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1168 label.innerHTML = "Hide passed tests";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1169 toolbar.appendChild( label );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1170
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1171 urlConfigCheckboxesContainer = document.createElement("span");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1172 urlConfigCheckboxesContainer.innerHTML = urlConfigHtml;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1173 urlConfigCheckboxes = urlConfigCheckboxesContainer.getElementsByTagName("input");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1174 // For oldIE support:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1175 // * Add handlers to the individual elements instead of the container
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1176 // * Use "click" instead of "change"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1177 // * Fallback from event.target to event.srcElement
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1178 addEvents( urlConfigCheckboxes, "click", function( event ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1179 var params = {},
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1180 target = event.target || event.srcElement;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1181 params[ target.name ] = target.checked ? true : undefined;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1182 window.location = QUnit.url( params );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1183 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1184 toolbar.appendChild( urlConfigCheckboxesContainer );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1185
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1186 if (numModules > 1) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1187 moduleFilter = document.createElement( "span" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1188 moduleFilter.setAttribute( "id", "qunit-modulefilter-container" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1189 moduleFilter.innerHTML = moduleFilterHtml;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1190 addEvent( moduleFilter.lastChild, "change", function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1191 var selectBox = moduleFilter.getElementsByTagName("select")[0],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1192 selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1193
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1194 window.location = QUnit.url({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1195 module: ( selectedModule === "" ) ? undefined : selectedModule,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1196 // Remove any existing filters
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1197 filter: undefined,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1198 testNumber: undefined
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1199 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1200 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1201 toolbar.appendChild(moduleFilter);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1202 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1203 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1204
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1205 // `main` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1206 main = id( "qunit-fixture" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1207 if ( main ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1208 config.fixture = main.innerHTML;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1209 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1210
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1211 if ( config.autostart ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1212 QUnit.start();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1213 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1214 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1215
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1216 addEvent( window, "load", QUnit.load );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1217
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1218 // `onErrorFnPrev` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1219 // Preserve other handlers
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1220 onErrorFnPrev = window.onerror;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1221
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1222 // Cover uncaught exceptions
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1223 // Returning true will suppress the default browser handler,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1224 // returning false will let it run.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1225 window.onerror = function ( error, filePath, linerNr ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1226 var ret = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1227 if ( onErrorFnPrev ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1228 ret = onErrorFnPrev( error, filePath, linerNr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1229 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1230
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1231 // Treat return value as window.onerror itself does,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1232 // Only do our handling if not suppressed.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1233 if ( ret !== true ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1234 if ( QUnit.config.current ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1235 if ( QUnit.config.current.ignoreGlobalErrors ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1236 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1237 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1238 QUnit.pushFailure( error, filePath + ":" + linerNr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1239 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1240 QUnit.test( "global failure", extend( function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1241 QUnit.pushFailure( error, filePath + ":" + linerNr );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1242 }, { validTest: validTest } ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1243 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1244 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1245 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1246
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1247 return ret;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1248 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1249
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1250 function done() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1251 config.autorun = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1252
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1253 // Log the last module results
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1254 if ( config.currentModule ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1255 runLoggingCallbacks( "moduleDone", QUnit, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1256 name: config.currentModule,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1257 failed: config.moduleStats.bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1258 passed: config.moduleStats.all - config.moduleStats.bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1259 total: config.moduleStats.all
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1260 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1261 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1262 delete config.previousModule;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1263
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1264 var i, key,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1265 banner = id( "qunit-banner" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1266 tests = id( "qunit-tests" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1267 runtime = +new Date() - config.started,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1268 passed = config.stats.all - config.stats.bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1269 html = [
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1270 "Tests completed in ",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1271 runtime,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1272 " milliseconds.<br/>",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1273 "<span class='passed'>",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1274 passed,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1275 "</span> assertions of <span class='total'>",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1276 config.stats.all,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1277 "</span> passed, <span class='failed'>",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1278 config.stats.bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1279 "</span> failed."
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1280 ].join( "" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1281
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1282 if ( banner ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1283 banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1284 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1285
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1286 if ( tests ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1287 id( "qunit-testresult" ).innerHTML = html;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1288 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1289
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1290 if ( config.altertitle && typeof document !== "undefined" && document.title ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1291 // show ✖ for good, ✔ for bad suite result in title
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1292 // use escape sequences in case file gets loaded with non-utf-8-charset
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1293 document.title = [
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1294 ( config.stats.bad ? "\u2716" : "\u2714" ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1295 document.title.replace( /^[\u2714\u2716] /i, "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1296 ].join( " " );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1297 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1298
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1299 // clear own sessionStorage items if all tests passed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1300 if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1301 // `key` & `i` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1302 for ( i = 0; i < sessionStorage.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1303 key = sessionStorage.key( i++ );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1304 if ( key.indexOf( "qunit-test-" ) === 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1305 sessionStorage.removeItem( key );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1306 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1307 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1308 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1309
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1310 // scroll back to top to show results
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1311 if ( window.scrollTo ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1312 window.scrollTo(0, 0);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1313 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1314
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1315 runLoggingCallbacks( "done", QUnit, {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1316 failed: config.stats.bad,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1317 passed: passed,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1318 total: config.stats.all,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1319 runtime: runtime
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1320 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1321 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1322
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1323 /** @return Boolean: true if this test should be ran */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1324 function validTest( test ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1325 var include,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1326 filter = config.filter && config.filter.toLowerCase(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1327 module = config.module && config.module.toLowerCase(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1328 fullName = (test.module + ": " + test.testName).toLowerCase();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1329
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1330 // Internally-generated tests are always valid
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1331 if ( test.callback && test.callback.validTest === validTest ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1332 delete test.callback.validTest;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1333 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1334 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1335
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1336 if ( config.testNumber ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1337 return test.testNumber === config.testNumber;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1338 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1339
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1340 if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1341 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1342 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1343
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1344 if ( !filter ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1345 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1346 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1347
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1348 include = filter.charAt( 0 ) !== "!";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1349 if ( !include ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1350 filter = filter.slice( 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1351 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1352
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1353 // If the filter matches, we need to honour include
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1354 if ( fullName.indexOf( filter ) !== -1 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1355 return include;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1356 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1357
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1358 // Otherwise, do the opposite
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1359 return !include;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1360 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1361
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1362 // so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1363 // Later Safari and IE10 are supposed to support error.stack as well
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1364 // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1365 function extractStacktrace( e, offset ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1366 offset = offset === undefined ? 3 : offset;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1367
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1368 var stack, include, i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1369
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1370 if ( e.stacktrace ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1371 // Opera
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1372 return e.stacktrace.split( "\n" )[ offset + 3 ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1373 } else if ( e.stack ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1374 // Firefox, Chrome
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1375 stack = e.stack.split( "\n" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1376 if (/^error$/i.test( stack[0] ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1377 stack.shift();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1378 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1379 if ( fileName ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1380 include = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1381 for ( i = offset; i < stack.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1382 if ( stack[ i ].indexOf( fileName ) !== -1 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1383 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1384 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1385 include.push( stack[ i ] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1386 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1387 if ( include.length ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1388 return include.join( "\n" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1389 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1390 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1391 return stack[ offset ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1392 } else if ( e.sourceURL ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1393 // Safari, PhantomJS
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1394 // hopefully one day Safari provides actual stacktraces
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1395 // exclude useless self-reference for generated Error objects
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1396 if ( /qunit.js$/.test( e.sourceURL ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1397 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1398 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1399 // for actual exceptions, this is useful
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1400 return e.sourceURL + ":" + e.line;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1401 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1402 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1403 function sourceFromStacktrace( offset ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1404 try {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1405 throw new Error();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1406 } catch ( e ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1407 return extractStacktrace( e, offset );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1408 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1409 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1410
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1411 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1412 * Escape text for attribute or text content.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1413 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1414 function escapeText( s ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1415 if ( !s ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1416 return "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1417 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1418 s = s + "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1419 // Both single quotes and double quotes (for attributes)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1420 return s.replace( /['"<>&]/g, function( s ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1421 switch( s ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1422 case "'":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1423 return "&#039;";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1424 case "\"":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1425 return "&quot;";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1426 case "<":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1427 return "&lt;";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1428 case ">":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1429 return "&gt;";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1430 case "&":
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1431 return "&amp;";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1432 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1433 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1434 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1435
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1436 function synchronize( callback, last ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1437 config.queue.push( callback );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1438
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1439 if ( config.autorun && !config.blocking ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1440 process( last );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1441 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1442 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1443
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1444 function process( last ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1445 function next() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1446 process( last );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1447 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1448 var start = new Date().getTime();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1449 config.depth = config.depth ? config.depth + 1 : 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1450
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1451 while ( config.queue.length && !config.blocking ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1452 if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1453 config.queue.shift()();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1454 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1455 setTimeout( next, 13 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1456 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1457 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1458 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1459 config.depth--;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1460 if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1461 done();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1462 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1463 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1464
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1465 function saveGlobal() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1466 config.pollution = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1467
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1468 if ( config.noglobals ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1469 for ( var key in window ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1470 if ( hasOwn.call( window, key ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1471 // in Opera sometimes DOM element ids show up here, ignore them
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1472 if ( /^qunit-test-output/.test( key ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1473 continue;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1474 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1475 config.pollution.push( key );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1476 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1477 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1478 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1479 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1480
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1481 function checkPollution() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1482 var newGlobals,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1483 deletedGlobals,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1484 old = config.pollution;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1485
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1486 saveGlobal();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1487
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1488 newGlobals = diff( config.pollution, old );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1489 if ( newGlobals.length > 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1490 QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1491 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1492
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1493 deletedGlobals = diff( old, config.pollution );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1494 if ( deletedGlobals.length > 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1495 QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1496 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1497 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1498
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1499 // returns a new Array with the elements that are in a but not in b
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1500 function diff( a, b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1501 var i, j,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1502 result = a.slice();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1503
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1504 for ( i = 0; i < result.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1505 for ( j = 0; j < b.length; j++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1506 if ( result[i] === b[j] ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1507 result.splice( i, 1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1508 i--;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1509 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1510 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1511 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1512 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1513 return result;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1514 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1515
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1516 function extend( a, b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1517 for ( var prop in b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1518 if ( hasOwn.call( b, prop ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1519 // Avoid "Member not found" error in IE8 caused by messing with window.constructor
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1520 if ( !( prop === "constructor" && a === window ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1521 if ( b[ prop ] === undefined ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1522 delete a[ prop ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1523 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1524 a[ prop ] = b[ prop ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1525 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1526 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1527 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1528 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1529
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1530 return a;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1531 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1532
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1533 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1534 * @param {HTMLElement} elem
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1535 * @param {string} type
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1536 * @param {Function} fn
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1537 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1538 function addEvent( elem, type, fn ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1539 // Standards-based browsers
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1540 if ( elem.addEventListener ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1541 elem.addEventListener( type, fn, false );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1542 // IE
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1543 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1544 elem.attachEvent( "on" + type, fn );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1545 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1546 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1547
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1548 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1549 * @param {Array|NodeList} elems
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1550 * @param {string} type
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1551 * @param {Function} fn
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1552 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1553 function addEvents( elems, type, fn ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1554 var i = elems.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1555 while ( i-- ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1556 addEvent( elems[i], type, fn );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1557 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1558 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1559
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1560 function hasClass( elem, name ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1561 return (" " + elem.className + " ").indexOf(" " + name + " ") > -1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1562 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1563
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1564 function addClass( elem, name ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1565 if ( !hasClass( elem, name ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1566 elem.className += (elem.className ? " " : "") + name;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1567 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1568 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1569
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1570 function removeClass( elem, name ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1571 var set = " " + elem.className + " ";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1572 // Class name may appear multiple times
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1573 while ( set.indexOf(" " + name + " ") > -1 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1574 set = set.replace(" " + name + " " , " ");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1575 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1576 // If possible, trim it for prettiness, but not necessarily
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1577 elem.className = typeof set.trim === "function" ? set.trim() : set.replace(/^\s+|\s+$/g, "");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1578 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1579
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1580 function id( name ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1581 return !!( typeof document !== "undefined" && document && document.getElementById ) &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1582 document.getElementById( name );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1583 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1584
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1585 function registerLoggingCallback( key ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1586 return function( callback ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1587 config[key].push( callback );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1588 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1589 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1590
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1591 // Supports deprecated method of completely overwriting logging callbacks
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1592 function runLoggingCallbacks( key, scope, args ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1593 var i, callbacks;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1594 if ( QUnit.hasOwnProperty( key ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1595 QUnit[ key ].call(scope, args );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1596 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1597 callbacks = config[ key ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1598 for ( i = 0; i < callbacks.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1599 callbacks[ i ].call( scope, args );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1600 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1601 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1602 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1603
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1604 // Test for equality any JavaScript type.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1605 // Author: Philippe Rathé <prathe@gmail.com>
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1606 QUnit.equiv = (function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1607
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1608 // Call the o related callback with the given arguments.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1609 function bindCallbacks( o, callbacks, args ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1610 var prop = QUnit.objectType( o );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1611 if ( prop ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1612 if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1613 return callbacks[ prop ].apply( callbacks, args );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1614 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1615 return callbacks[ prop ]; // or undefined
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1616 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1617 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1618 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1619
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1620 // the real equiv function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1621 var innerEquiv,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1622 // stack to decide between skip/abort functions
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1623 callers = [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1624 // stack to avoiding loops from circular referencing
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1625 parents = [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1626 parentsB = [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1627
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1628 getProto = Object.getPrototypeOf || function ( obj ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1629 /*jshint camelcase:false */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1630 return obj.__proto__;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1631 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1632 callbacks = (function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1633
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1634 // for string, boolean, number and null
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1635 function useStrictEquality( b, a ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1636 /*jshint eqeqeq:false */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1637 if ( b instanceof a.constructor || a instanceof b.constructor ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1638 // to catch short annotation VS 'new' annotation of a
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1639 // declaration
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1640 // e.g. var i = 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1641 // var j = new Number(1);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1642 return a == b;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1643 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1644 return a === b;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1645 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1646 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1647
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1648 return {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1649 "string": useStrictEquality,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1650 "boolean": useStrictEquality,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1651 "number": useStrictEquality,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1652 "null": useStrictEquality,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1653 "undefined": useStrictEquality,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1654
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1655 "nan": function( b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1656 return isNaN( b );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1657 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1658
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1659 "date": function( b, a ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1660 return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1661 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1662
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1663 "regexp": function( b, a ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1664 return QUnit.objectType( b ) === "regexp" &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1665 // the regex itself
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1666 a.source === b.source &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1667 // and its modifiers
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1668 a.global === b.global &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1669 // (gmi) ...
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1670 a.ignoreCase === b.ignoreCase &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1671 a.multiline === b.multiline &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1672 a.sticky === b.sticky;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1673 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1674
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1675 // - skip when the property is a method of an instance (OOP)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1676 // - abort otherwise,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1677 // initial === would have catch identical references anyway
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1678 "function": function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1679 var caller = callers[callers.length - 1];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1680 return caller !== Object && typeof caller !== "undefined";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1681 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1682
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1683 "array": function( b, a ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1684 var i, j, len, loop, aCircular, bCircular;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1685
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1686 // b could be an object literal here
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1687 if ( QUnit.objectType( b ) !== "array" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1688 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1689 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1690
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1691 len = a.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1692 if ( len !== b.length ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1693 // safe and faster
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1694 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1695 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1696
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1697 // track reference to avoid circular references
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1698 parents.push( a );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1699 parentsB.push( b );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1700 for ( i = 0; i < len; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1701 loop = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1702 for ( j = 0; j < parents.length; j++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1703 aCircular = parents[j] === a[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1704 bCircular = parentsB[j] === b[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1705 if ( aCircular || bCircular ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1706 if ( a[i] === b[i] || aCircular && bCircular ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1707 loop = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1708 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1709 parents.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1710 parentsB.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1711 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1712 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1713 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1714 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1715 if ( !loop && !innerEquiv(a[i], b[i]) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1716 parents.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1717 parentsB.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1718 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1719 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1720 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1721 parents.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1722 parentsB.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1723 return true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1724 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1725
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1726 "object": function( b, a ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1727 /*jshint forin:false */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1728 var i, j, loop, aCircular, bCircular,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1729 // Default to true
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1730 eq = true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1731 aProperties = [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1732 bProperties = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1733
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1734 // comparing constructors is more strict than using
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1735 // instanceof
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1736 if ( a.constructor !== b.constructor ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1737 // Allow objects with no prototype to be equivalent to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1738 // objects with Object as their constructor.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1739 if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1740 ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1741 return false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1742 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1743 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1744
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1745 // stack constructor before traversing properties
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1746 callers.push( a.constructor );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1747
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1748 // track reference to avoid circular references
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1749 parents.push( a );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1750 parentsB.push( b );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1751
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1752 // be strict: don't ensure hasOwnProperty and go deep
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1753 for ( i in a ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1754 loop = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1755 for ( j = 0; j < parents.length; j++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1756 aCircular = parents[j] === a[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1757 bCircular = parentsB[j] === b[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1758 if ( aCircular || bCircular ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1759 if ( a[i] === b[i] || aCircular && bCircular ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1760 loop = true;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1761 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1762 eq = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1763 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1764 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1765 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1766 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1767 aProperties.push(i);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1768 if ( !loop && !innerEquiv(a[i], b[i]) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1769 eq = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1770 break;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1771 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1772 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1773
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1774 parents.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1775 parentsB.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1776 callers.pop(); // unstack, we are done
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1777
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1778 for ( i in b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1779 bProperties.push( i ); // collect b's properties
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1780 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1781
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1782 // Ensures identical properties name
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1783 return eq && innerEquiv( aProperties.sort(), bProperties.sort() );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1784 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1785 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1786 }());
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1787
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1788 innerEquiv = function() { // can take multiple arguments
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1789 var args = [].slice.apply( arguments );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1790 if ( args.length < 2 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1791 return true; // end transition
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1792 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1793
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1794 return (function( a, b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1795 if ( a === b ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1796 return true; // catch the most you can
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1797 } else if ( a === null || b === null || typeof a === "undefined" ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1798 typeof b === "undefined" ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1799 QUnit.objectType(a) !== QUnit.objectType(b) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1800 return false; // don't lose time with error prone cases
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1801 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1802 return bindCallbacks(a, callbacks, [ b, a ]);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1803 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1804
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1805 // apply transition with (1..n) arguments
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1806 }( args[0], args[1] ) && innerEquiv.apply( this, args.splice(1, args.length - 1 )) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1807 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1808
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1809 return innerEquiv;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1810 }());
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1811
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1812 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1813 * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com |
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1814 * http://flesler.blogspot.com Licensed under BSD
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1815 * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1816 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1817 * @projectDescription Advanced and extensible data dumping for Javascript.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1818 * @version 1.0.0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1819 * @author Ariel Flesler
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1820 * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1821 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1822 QUnit.jsDump = (function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1823 function quote( str ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1824 return "\"" + str.toString().replace( /"/g, "\\\"" ) + "\"";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1825 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1826 function literal( o ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1827 return o + "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1828 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1829 function join( pre, arr, post ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1830 var s = jsDump.separator(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1831 base = jsDump.indent(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1832 inner = jsDump.indent(1);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1833 if ( arr.join ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1834 arr = arr.join( "," + s + inner );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1835 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1836 if ( !arr ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1837 return pre + post;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1838 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1839 return [ pre, inner + arr, base + post ].join(s);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1840 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1841 function array( arr, stack ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1842 var i = arr.length, ret = new Array(i);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1843 this.up();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1844 while ( i-- ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1845 ret[i] = this.parse( arr[i] , undefined , stack);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1846 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1847 this.down();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1848 return join( "[", ret, "]" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1849 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1850
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1851 var reName = /^function (\w+)/,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1852 jsDump = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1853 // type is used mostly internally, you can fix a (custom)type in advance
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1854 parse: function( obj, type, stack ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1855 stack = stack || [ ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1856 var inStack, res,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1857 parser = this.parsers[ type || this.typeOf(obj) ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1858
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1859 type = typeof parser;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1860 inStack = inArray( obj, stack );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1861
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1862 if ( inStack !== -1 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1863 return "recursion(" + (inStack - stack.length) + ")";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1864 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1865 if ( type === "function" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1866 stack.push( obj );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1867 res = parser.call( this, obj, stack );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1868 stack.pop();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1869 return res;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1870 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1871 return ( type === "string" ) ? parser : this.parsers.error;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1872 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1873 typeOf: function( obj ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1874 var type;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1875 if ( obj === null ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1876 type = "null";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1877 } else if ( typeof obj === "undefined" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1878 type = "undefined";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1879 } else if ( QUnit.is( "regexp", obj) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1880 type = "regexp";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1881 } else if ( QUnit.is( "date", obj) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1882 type = "date";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1883 } else if ( QUnit.is( "function", obj) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1884 type = "function";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1885 } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1886 type = "window";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1887 } else if ( obj.nodeType === 9 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1888 type = "document";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1889 } else if ( obj.nodeType ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1890 type = "node";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1891 } else if (
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1892 // native arrays
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1893 toString.call( obj ) === "[object Array]" ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1894 // NodeList objects
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1895 ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1896 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1897 type = "array";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1898 } else if ( obj.constructor === Error.prototype.constructor ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1899 type = "error";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1900 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1901 type = typeof obj;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1902 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1903 return type;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1904 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1905 separator: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1906 return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? "&nbsp;" : " ";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1907 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1908 // extra can be a number, shortcut for increasing-calling-decreasing
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1909 indent: function( extra ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1910 if ( !this.multiline ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1911 return "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1912 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1913 var chr = this.indentChar;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1914 if ( this.HTML ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1915 chr = chr.replace( /\t/g, " " ).replace( / /g, "&nbsp;" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1916 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1917 return new Array( this.depth + ( extra || 0 ) ).join(chr);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1918 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1919 up: function( a ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1920 this.depth += a || 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1921 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1922 down: function( a ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1923 this.depth -= a || 1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1924 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1925 setParser: function( name, parser ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1926 this.parsers[name] = parser;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1927 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1928 // The next 3 are exposed so you can use them
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1929 quote: quote,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1930 literal: literal,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1931 join: join,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1932 //
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1933 depth: 1,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1934 // This is the list of parsers, to modify them, use jsDump.setParser
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1935 parsers: {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1936 window: "[Window]",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1937 document: "[Document]",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1938 error: function(error) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1939 return "Error(\"" + error.message + "\")";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1940 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1941 unknown: "[Unknown]",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1942 "null": "null",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1943 "undefined": "undefined",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1944 "function": function( fn ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1945 var ret = "function",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1946 // functions never have name in IE
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1947 name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1948
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1949 if ( name ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1950 ret += " " + name;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1951 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1952 ret += "( ";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1953
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1954 ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1955 return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1956 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1957 array: array,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1958 nodelist: array,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1959 "arguments": array,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1960 object: function( map, stack ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1961 /*jshint forin:false */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1962 var ret = [ ], keys, key, val, i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1963 QUnit.jsDump.up();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1964 keys = [];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1965 for ( key in map ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1966 keys.push( key );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1967 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1968 keys.sort();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1969 for ( i = 0; i < keys.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1970 key = keys[ i ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1971 val = map[ key ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1972 ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1973 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1974 QUnit.jsDump.down();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1975 return join( "{", ret, "}" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1976 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1977 node: function( node ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1978 var len, i, val,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1979 open = QUnit.jsDump.HTML ? "&lt;" : "<",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1980 close = QUnit.jsDump.HTML ? "&gt;" : ">",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1981 tag = node.nodeName.toLowerCase(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1982 ret = open + tag,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1983 attrs = node.attributes;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1984
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1985 if ( attrs ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1986 for ( i = 0, len = attrs.length; i < len; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1987 val = attrs[i].nodeValue;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1988 // IE6 includes all attributes in .attributes, even ones not explicitly set.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1989 // Those have values like undefined, null, 0, false, "" or "inherit".
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1990 if ( val && val !== "inherit" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1991 ret += " " + attrs[i].nodeName + "=" + QUnit.jsDump.parse( val, "attribute" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1992 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1993 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1994 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1995 ret += close;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1996
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1997 // Show content of TextNode or CDATASection
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1998 if ( node.nodeType === 3 || node.nodeType === 4 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1999 ret += node.nodeValue;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2000 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2001
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2002 return ret + open + "/" + tag + close;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2003 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2004 // function calls it internally, it's the arguments part of the function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2005 functionArgs: function( fn ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2006 var args,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2007 l = fn.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2008
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2009 if ( !l ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2010 return "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2011 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2012
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2013 args = new Array(l);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2014 while ( l-- ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2015 // 97 is 'a'
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2016 args[l] = String.fromCharCode(97+l);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2017 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2018 return " " + args.join( ", " ) + " ";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2019 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2020 // object calls it internally, the key part of an item in a map
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2021 key: quote,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2022 // function calls it internally, it's the content of the function
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2023 functionCode: "[code]",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2024 // node calls it internally, it's an html attribute value
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2025 attribute: quote,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2026 string: quote,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2027 date: quote,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2028 regexp: literal,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2029 number: literal,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2030 "boolean": literal
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2031 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2032 // if true, entities are escaped ( <, >, \t, space and \n )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2033 HTML: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2034 // indentation unit
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2035 indentChar: " ",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2036 // if true, items in a collection, are separated by a \n, else just a space.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2037 multiline: true
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2038 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2039
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2040 return jsDump;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2041 }());
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2042
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2043 // from jquery.js
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2044 function inArray( elem, array ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2045 if ( array.indexOf ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2046 return array.indexOf( elem );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2047 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2048
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2049 for ( var i = 0, length = array.length; i < length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2050 if ( array[ i ] === elem ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2051 return i;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2052 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2053 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2054
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2055 return -1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2056 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2057
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2058 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2059 * Javascript Diff Algorithm
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2060 * By John Resig (http://ejohn.org/)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2061 * Modified by Chu Alan "sprite"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2062 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2063 * Released under the MIT license.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2064 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2065 * More Info:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2066 * http://ejohn.org/projects/javascript-diff-algorithm/
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2067 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2068 * Usage: QUnit.diff(expected, actual)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2069 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2070 * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2071 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2072 QUnit.diff = (function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2073 /*jshint eqeqeq:false, eqnull:true */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2074 function diff( o, n ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2075 var i,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2076 ns = {},
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2077 os = {};
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2078
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2079 for ( i = 0; i < n.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2080 if ( !hasOwn.call( ns, n[i] ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2081 ns[ n[i] ] = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2082 rows: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2083 o: null
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2084 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2085 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2086 ns[ n[i] ].rows.push( i );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2087 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2088
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2089 for ( i = 0; i < o.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2090 if ( !hasOwn.call( os, o[i] ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2091 os[ o[i] ] = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2092 rows: [],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2093 n: null
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2094 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2095 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2096 os[ o[i] ].rows.push( i );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2097 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2098
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2099 for ( i in ns ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2100 if ( hasOwn.call( ns, i ) ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2101 if ( ns[i].rows.length === 1 && hasOwn.call( os, i ) && os[i].rows.length === 1 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2102 n[ ns[i].rows[0] ] = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2103 text: n[ ns[i].rows[0] ],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2104 row: os[i].rows[0]
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2105 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2106 o[ os[i].rows[0] ] = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2107 text: o[ os[i].rows[0] ],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2108 row: ns[i].rows[0]
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2109 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2110 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2111 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2112 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2113
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2114 for ( i = 0; i < n.length - 1; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2115 if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2116 n[ i + 1 ] == o[ n[i].row + 1 ] ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2117
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2118 n[ i + 1 ] = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2119 text: n[ i + 1 ],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2120 row: n[i].row + 1
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2121 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2122 o[ n[i].row + 1 ] = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2123 text: o[ n[i].row + 1 ],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2124 row: i + 1
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2125 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2126 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2127 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2128
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2129 for ( i = n.length - 1; i > 0; i-- ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2130 if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2131 n[ i - 1 ] == o[ n[i].row - 1 ]) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2132
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2133 n[ i - 1 ] = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2134 text: n[ i - 1 ],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2135 row: n[i].row - 1
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2136 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2137 o[ n[i].row - 1 ] = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2138 text: o[ n[i].row - 1 ],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2139 row: i - 1
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2140 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2141 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2142 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2143
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2144 return {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2145 o: o,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2146 n: n
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2147 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2148 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2149
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2150 return function( o, n ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2151 o = o.replace( /\s+$/, "" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2152 n = n.replace( /\s+$/, "" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2153
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2154 var i, pre,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2155 str = "",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2156 out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2157 oSpace = o.match(/\s+/g),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2158 nSpace = n.match(/\s+/g);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2159
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2160 if ( oSpace == null ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2161 oSpace = [ " " ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2162 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2163 else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2164 oSpace.push( " " );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2165 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2166
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2167 if ( nSpace == null ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2168 nSpace = [ " " ];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2169 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2170 else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2171 nSpace.push( " " );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2172 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2173
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2174 if ( out.n.length === 0 ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2175 for ( i = 0; i < out.o.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2176 str += "<del>" + out.o[i] + oSpace[i] + "</del>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2177 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2178 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2179 else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2180 if ( out.n[0].text == null ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2181 for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2182 str += "<del>" + out.o[n] + oSpace[n] + "</del>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2183 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2184 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2185
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2186 for ( i = 0; i < out.n.length; i++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2187 if (out.n[i].text == null) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2188 str += "<ins>" + out.n[i] + nSpace[i] + "</ins>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2189 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2190 else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2191 // `pre` initialized at top of scope
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2192 pre = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2193
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2194 for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2195 pre += "<del>" + out.o[n] + oSpace[n] + "</del>";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2196 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2197 str += " " + out.n[i].text + nSpace[i] + pre;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2198 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2199 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2200 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2201
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2202 return str;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2203 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2204 }());
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2205
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2206 // for CommonJS environments, export everything
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2207 if ( typeof exports !== "undefined" ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2208 extend( exports, QUnit.constructor.prototype );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2209 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2210
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2211 // get at whatever the global object is, like window in browsers
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2212 }( (function() {return this;}.call()) ));