qunit.js 70 KB

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