qunit-1.12.0.js 57 KB

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