qunit-1.16.0.js 69 KB

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