mocha.js 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340
  1. ;(function(){
  2. // CommonJS require()
  3. function require(p){
  4. var path = require.resolve(p)
  5. , mod = require.modules[path];
  6. if (!mod) throw new Error('failed to require "' + p + '"');
  7. if (!mod.exports) {
  8. mod.exports = {};
  9. mod.call(mod.exports, mod, mod.exports, require.relative(path));
  10. }
  11. return mod.exports;
  12. }
  13. require.modules = {};
  14. require.resolve = function (path){
  15. var orig = path
  16. , reg = path + '.js'
  17. , index = path + '/index.js';
  18. return require.modules[reg] && reg
  19. || require.modules[index] && index
  20. || orig;
  21. };
  22. require.register = function (path, fn){
  23. require.modules[path] = fn;
  24. };
  25. require.relative = function (parent) {
  26. return function(p){
  27. if ('.' != p.charAt(0)) return require(p);
  28. var path = parent.split('/')
  29. , segs = p.split('/');
  30. path.pop();
  31. for (var i = 0; i < segs.length; i++) {
  32. var seg = segs[i];
  33. if ('..' == seg) path.pop();
  34. else if ('.' != seg) path.push(seg);
  35. }
  36. return require(path.join('/'));
  37. };
  38. };
  39. require.register("browser/debug.js", function(module, exports, require){
  40. module.exports = function(type){
  41. return function(){
  42. }
  43. };
  44. }); // module: browser/debug.js
  45. require.register("browser/diff.js", function(module, exports, require){
  46. /* See license.txt for terms of usage */
  47. /*
  48. * Text diff implementation.
  49. *
  50. * This library supports the following APIS:
  51. * JsDiff.diffChars: Character by character diff
  52. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  53. * JsDiff.diffLines: Line based diff
  54. *
  55. * JsDiff.diffCss: Diff targeted at CSS content
  56. *
  57. * These methods are based on the implementation proposed in
  58. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  59. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  60. */
  61. var JsDiff = (function() {
  62. function clonePath(path) {
  63. return { newPos: path.newPos, components: path.components.slice(0) };
  64. }
  65. function removeEmpty(array) {
  66. var ret = [];
  67. for (var i = 0; i < array.length; i++) {
  68. if (array[i]) {
  69. ret.push(array[i]);
  70. }
  71. }
  72. return ret;
  73. }
  74. function escapeHTML(s) {
  75. var n = s;
  76. n = n.replace(/&/g, "&amp;");
  77. n = n.replace(/</g, "&lt;");
  78. n = n.replace(/>/g, "&gt;");
  79. n = n.replace(/"/g, "&quot;");
  80. return n;
  81. }
  82. var fbDiff = function(ignoreWhitespace) {
  83. this.ignoreWhitespace = ignoreWhitespace;
  84. };
  85. fbDiff.prototype = {
  86. diff: function(oldString, newString) {
  87. // Handle the identity case (this is due to unrolling editLength == 0
  88. if (newString == oldString) {
  89. return [{ value: newString }];
  90. }
  91. if (!newString) {
  92. return [{ value: oldString, removed: true }];
  93. }
  94. if (!oldString) {
  95. return [{ value: newString, added: true }];
  96. }
  97. newString = this.tokenize(newString);
  98. oldString = this.tokenize(oldString);
  99. var newLen = newString.length, oldLen = oldString.length;
  100. var maxEditLength = newLen + oldLen;
  101. var bestPath = [{ newPos: -1, components: [] }];
  102. // Seed editLength = 0
  103. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  104. if (bestPath[0].newPos+1 >= newLen && oldPos+1 >= oldLen) {
  105. return bestPath[0].components;
  106. }
  107. for (var editLength = 1; editLength <= maxEditLength; editLength++) {
  108. for (var diagonalPath = -1*editLength; diagonalPath <= editLength; diagonalPath+=2) {
  109. var basePath;
  110. var addPath = bestPath[diagonalPath-1],
  111. removePath = bestPath[diagonalPath+1];
  112. oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  113. if (addPath) {
  114. // No one else is going to attempt to use this value, clear it
  115. bestPath[diagonalPath-1] = undefined;
  116. }
  117. var canAdd = addPath && addPath.newPos+1 < newLen;
  118. var canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  119. if (!canAdd && !canRemove) {
  120. bestPath[diagonalPath] = undefined;
  121. continue;
  122. }
  123. // Select the diagonal that we want to branch from. We select the prior
  124. // path whose position in the new string is the farthest from the origin
  125. // and does not pass the bounds of the diff graph
  126. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  127. basePath = clonePath(removePath);
  128. this.pushComponent(basePath.components, oldString[oldPos], undefined, true);
  129. } else {
  130. basePath = clonePath(addPath);
  131. basePath.newPos++;
  132. this.pushComponent(basePath.components, newString[basePath.newPos], true, undefined);
  133. }
  134. var oldPos = this.extractCommon(basePath, newString, oldString, diagonalPath);
  135. if (basePath.newPos+1 >= newLen && oldPos+1 >= oldLen) {
  136. return basePath.components;
  137. } else {
  138. bestPath[diagonalPath] = basePath;
  139. }
  140. }
  141. }
  142. },
  143. pushComponent: function(components, value, added, removed) {
  144. var last = components[components.length-1];
  145. if (last && last.added === added && last.removed === removed) {
  146. // We need to clone here as the component clone operation is just
  147. // as shallow array clone
  148. components[components.length-1] =
  149. {value: this.join(last.value, value), added: added, removed: removed };
  150. } else {
  151. components.push({value: value, added: added, removed: removed });
  152. }
  153. },
  154. extractCommon: function(basePath, newString, oldString, diagonalPath) {
  155. var newLen = newString.length,
  156. oldLen = oldString.length,
  157. newPos = basePath.newPos,
  158. oldPos = newPos - diagonalPath;
  159. while (newPos+1 < newLen && oldPos+1 < oldLen && this.equals(newString[newPos+1], oldString[oldPos+1])) {
  160. newPos++;
  161. oldPos++;
  162. this.pushComponent(basePath.components, newString[newPos], undefined, undefined);
  163. }
  164. basePath.newPos = newPos;
  165. return oldPos;
  166. },
  167. equals: function(left, right) {
  168. var reWhitespace = /\S/;
  169. if (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right)) {
  170. return true;
  171. } else {
  172. return left == right;
  173. }
  174. },
  175. join: function(left, right) {
  176. return left + right;
  177. },
  178. tokenize: function(value) {
  179. return value;
  180. }
  181. };
  182. var CharDiff = new fbDiff();
  183. var WordDiff = new fbDiff(true);
  184. WordDiff.tokenize = function(value) {
  185. return removeEmpty(value.split(/(\s+|\b)/));
  186. };
  187. var CssDiff = new fbDiff(true);
  188. CssDiff.tokenize = function(value) {
  189. return removeEmpty(value.split(/([{}:;,]|\s+)/));
  190. };
  191. var LineDiff = new fbDiff();
  192. LineDiff.tokenize = function(value) {
  193. return value.split(/^/m);
  194. };
  195. return {
  196. diffChars: function(oldStr, newStr) { return CharDiff.diff(oldStr, newStr); },
  197. diffWords: function(oldStr, newStr) { return WordDiff.diff(oldStr, newStr); },
  198. diffLines: function(oldStr, newStr) { return LineDiff.diff(oldStr, newStr); },
  199. diffCss: function(oldStr, newStr) { return CssDiff.diff(oldStr, newStr); },
  200. createPatch: function(fileName, oldStr, newStr, oldHeader, newHeader) {
  201. var ret = [];
  202. ret.push("Index: " + fileName);
  203. ret.push("===================================================================");
  204. ret.push("--- " + fileName + (typeof oldHeader === "undefined" ? "" : "\t" + oldHeader));
  205. ret.push("+++ " + fileName + (typeof newHeader === "undefined" ? "" : "\t" + newHeader));
  206. var diff = LineDiff.diff(oldStr, newStr);
  207. if (!diff[diff.length-1].value) {
  208. diff.pop(); // Remove trailing newline add
  209. }
  210. diff.push({value: "", lines: []}); // Append an empty value to make cleanup easier
  211. function contextLines(lines) {
  212. return lines.map(function(entry) { return ' ' + entry; });
  213. }
  214. function eofNL(curRange, i, current) {
  215. var last = diff[diff.length-2],
  216. isLast = i === diff.length-2,
  217. isLastOfType = i === diff.length-3 && (current.added === !last.added || current.removed === !last.removed);
  218. // Figure out if this is the last line for the given file and missing NL
  219. if (!/\n$/.test(current.value) && (isLast || isLastOfType)) {
  220. curRange.push('\\ No newline at end of file');
  221. }
  222. }
  223. var oldRangeStart = 0, newRangeStart = 0, curRange = [],
  224. oldLine = 1, newLine = 1;
  225. for (var i = 0; i < diff.length; i++) {
  226. var current = diff[i],
  227. lines = current.lines || current.value.replace(/\n$/, "").split("\n");
  228. current.lines = lines;
  229. if (current.added || current.removed) {
  230. if (!oldRangeStart) {
  231. var prev = diff[i-1];
  232. oldRangeStart = oldLine;
  233. newRangeStart = newLine;
  234. if (prev) {
  235. curRange = contextLines(prev.lines.slice(-4));
  236. oldRangeStart -= curRange.length;
  237. newRangeStart -= curRange.length;
  238. }
  239. }
  240. curRange.push.apply(curRange, lines.map(function(entry) { return (current.added?"+":"-") + entry; }));
  241. eofNL(curRange, i, current);
  242. if (current.added) {
  243. newLine += lines.length;
  244. } else {
  245. oldLine += lines.length;
  246. }
  247. } else {
  248. if (oldRangeStart) {
  249. // Close out any changes that have been output (or join overlapping)
  250. if (lines.length <= 8 && i < diff.length-2) {
  251. // Overlapping
  252. curRange.push.apply(curRange, contextLines(lines));
  253. } else {
  254. // end the range and output
  255. var contextSize = Math.min(lines.length, 4);
  256. ret.push(
  257. "@@ -" + oldRangeStart + "," + (oldLine-oldRangeStart+contextSize)
  258. + " +" + newRangeStart + "," + (newLine-newRangeStart+contextSize)
  259. + " @@");
  260. ret.push.apply(ret, curRange);
  261. ret.push.apply(ret, contextLines(lines.slice(0, contextSize)));
  262. if (lines.length <= 4) {
  263. eofNL(ret, i, current);
  264. }
  265. oldRangeStart = 0; newRangeStart = 0; curRange = [];
  266. }
  267. }
  268. oldLine += lines.length;
  269. newLine += lines.length;
  270. }
  271. }
  272. return ret.join('\n') + '\n';
  273. },
  274. convertChangesToXML: function(changes){
  275. var ret = [];
  276. for ( var i = 0; i < changes.length; i++) {
  277. var change = changes[i];
  278. if (change.added) {
  279. ret.push("<ins>");
  280. } else if (change.removed) {
  281. ret.push("<del>");
  282. }
  283. ret.push(escapeHTML(change.value));
  284. if (change.added) {
  285. ret.push("</ins>");
  286. } else if (change.removed) {
  287. ret.push("</del>");
  288. }
  289. }
  290. return ret.join("");
  291. }
  292. };
  293. })();
  294. if (typeof module !== "undefined") {
  295. module.exports = JsDiff;
  296. }
  297. }); // module: browser/diff.js
  298. require.register("browser/events.js", function(module, exports, require){
  299. /**
  300. * Module exports.
  301. */
  302. exports.EventEmitter = EventEmitter;
  303. /**
  304. * Check if `obj` is an array.
  305. */
  306. function isArray(obj) {
  307. return '[object Array]' == {}.toString.call(obj);
  308. }
  309. /**
  310. * Event emitter constructor.
  311. *
  312. * @api public
  313. */
  314. function EventEmitter(){};
  315. /**
  316. * Adds a listener.
  317. *
  318. * @api public
  319. */
  320. EventEmitter.prototype.on = function (name, fn) {
  321. if (!this.$events) {
  322. this.$events = {};
  323. }
  324. if (!this.$events[name]) {
  325. this.$events[name] = fn;
  326. } else if (isArray(this.$events[name])) {
  327. this.$events[name].push(fn);
  328. } else {
  329. this.$events[name] = [this.$events[name], fn];
  330. }
  331. return this;
  332. };
  333. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  334. /**
  335. * Adds a volatile listener.
  336. *
  337. * @api public
  338. */
  339. EventEmitter.prototype.once = function (name, fn) {
  340. var self = this;
  341. function on () {
  342. self.removeListener(name, on);
  343. fn.apply(this, arguments);
  344. };
  345. on.listener = fn;
  346. this.on(name, on);
  347. return this;
  348. };
  349. /**
  350. * Removes a listener.
  351. *
  352. * @api public
  353. */
  354. EventEmitter.prototype.removeListener = function (name, fn) {
  355. if (this.$events && this.$events[name]) {
  356. var list = this.$events[name];
  357. if (isArray(list)) {
  358. var pos = -1;
  359. for (var i = 0, l = list.length; i < l; i++) {
  360. if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
  361. pos = i;
  362. break;
  363. }
  364. }
  365. if (pos < 0) {
  366. return this;
  367. }
  368. list.splice(pos, 1);
  369. if (!list.length) {
  370. delete this.$events[name];
  371. }
  372. } else if (list === fn || (list.listener && list.listener === fn)) {
  373. delete this.$events[name];
  374. }
  375. }
  376. return this;
  377. };
  378. /**
  379. * Removes all listeners for an event.
  380. *
  381. * @api public
  382. */
  383. EventEmitter.prototype.removeAllListeners = function (name) {
  384. if (name === undefined) {
  385. this.$events = {};
  386. return this;
  387. }
  388. if (this.$events && this.$events[name]) {
  389. this.$events[name] = null;
  390. }
  391. return this;
  392. };
  393. /**
  394. * Gets all listeners for a certain event.
  395. *
  396. * @api public
  397. */
  398. EventEmitter.prototype.listeners = function (name) {
  399. if (!this.$events) {
  400. this.$events = {};
  401. }
  402. if (!this.$events[name]) {
  403. this.$events[name] = [];
  404. }
  405. if (!isArray(this.$events[name])) {
  406. this.$events[name] = [this.$events[name]];
  407. }
  408. return this.$events[name];
  409. };
  410. /**
  411. * Emits an event.
  412. *
  413. * @api public
  414. */
  415. EventEmitter.prototype.emit = function (name) {
  416. if (!this.$events) {
  417. return false;
  418. }
  419. var handler = this.$events[name];
  420. if (!handler) {
  421. return false;
  422. }
  423. var args = [].slice.call(arguments, 1);
  424. if ('function' == typeof handler) {
  425. handler.apply(this, args);
  426. } else if (isArray(handler)) {
  427. var listeners = handler.slice();
  428. for (var i = 0, l = listeners.length; i < l; i++) {
  429. listeners[i].apply(this, args);
  430. }
  431. } else {
  432. return false;
  433. }
  434. return true;
  435. };
  436. }); // module: browser/events.js
  437. require.register("browser/fs.js", function(module, exports, require){
  438. }); // module: browser/fs.js
  439. require.register("browser/path.js", function(module, exports, require){
  440. }); // module: browser/path.js
  441. require.register("browser/progress.js", function(module, exports, require){
  442. /**
  443. * Expose `Progress`.
  444. */
  445. module.exports = Progress;
  446. /**
  447. * Initialize a new `Progress` indicator.
  448. */
  449. function Progress() {
  450. this.percent = 0;
  451. this.size(0);
  452. this.fontSize(11);
  453. this.font('helvetica, arial, sans-serif');
  454. }
  455. /**
  456. * Set progress size to `n`.
  457. *
  458. * @param {Number} n
  459. * @return {Progress} for chaining
  460. * @api public
  461. */
  462. Progress.prototype.size = function(n){
  463. this._size = n;
  464. return this;
  465. };
  466. /**
  467. * Set text to `str`.
  468. *
  469. * @param {String} str
  470. * @return {Progress} for chaining
  471. * @api public
  472. */
  473. Progress.prototype.text = function(str){
  474. this._text = str;
  475. return this;
  476. };
  477. /**
  478. * Set font size to `n`.
  479. *
  480. * @param {Number} n
  481. * @return {Progress} for chaining
  482. * @api public
  483. */
  484. Progress.prototype.fontSize = function(n){
  485. this._fontSize = n;
  486. return this;
  487. };
  488. /**
  489. * Set font `family`.
  490. *
  491. * @param {String} family
  492. * @return {Progress} for chaining
  493. */
  494. Progress.prototype.font = function(family){
  495. this._font = family;
  496. return this;
  497. };
  498. /**
  499. * Update percentage to `n`.
  500. *
  501. * @param {Number} n
  502. * @return {Progress} for chaining
  503. */
  504. Progress.prototype.update = function(n){
  505. this.percent = n;
  506. return this;
  507. };
  508. /**
  509. * Draw on `ctx`.
  510. *
  511. * @param {CanvasRenderingContext2d} ctx
  512. * @return {Progress} for chaining
  513. */
  514. Progress.prototype.draw = function(ctx){
  515. var percent = Math.min(this.percent, 100)
  516. , size = this._size
  517. , half = size / 2
  518. , x = half
  519. , y = half
  520. , rad = half - 1
  521. , fontSize = this._fontSize;
  522. ctx.font = fontSize + 'px ' + this._font;
  523. var angle = Math.PI * 2 * (percent / 100);
  524. ctx.clearRect(0, 0, size, size);
  525. // outer circle
  526. ctx.strokeStyle = '#9f9f9f';
  527. ctx.beginPath();
  528. ctx.arc(x, y, rad, 0, angle, false);
  529. ctx.stroke();
  530. // inner circle
  531. ctx.strokeStyle = '#eee';
  532. ctx.beginPath();
  533. ctx.arc(x, y, rad - 1, 0, angle, true);
  534. ctx.stroke();
  535. // text
  536. var text = this._text || (percent | 0) + '%'
  537. , w = ctx.measureText(text).width;
  538. ctx.fillText(
  539. text
  540. , x - w / 2 + 1
  541. , y + fontSize / 2 - 1);
  542. return this;
  543. };
  544. }); // module: browser/progress.js
  545. require.register("browser/tty.js", function(module, exports, require){
  546. exports.isatty = function(){
  547. return true;
  548. };
  549. exports.getWindowSize = function(){
  550. return [window.innerHeight, window.innerWidth];
  551. };
  552. }); // module: browser/tty.js
  553. require.register("context.js", function(module, exports, require){
  554. /**
  555. * Expose `Context`.
  556. */
  557. module.exports = Context;
  558. /**
  559. * Initialize a new `Context`.
  560. *
  561. * @api private
  562. */
  563. function Context(){}
  564. /**
  565. * Set or get the context `Runnable` to `runnable`.
  566. *
  567. * @param {Runnable} runnable
  568. * @return {Context}
  569. * @api private
  570. */
  571. Context.prototype.runnable = function(runnable){
  572. if (0 == arguments.length) return this._runnable;
  573. this.test = this._runnable = runnable;
  574. return this;
  575. };
  576. /**
  577. * Set test timeout `ms`.
  578. *
  579. * @param {Number} ms
  580. * @return {Context} self
  581. * @api private
  582. */
  583. Context.prototype.timeout = function(ms){
  584. this.runnable().timeout(ms);
  585. return this;
  586. };
  587. /**
  588. * Set test slowness threshold `ms`.
  589. *
  590. * @param {Number} ms
  591. * @return {Context} self
  592. * @api private
  593. */
  594. Context.prototype.slow = function(ms){
  595. this.runnable().slow(ms);
  596. return this;
  597. };
  598. /**
  599. * Inspect the context void of `._runnable`.
  600. *
  601. * @return {String}
  602. * @api private
  603. */
  604. Context.prototype.inspect = function(){
  605. return JSON.stringify(this, function(key, val){
  606. if ('_runnable' == key) return;
  607. if ('test' == key) return;
  608. return val;
  609. }, 2);
  610. };
  611. }); // module: context.js
  612. require.register("hook.js", function(module, exports, require){
  613. /**
  614. * Module dependencies.
  615. */
  616. var Runnable = require('./runnable');
  617. /**
  618. * Expose `Hook`.
  619. */
  620. module.exports = Hook;
  621. /**
  622. * Initialize a new `Hook` with the given `title` and callback `fn`.
  623. *
  624. * @param {String} title
  625. * @param {Function} fn
  626. * @api private
  627. */
  628. function Hook(title, fn) {
  629. Runnable.call(this, title, fn);
  630. this.type = 'hook';
  631. }
  632. /**
  633. * Inherit from `Runnable.prototype`.
  634. */
  635. function F(){};
  636. F.prototype = Runnable.prototype;
  637. Hook.prototype = new F;
  638. Hook.prototype.constructor = Hook;
  639. /**
  640. * Get or set the test `err`.
  641. *
  642. * @param {Error} err
  643. * @return {Error}
  644. * @api public
  645. */
  646. Hook.prototype.error = function(err){
  647. if (0 == arguments.length) {
  648. var err = this._error;
  649. this._error = null;
  650. return err;
  651. }
  652. this._error = err;
  653. };
  654. }); // module: hook.js
  655. require.register("interfaces/bdd.js", function(module, exports, require){
  656. /**
  657. * Module dependencies.
  658. */
  659. var Suite = require('../suite')
  660. , Test = require('../test');
  661. /**
  662. * BDD-style interface:
  663. *
  664. * describe('Array', function(){
  665. * describe('#indexOf()', function(){
  666. * it('should return -1 when not present', function(){
  667. *
  668. * });
  669. *
  670. * it('should return the index when present', function(){
  671. *
  672. * });
  673. * });
  674. * });
  675. *
  676. */
  677. module.exports = function(suite){
  678. var suites = [suite];
  679. suite.on('pre-require', function(context, file, mocha){
  680. /**
  681. * Execute before running tests.
  682. */
  683. context.before = function(fn){
  684. suites[0].beforeAll(fn);
  685. };
  686. /**
  687. * Execute after running tests.
  688. */
  689. context.after = function(fn){
  690. suites[0].afterAll(fn);
  691. };
  692. /**
  693. * Execute before each test case.
  694. */
  695. context.beforeEach = function(fn){
  696. suites[0].beforeEach(fn);
  697. };
  698. /**
  699. * Execute after each test case.
  700. */
  701. context.afterEach = function(fn){
  702. suites[0].afterEach(fn);
  703. };
  704. /**
  705. * Describe a "suite" with the given `title`
  706. * and callback `fn` containing nested suites
  707. * and/or tests.
  708. */
  709. context.describe = context.context = function(title, fn){
  710. var suite = Suite.create(suites[0], title);
  711. suites.unshift(suite);
  712. fn.call(suite);
  713. suites.shift();
  714. return suite;
  715. };
  716. /**
  717. * Pending describe.
  718. */
  719. context.xdescribe =
  720. context.xcontext =
  721. context.describe.skip = function(title, fn){
  722. var suite = Suite.create(suites[0], title);
  723. suite.pending = true;
  724. suites.unshift(suite);
  725. fn.call(suite);
  726. suites.shift();
  727. };
  728. /**
  729. * Exclusive suite.
  730. */
  731. context.describe.only = function(title, fn){
  732. var suite = context.describe(title, fn);
  733. mocha.grep(suite.fullTitle());
  734. };
  735. /**
  736. * Describe a specification or test-case
  737. * with the given `title` and callback `fn`
  738. * acting as a thunk.
  739. */
  740. context.it = context.specify = function(title, fn){
  741. var suite = suites[0];
  742. if (suite.pending) var fn = null;
  743. var test = new Test(title, fn);
  744. suite.addTest(test);
  745. return test;
  746. };
  747. /**
  748. * Exclusive test-case.
  749. */
  750. context.it.only = function(title, fn){
  751. var test = context.it(title, fn);
  752. mocha.grep(test.fullTitle());
  753. };
  754. /**
  755. * Pending test case.
  756. */
  757. context.xit =
  758. context.xspecify =
  759. context.it.skip = function(title){
  760. context.it(title);
  761. };
  762. });
  763. };
  764. }); // module: interfaces/bdd.js
  765. require.register("interfaces/exports.js", function(module, exports, require){
  766. /**
  767. * Module dependencies.
  768. */
  769. var Suite = require('../suite')
  770. , Test = require('../test');
  771. /**
  772. * TDD-style interface:
  773. *
  774. * exports.Array = {
  775. * '#indexOf()': {
  776. * 'should return -1 when the value is not present': function(){
  777. *
  778. * },
  779. *
  780. * 'should return the correct index when the value is present': function(){
  781. *
  782. * }
  783. * }
  784. * };
  785. *
  786. */
  787. module.exports = function(suite){
  788. var suites = [suite];
  789. suite.on('require', visit);
  790. function visit(obj) {
  791. var suite;
  792. for (var key in obj) {
  793. if ('function' == typeof obj[key]) {
  794. var fn = obj[key];
  795. switch (key) {
  796. case 'before':
  797. suites[0].beforeAll(fn);
  798. break;
  799. case 'after':
  800. suites[0].afterAll(fn);
  801. break;
  802. case 'beforeEach':
  803. suites[0].beforeEach(fn);
  804. break;
  805. case 'afterEach':
  806. suites[0].afterEach(fn);
  807. break;
  808. default:
  809. suites[0].addTest(new Test(key, fn));
  810. }
  811. } else {
  812. var suite = Suite.create(suites[0], key);
  813. suites.unshift(suite);
  814. visit(obj[key]);
  815. suites.shift();
  816. }
  817. }
  818. }
  819. };
  820. }); // module: interfaces/exports.js
  821. require.register("interfaces/index.js", function(module, exports, require){
  822. exports.bdd = require('./bdd');
  823. exports.tdd = require('./tdd');
  824. exports.qunit = require('./qunit');
  825. exports.exports = require('./exports');
  826. }); // module: interfaces/index.js
  827. require.register("interfaces/qunit.js", function(module, exports, require){
  828. /**
  829. * Module dependencies.
  830. */
  831. var Suite = require('../suite')
  832. , Test = require('../test');
  833. /**
  834. * QUnit-style interface:
  835. *
  836. * suite('Array');
  837. *
  838. * test('#length', function(){
  839. * var arr = [1,2,3];
  840. * ok(arr.length == 3);
  841. * });
  842. *
  843. * test('#indexOf()', function(){
  844. * var arr = [1,2,3];
  845. * ok(arr.indexOf(1) == 0);
  846. * ok(arr.indexOf(2) == 1);
  847. * ok(arr.indexOf(3) == 2);
  848. * });
  849. *
  850. * suite('String');
  851. *
  852. * test('#length', function(){
  853. * ok('foo'.length == 3);
  854. * });
  855. *
  856. */
  857. module.exports = function(suite){
  858. var suites = [suite];
  859. suite.on('pre-require', function(context){
  860. /**
  861. * Execute before running tests.
  862. */
  863. context.before = function(fn){
  864. suites[0].beforeAll(fn);
  865. };
  866. /**
  867. * Execute after running tests.
  868. */
  869. context.after = function(fn){
  870. suites[0].afterAll(fn);
  871. };
  872. /**
  873. * Execute before each test case.
  874. */
  875. context.beforeEach = function(fn){
  876. suites[0].beforeEach(fn);
  877. };
  878. /**
  879. * Execute after each test case.
  880. */
  881. context.afterEach = function(fn){
  882. suites[0].afterEach(fn);
  883. };
  884. /**
  885. * Describe a "suite" with the given `title`.
  886. */
  887. context.suite = function(title){
  888. if (suites.length > 1) suites.shift();
  889. var suite = Suite.create(suites[0], title);
  890. suites.unshift(suite);
  891. };
  892. /**
  893. * Describe a specification or test-case
  894. * with the given `title` and callback `fn`
  895. * acting as a thunk.
  896. */
  897. context.test = function(title, fn){
  898. suites[0].addTest(new Test(title, fn));
  899. };
  900. });
  901. };
  902. }); // module: interfaces/qunit.js
  903. require.register("interfaces/tdd.js", function(module, exports, require){
  904. /**
  905. * Module dependencies.
  906. */
  907. var Suite = require('../suite')
  908. , Test = require('../test');
  909. /**
  910. * TDD-style interface:
  911. *
  912. * suite('Array', function(){
  913. * suite('#indexOf()', function(){
  914. * suiteSetup(function(){
  915. *
  916. * });
  917. *
  918. * test('should return -1 when not present', function(){
  919. *
  920. * });
  921. *
  922. * test('should return the index when present', function(){
  923. *
  924. * });
  925. *
  926. * suiteTeardown(function(){
  927. *
  928. * });
  929. * });
  930. * });
  931. *
  932. */
  933. module.exports = function(suite){
  934. var suites = [suite];
  935. suite.on('pre-require', function(context, file, mocha){
  936. /**
  937. * Execute before each test case.
  938. */
  939. context.setup = function(fn){
  940. suites[0].beforeEach(fn);
  941. };
  942. /**
  943. * Execute after each test case.
  944. */
  945. context.teardown = function(fn){
  946. suites[0].afterEach(fn);
  947. };
  948. /**
  949. * Execute before the suite.
  950. */
  951. context.suiteSetup = function(fn){
  952. suites[0].beforeAll(fn);
  953. };
  954. /**
  955. * Execute after the suite.
  956. */
  957. context.suiteTeardown = function(fn){
  958. suites[0].afterAll(fn);
  959. };
  960. /**
  961. * Describe a "suite" with the given `title`
  962. * and callback `fn` containing nested suites
  963. * and/or tests.
  964. */
  965. context.suite = function(title, fn){
  966. var suite = Suite.create(suites[0], title);
  967. suites.unshift(suite);
  968. fn.call(suite);
  969. suites.shift();
  970. return suite;
  971. };
  972. /**
  973. * Exclusive test-case.
  974. */
  975. context.suite.only = function(title, fn){
  976. var suite = context.suite(title, fn);
  977. mocha.grep(suite.fullTitle());
  978. };
  979. /**
  980. * Describe a specification or test-case
  981. * with the given `title` and callback `fn`
  982. * acting as a thunk.
  983. */
  984. context.test = function(title, fn){
  985. var test = new Test(title, fn);
  986. suites[0].addTest(test);
  987. return test;
  988. };
  989. /**
  990. * Exclusive test-case.
  991. */
  992. context.test.only = function(title, fn){
  993. var test = context.test(title, fn);
  994. mocha.grep(test.fullTitle());
  995. };
  996. /**
  997. * Pending test case.
  998. */
  999. context.test.skip = function(title){
  1000. context.test(title);
  1001. };
  1002. });
  1003. };
  1004. }); // module: interfaces/tdd.js
  1005. require.register("mocha.js", function(module, exports, require){
  1006. /*!
  1007. * mocha
  1008. * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
  1009. * MIT Licensed
  1010. */
  1011. /**
  1012. * Module dependencies.
  1013. */
  1014. var path = require('browser/path')
  1015. , utils = require('./utils');
  1016. /**
  1017. * Expose `Mocha`.
  1018. */
  1019. exports = module.exports = Mocha;
  1020. /**
  1021. * Expose internals.
  1022. */
  1023. exports.utils = utils;
  1024. exports.interfaces = require('./interfaces');
  1025. exports.reporters = require('./reporters');
  1026. exports.Runnable = require('./runnable');
  1027. exports.Context = require('./context');
  1028. exports.Runner = require('./runner');
  1029. exports.Suite = require('./suite');
  1030. exports.Hook = require('./hook');
  1031. exports.Test = require('./test');
  1032. /**
  1033. * Return image `name` path.
  1034. *
  1035. * @param {String} name
  1036. * @return {String}
  1037. * @api private
  1038. */
  1039. function image(name) {
  1040. return __dirname + '/../images/' + name + '.png';
  1041. }
  1042. /**
  1043. * Setup mocha with `options`.
  1044. *
  1045. * Options:
  1046. *
  1047. * - `ui` name "bdd", "tdd", "exports" etc
  1048. * - `reporter` reporter instance, defaults to `mocha.reporters.Dot`
  1049. * - `globals` array of accepted globals
  1050. * - `timeout` timeout in milliseconds
  1051. * - `bail` bail on the first test failure
  1052. * - `slow` milliseconds to wait before considering a test slow
  1053. * - `ignoreLeaks` ignore global leaks
  1054. * - `grep` string or regexp to filter tests with
  1055. *
  1056. * @param {Object} options
  1057. * @api public
  1058. */
  1059. function Mocha(options) {
  1060. options = options || {};
  1061. this.files = [];
  1062. this.options = options;
  1063. this.grep(options.grep);
  1064. this.suite = new exports.Suite('', new exports.Context);
  1065. this.ui(options.ui);
  1066. this.bail(options.bail);
  1067. this.reporter(options.reporter);
  1068. if (options.timeout) this.timeout(options.timeout);
  1069. if (options.slow) this.slow(options.slow);
  1070. }
  1071. /**
  1072. * Enable or disable bailing on the first failure.
  1073. *
  1074. * @param {Boolean} [bail]
  1075. * @api public
  1076. */
  1077. Mocha.prototype.bail = function(bail){
  1078. if (0 == arguments.length) bail = true;
  1079. this.suite.bail(bail);
  1080. return this;
  1081. };
  1082. /**
  1083. * Add test `file`.
  1084. *
  1085. * @param {String} file
  1086. * @api public
  1087. */
  1088. Mocha.prototype.addFile = function(file){
  1089. this.files.push(file);
  1090. return this;
  1091. };
  1092. /**
  1093. * Set reporter to `reporter`, defaults to "dot".
  1094. *
  1095. * @param {String|Function} reporter name or constructor
  1096. * @api public
  1097. */
  1098. Mocha.prototype.reporter = function(reporter){
  1099. if ('function' == typeof reporter) {
  1100. this._reporter = reporter;
  1101. } else {
  1102. reporter = reporter || 'dot';
  1103. try {
  1104. this._reporter = require('./reporters/' + reporter);
  1105. } catch (err) {
  1106. this._reporter = require(reporter);
  1107. }
  1108. if (!this._reporter) throw new Error('invalid reporter "' + reporter + '"');
  1109. }
  1110. return this;
  1111. };
  1112. /**
  1113. * Set test UI `name`, defaults to "bdd".
  1114. *
  1115. * @param {String} bdd
  1116. * @api public
  1117. */
  1118. Mocha.prototype.ui = function(name){
  1119. name = name || 'bdd';
  1120. this._ui = exports.interfaces[name];
  1121. if (!this._ui) throw new Error('invalid interface "' + name + '"');
  1122. this._ui = this._ui(this.suite);
  1123. return this;
  1124. };
  1125. /**
  1126. * Load registered files.
  1127. *
  1128. * @api private
  1129. */
  1130. Mocha.prototype.loadFiles = function(fn){
  1131. var self = this;
  1132. var suite = this.suite;
  1133. var pending = this.files.length;
  1134. this.files.forEach(function(file){
  1135. file = path.resolve(file);
  1136. suite.emit('pre-require', global, file, self);
  1137. suite.emit('require', require(file), file, self);
  1138. suite.emit('post-require', global, file, self);
  1139. --pending || (fn && fn());
  1140. });
  1141. };
  1142. /**
  1143. * Enable growl support.
  1144. *
  1145. * @api private
  1146. */
  1147. Mocha.prototype._growl = function(runner, reporter) {
  1148. var notify = require('growl');
  1149. runner.on('end', function(){
  1150. var stats = reporter.stats;
  1151. if (stats.failures) {
  1152. var msg = stats.failures + ' of ' + runner.total + ' tests failed';
  1153. notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
  1154. } else {
  1155. notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
  1156. name: 'mocha'
  1157. , title: 'Passed'
  1158. , image: image('ok')
  1159. });
  1160. }
  1161. });
  1162. };
  1163. /**
  1164. * Add regexp to grep, if `re` is a string it is escaped.
  1165. *
  1166. * @param {RegExp|String} re
  1167. * @return {Mocha}
  1168. * @api public
  1169. */
  1170. Mocha.prototype.grep = function(re){
  1171. this.options.grep = 'string' == typeof re
  1172. ? new RegExp(utils.escapeRegexp(re))
  1173. : re;
  1174. return this;
  1175. };
  1176. /**
  1177. * Invert `.grep()` matches.
  1178. *
  1179. * @return {Mocha}
  1180. * @api public
  1181. */
  1182. Mocha.prototype.invert = function(){
  1183. this.options.invert = true;
  1184. return this;
  1185. };
  1186. /**
  1187. * Ignore global leaks.
  1188. *
  1189. * @return {Mocha}
  1190. * @api public
  1191. */
  1192. Mocha.prototype.ignoreLeaks = function(){
  1193. this.options.ignoreLeaks = true;
  1194. return this;
  1195. };
  1196. /**
  1197. * Enable global leak checking.
  1198. *
  1199. * @return {Mocha}
  1200. * @api public
  1201. */
  1202. Mocha.prototype.checkLeaks = function(){
  1203. this.options.ignoreLeaks = false;
  1204. return this;
  1205. };
  1206. /**
  1207. * Enable growl support.
  1208. *
  1209. * @return {Mocha}
  1210. * @api public
  1211. */
  1212. Mocha.prototype.growl = function(){
  1213. this.options.growl = true;
  1214. return this;
  1215. };
  1216. /**
  1217. * Ignore `globals` array or string.
  1218. *
  1219. * @param {Array|String} globals
  1220. * @return {Mocha}
  1221. * @api public
  1222. */
  1223. Mocha.prototype.globals = function(globals){
  1224. this.options.globals = (this.options.globals || []).concat(globals);
  1225. return this;
  1226. };
  1227. /**
  1228. * Set the timeout in milliseconds.
  1229. *
  1230. * @param {Number} timeout
  1231. * @return {Mocha}
  1232. * @api public
  1233. */
  1234. Mocha.prototype.timeout = function(timeout){
  1235. this.suite.timeout(timeout);
  1236. return this;
  1237. };
  1238. /**
  1239. * Set slowness threshold in milliseconds.
  1240. *
  1241. * @param {Number} slow
  1242. * @return {Mocha}
  1243. * @api public
  1244. */
  1245. Mocha.prototype.slow = function(slow){
  1246. this.suite.slow(slow);
  1247. return this;
  1248. };
  1249. /**
  1250. * Makes all tests async (accepting a callback)
  1251. *
  1252. * @return {Mocha}
  1253. * @api public
  1254. */
  1255. Mocha.prototype.asyncOnly = function(){
  1256. this.options.asyncOnly = true;
  1257. return this;
  1258. };
  1259. /**
  1260. * Run tests and invoke `fn()` when complete.
  1261. *
  1262. * @param {Function} fn
  1263. * @return {Runner}
  1264. * @api public
  1265. */
  1266. Mocha.prototype.run = function(fn){
  1267. if (this.files.length) this.loadFiles();
  1268. var suite = this.suite;
  1269. var options = this.options;
  1270. var runner = new exports.Runner(suite);
  1271. var reporter = new this._reporter(runner);
  1272. runner.ignoreLeaks = options.ignoreLeaks;
  1273. runner.asyncOnly = options.asyncOnly;
  1274. if (options.grep) runner.grep(options.grep, options.invert);
  1275. if (options.globals) runner.globals(options.globals);
  1276. if (options.growl) this._growl(runner, reporter);
  1277. return runner.run(fn);
  1278. };
  1279. }); // module: mocha.js
  1280. require.register("ms.js", function(module, exports, require){
  1281. /**
  1282. * Helpers.
  1283. */
  1284. var s = 1000;
  1285. var m = s * 60;
  1286. var h = m * 60;
  1287. var d = h * 24;
  1288. /**
  1289. * Parse or format the given `val`.
  1290. *
  1291. * @param {String|Number} val
  1292. * @return {String|Number}
  1293. * @api public
  1294. */
  1295. module.exports = function(val){
  1296. if ('string' == typeof val) return parse(val);
  1297. return format(val);
  1298. }
  1299. /**
  1300. * Parse the given `str` and return milliseconds.
  1301. *
  1302. * @param {String} str
  1303. * @return {Number}
  1304. * @api private
  1305. */
  1306. function parse(str) {
  1307. var m = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str);
  1308. if (!m) return;
  1309. var n = parseFloat(m[1]);
  1310. var type = (m[2] || 'ms').toLowerCase();
  1311. switch (type) {
  1312. case 'years':
  1313. case 'year':
  1314. case 'y':
  1315. return n * 31557600000;
  1316. case 'days':
  1317. case 'day':
  1318. case 'd':
  1319. return n * 86400000;
  1320. case 'hours':
  1321. case 'hour':
  1322. case 'h':
  1323. return n * 3600000;
  1324. case 'minutes':
  1325. case 'minute':
  1326. case 'm':
  1327. return n * 60000;
  1328. case 'seconds':
  1329. case 'second':
  1330. case 's':
  1331. return n * 1000;
  1332. case 'ms':
  1333. return n;
  1334. }
  1335. }
  1336. /**
  1337. * Format the given `ms`.
  1338. *
  1339. * @param {Number} ms
  1340. * @return {String}
  1341. * @api public
  1342. */
  1343. function format(ms) {
  1344. if (ms == d) return Math.round(ms / d) + ' day';
  1345. if (ms > d) return Math.round(ms / d) + ' days';
  1346. if (ms == h) return Math.round(ms / h) + ' hour';
  1347. if (ms > h) return Math.round(ms / h) + ' hours';
  1348. if (ms == m) return Math.round(ms / m) + ' minute';
  1349. if (ms > m) return Math.round(ms / m) + ' minutes';
  1350. if (ms == s) return Math.round(ms / s) + ' second';
  1351. if (ms > s) return Math.round(ms / s) + ' seconds';
  1352. return ms + ' ms';
  1353. }
  1354. }); // module: ms.js
  1355. require.register("reporters/base.js", function(module, exports, require){
  1356. /**
  1357. * Module dependencies.
  1358. */
  1359. var tty = require('browser/tty')
  1360. , diff = require('browser/diff')
  1361. , ms = require('../ms');
  1362. /**
  1363. * Save timer references to avoid Sinon interfering (see GH-237).
  1364. */
  1365. var Date = global.Date
  1366. , setTimeout = global.setTimeout
  1367. , setInterval = global.setInterval
  1368. , clearTimeout = global.clearTimeout
  1369. , clearInterval = global.clearInterval;
  1370. /**
  1371. * Check if both stdio streams are associated with a tty.
  1372. */
  1373. var isatty = tty.isatty(1) && tty.isatty(2);
  1374. /**
  1375. * Expose `Base`.
  1376. */
  1377. exports = module.exports = Base;
  1378. /**
  1379. * Enable coloring by default.
  1380. */
  1381. exports.useColors = isatty;
  1382. /**
  1383. * Default color map.
  1384. */
  1385. exports.colors = {
  1386. 'pass': 90
  1387. , 'fail': 31
  1388. , 'bright pass': 92
  1389. , 'bright fail': 91
  1390. , 'bright yellow': 93
  1391. , 'pending': 36
  1392. , 'suite': 0
  1393. , 'error title': 0
  1394. , 'error message': 31
  1395. , 'error stack': 90
  1396. , 'checkmark': 32
  1397. , 'fast': 90
  1398. , 'medium': 33
  1399. , 'slow': 31
  1400. , 'green': 32
  1401. , 'light': 90
  1402. , 'diff gutter': 90
  1403. , 'diff added': 42
  1404. , 'diff removed': 41
  1405. };
  1406. /**
  1407. * Default symbol map.
  1408. */
  1409. exports.symbols = {
  1410. ok: '✓',
  1411. err: '✖',
  1412. dot: '․'
  1413. };
  1414. // With node.js on Windows: use symbols available in terminal default fonts
  1415. if ('win32' == process.platform) {
  1416. exports.symbols.ok = '\u221A';
  1417. exports.symbols.err = '\u00D7';
  1418. exports.symbols.dot = '.';
  1419. }
  1420. /**
  1421. * Color `str` with the given `type`,
  1422. * allowing colors to be disabled,
  1423. * as well as user-defined color
  1424. * schemes.
  1425. *
  1426. * @param {String} type
  1427. * @param {String} str
  1428. * @return {String}
  1429. * @api private
  1430. */
  1431. var color = exports.color = function(type, str) {
  1432. if (!exports.useColors) return str;
  1433. return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
  1434. };
  1435. /**
  1436. * Expose term window size, with some
  1437. * defaults for when stderr is not a tty.
  1438. */
  1439. exports.window = {
  1440. width: isatty
  1441. ? process.stdout.getWindowSize
  1442. ? process.stdout.getWindowSize(1)[0]
  1443. : tty.getWindowSize()[1]
  1444. : 75
  1445. };
  1446. /**
  1447. * Expose some basic cursor interactions
  1448. * that are common among reporters.
  1449. */
  1450. exports.cursor = {
  1451. hide: function(){
  1452. process.stdout.write('\u001b[?25l');
  1453. },
  1454. show: function(){
  1455. process.stdout.write('\u001b[?25h');
  1456. },
  1457. deleteLine: function(){
  1458. process.stdout.write('\u001b[2K');
  1459. },
  1460. beginningOfLine: function(){
  1461. process.stdout.write('\u001b[0G');
  1462. },
  1463. CR: function(){
  1464. exports.cursor.deleteLine();
  1465. exports.cursor.beginningOfLine();
  1466. }
  1467. };
  1468. /**
  1469. * Outut the given `failures` as a list.
  1470. *
  1471. * @param {Array} failures
  1472. * @api public
  1473. */
  1474. exports.list = function(failures){
  1475. console.error();
  1476. failures.forEach(function(test, i){
  1477. // format
  1478. var fmt = color('error title', ' %s) %s:\n')
  1479. + color('error message', ' %s')
  1480. + color('error stack', '\n%s\n');
  1481. // msg
  1482. var err = test.err
  1483. , message = err.message || ''
  1484. , stack = err.stack || message
  1485. , index = stack.indexOf(message) + message.length
  1486. , msg = stack.slice(0, index)
  1487. , actual = err.actual
  1488. , expected = err.expected
  1489. , escape = true;
  1490. // explicitly show diff
  1491. if (err.showDiff) {
  1492. escape = false;
  1493. err.actual = actual = JSON.stringify(actual, null, 2);
  1494. err.expected = expected = JSON.stringify(expected, null, 2);
  1495. }
  1496. // actual / expected diff
  1497. if ('string' == typeof actual && 'string' == typeof expected) {
  1498. var len = Math.max(actual.length, expected.length);
  1499. if (len < 20) msg = errorDiff(err, 'Chars', escape);
  1500. else msg = errorDiff(err, 'Words', escape);
  1501. // linenos
  1502. var lines = msg.split('\n');
  1503. if (lines.length > 4) {
  1504. var width = String(lines.length).length;
  1505. msg = lines.map(function(str, i){
  1506. return pad(++i, width) + ' |' + ' ' + str;
  1507. }).join('\n');
  1508. }
  1509. // legend
  1510. msg = '\n'
  1511. + color('diff removed', 'actual')
  1512. + ' '
  1513. + color('diff added', 'expected')
  1514. + '\n\n'
  1515. + msg
  1516. + '\n';
  1517. // indent
  1518. msg = msg.replace(/^/gm, ' ');
  1519. fmt = color('error title', ' %s) %s:\n%s')
  1520. + color('error stack', '\n%s\n');
  1521. }
  1522. // indent stack trace without msg
  1523. stack = stack.slice(index ? index + 1 : index)
  1524. .replace(/^/gm, ' ');
  1525. console.error(fmt, (i + 1), test.fullTitle(), msg, stack);
  1526. });
  1527. };
  1528. /**
  1529. * Initialize a new `Base` reporter.
  1530. *
  1531. * All other reporters generally
  1532. * inherit from this reporter, providing
  1533. * stats such as test duration, number
  1534. * of tests passed / failed etc.
  1535. *
  1536. * @param {Runner} runner
  1537. * @api public
  1538. */
  1539. function Base(runner) {
  1540. var self = this
  1541. , stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
  1542. , failures = this.failures = [];
  1543. if (!runner) return;
  1544. this.runner = runner;
  1545. runner.stats = stats;
  1546. runner.on('start', function(){
  1547. stats.start = new Date;
  1548. });
  1549. runner.on('suite', function(suite){
  1550. stats.suites = stats.suites || 0;
  1551. suite.root || stats.suites++;
  1552. });
  1553. runner.on('test end', function(test){
  1554. stats.tests = stats.tests || 0;
  1555. stats.tests++;
  1556. });
  1557. runner.on('pass', function(test){
  1558. stats.passes = stats.passes || 0;
  1559. var medium = test.slow() / 2;
  1560. test.speed = test.duration > test.slow()
  1561. ? 'slow'
  1562. : test.duration > medium
  1563. ? 'medium'
  1564. : 'fast';
  1565. stats.passes++;
  1566. });
  1567. runner.on('fail', function(test, err){
  1568. stats.failures = stats.failures || 0;
  1569. stats.failures++;
  1570. test.err = err;
  1571. failures.push(test);
  1572. });
  1573. runner.on('end', function(){
  1574. stats.end = new Date;
  1575. stats.duration = new Date - stats.start;
  1576. });
  1577. runner.on('pending', function(){
  1578. stats.pending++;
  1579. });
  1580. }
  1581. /**
  1582. * Output common epilogue used by many of
  1583. * the bundled reporters.
  1584. *
  1585. * @api public
  1586. */
  1587. Base.prototype.epilogue = function(){
  1588. var stats = this.stats
  1589. , fmt
  1590. , tests;
  1591. console.log();
  1592. function pluralize(n) {
  1593. return 1 == n ? 'test' : 'tests';
  1594. }
  1595. // failure
  1596. if (stats.failures) {
  1597. fmt = color('bright fail', ' ' + exports.symbols.err)
  1598. + color('fail', ' %d of %d %s failed')
  1599. + color('light', ':')
  1600. console.error(fmt,
  1601. stats.failures,
  1602. this.runner.total,
  1603. pluralize(this.runner.total));
  1604. Base.list(this.failures);
  1605. console.error();
  1606. return;
  1607. }
  1608. // pass
  1609. fmt = color('bright pass', ' ')
  1610. + color('green', ' %d %s complete')
  1611. + color('light', ' (%s)');
  1612. console.log(fmt,
  1613. stats.tests || 0,
  1614. pluralize(stats.tests),
  1615. ms(stats.duration));
  1616. // pending
  1617. if (stats.pending) {
  1618. fmt = color('pending', ' ')
  1619. + color('pending', ' %d %s pending');
  1620. console.log(fmt, stats.pending, pluralize(stats.pending));
  1621. }
  1622. console.log();
  1623. };
  1624. /**
  1625. * Pad the given `str` to `len`.
  1626. *
  1627. * @param {String} str
  1628. * @param {String} len
  1629. * @return {String}
  1630. * @api private
  1631. */
  1632. function pad(str, len) {
  1633. str = String(str);
  1634. return Array(len - str.length + 1).join(' ') + str;
  1635. }
  1636. /**
  1637. * Return a character diff for `err`.
  1638. *
  1639. * @param {Error} err
  1640. * @return {String}
  1641. * @api private
  1642. */
  1643. function errorDiff(err, type, escape) {
  1644. return diff['diff' + type](err.actual, err.expected).map(function(str){
  1645. if (escape) {
  1646. str.value = str.value
  1647. .replace(/\t/g, '<tab>')
  1648. .replace(/\r/g, '<CR>')
  1649. .replace(/\n/g, '<LF>\n');
  1650. }
  1651. if (str.added) return colorLines('diff added', str.value);
  1652. if (str.removed) return colorLines('diff removed', str.value);
  1653. return str.value;
  1654. }).join('');
  1655. }
  1656. /**
  1657. * Color lines for `str`, using the color `name`.
  1658. *
  1659. * @param {String} name
  1660. * @param {String} str
  1661. * @return {String}
  1662. * @api private
  1663. */
  1664. function colorLines(name, str) {
  1665. return str.split('\n').map(function(str){
  1666. return color(name, str);
  1667. }).join('\n');
  1668. }
  1669. }); // module: reporters/base.js
  1670. require.register("reporters/doc.js", function(module, exports, require){
  1671. /**
  1672. * Module dependencies.
  1673. */
  1674. var Base = require('./base')
  1675. , utils = require('../utils');
  1676. /**
  1677. * Expose `Doc`.
  1678. */
  1679. exports = module.exports = Doc;
  1680. /**
  1681. * Initialize a new `Doc` reporter.
  1682. *
  1683. * @param {Runner} runner
  1684. * @api public
  1685. */
  1686. function Doc(runner) {
  1687. Base.call(this, runner);
  1688. var self = this
  1689. , stats = this.stats
  1690. , total = runner.total
  1691. , indents = 2;
  1692. function indent() {
  1693. return Array(indents).join(' ');
  1694. }
  1695. runner.on('suite', function(suite){
  1696. if (suite.root) return;
  1697. ++indents;
  1698. console.log('%s<section class="suite">', indent());
  1699. ++indents;
  1700. console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
  1701. console.log('%s<dl>', indent());
  1702. });
  1703. runner.on('suite end', function(suite){
  1704. if (suite.root) return;
  1705. console.log('%s</dl>', indent());
  1706. --indents;
  1707. console.log('%s</section>', indent());
  1708. --indents;
  1709. });
  1710. runner.on('pass', function(test){
  1711. console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
  1712. var code = utils.escape(utils.clean(test.fn.toString()));
  1713. console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
  1714. });
  1715. }
  1716. }); // module: reporters/doc.js
  1717. require.register("reporters/dot.js", function(module, exports, require){
  1718. /**
  1719. * Module dependencies.
  1720. */
  1721. var Base = require('./base')
  1722. , color = Base.color;
  1723. /**
  1724. * Expose `Dot`.
  1725. */
  1726. exports = module.exports = Dot;
  1727. /**
  1728. * Initialize a new `Dot` matrix test reporter.
  1729. *
  1730. * @param {Runner} runner
  1731. * @api public
  1732. */
  1733. function Dot(runner) {
  1734. Base.call(this, runner);
  1735. var self = this
  1736. , stats = this.stats
  1737. , width = Base.window.width * .75 | 0
  1738. , n = 0;
  1739. runner.on('start', function(){
  1740. process.stdout.write('\n ');
  1741. });
  1742. runner.on('pending', function(test){
  1743. process.stdout.write(color('pending', Base.symbols.dot));
  1744. });
  1745. runner.on('pass', function(test){
  1746. if (++n % width == 0) process.stdout.write('\n ');
  1747. if ('slow' == test.speed) {
  1748. process.stdout.write(color('bright yellow', Base.symbols.dot));
  1749. } else {
  1750. process.stdout.write(color(test.speed, Base.symbols.dot));
  1751. }
  1752. });
  1753. runner.on('fail', function(test, err){
  1754. if (++n % width == 0) process.stdout.write('\n ');
  1755. process.stdout.write(color('fail', Base.symbols.dot));
  1756. });
  1757. runner.on('end', function(){
  1758. console.log();
  1759. self.epilogue();
  1760. });
  1761. }
  1762. /**
  1763. * Inherit from `Base.prototype`.
  1764. */
  1765. function F(){};
  1766. F.prototype = Base.prototype;
  1767. Dot.prototype = new F;
  1768. Dot.prototype.constructor = Dot;
  1769. }); // module: reporters/dot.js
  1770. require.register("reporters/html-cov.js", function(module, exports, require){
  1771. /**
  1772. * Module dependencies.
  1773. */
  1774. var JSONCov = require('./json-cov')
  1775. , fs = require('browser/fs');
  1776. /**
  1777. * Expose `HTMLCov`.
  1778. */
  1779. exports = module.exports = HTMLCov;
  1780. /**
  1781. * Initialize a new `JsCoverage` reporter.
  1782. *
  1783. * @param {Runner} runner
  1784. * @api public
  1785. */
  1786. function HTMLCov(runner) {
  1787. var jade = require('jade')
  1788. , file = __dirname + '/templates/coverage.jade'
  1789. , str = fs.readFileSync(file, 'utf8')
  1790. , fn = jade.compile(str, { filename: file })
  1791. , self = this;
  1792. JSONCov.call(this, runner, false);
  1793. runner.on('end', function(){
  1794. process.stdout.write(fn({
  1795. cov: self.cov
  1796. , coverageClass: coverageClass
  1797. }));
  1798. });
  1799. }
  1800. /**
  1801. * Return coverage class for `n`.
  1802. *
  1803. * @return {String}
  1804. * @api private
  1805. */
  1806. function coverageClass(n) {
  1807. if (n >= 75) return 'high';
  1808. if (n >= 50) return 'medium';
  1809. if (n >= 25) return 'low';
  1810. return 'terrible';
  1811. }
  1812. }); // module: reporters/html-cov.js
  1813. require.register("reporters/html.js", function(module, exports, require){
  1814. /**
  1815. * Module dependencies.
  1816. */
  1817. var Base = require('./base')
  1818. , utils = require('../utils')
  1819. , Progress = require('../browser/progress')
  1820. , escape = utils.escape;
  1821. /**
  1822. * Save timer references to avoid Sinon interfering (see GH-237).
  1823. */
  1824. var Date = global.Date
  1825. , setTimeout = global.setTimeout
  1826. , setInterval = global.setInterval
  1827. , clearTimeout = global.clearTimeout
  1828. , clearInterval = global.clearInterval;
  1829. /**
  1830. * Expose `Doc`.
  1831. */
  1832. exports = module.exports = HTML;
  1833. /**
  1834. * Stats template.
  1835. */
  1836. var statsTemplate = '<ul id="mocha-stats">'
  1837. + '<li class="progress"><canvas width="40" height="40"></canvas></li>'
  1838. + '<li class="passes"><a href="#">passes:</a> <em>0</em></li>'
  1839. + '<li class="failures"><a href="#">failures:</a> <em>0</em></li>'
  1840. + '<li class="duration">duration: <em>0</em>s</li>'
  1841. + '</ul>';
  1842. /**
  1843. * Initialize a new `Doc` reporter.
  1844. *
  1845. * @param {Runner} runner
  1846. * @api public
  1847. */
  1848. function HTML(runner, root) {
  1849. Base.call(this, runner);
  1850. var self = this
  1851. , stats = this.stats
  1852. , total = runner.total
  1853. , stat = fragment(statsTemplate)
  1854. , items = stat.getElementsByTagName('li')
  1855. , passes = items[1].getElementsByTagName('em')[0]
  1856. , passesLink = items[1].getElementsByTagName('a')[0]
  1857. , failures = items[2].getElementsByTagName('em')[0]
  1858. , failuresLink = items[2].getElementsByTagName('a')[0]
  1859. , duration = items[3].getElementsByTagName('em')[0]
  1860. , canvas = stat.getElementsByTagName('canvas')[0]
  1861. , report = fragment('<ul id="mocha-report"></ul>')
  1862. , stack = [report]
  1863. , progress
  1864. , ctx
  1865. root = root || document.getElementById('mocha');
  1866. if (canvas.getContext) {
  1867. var ratio = window.devicePixelRatio || 1;
  1868. canvas.style.width = canvas.width;
  1869. canvas.style.height = canvas.height;
  1870. canvas.width *= ratio;
  1871. canvas.height *= ratio;
  1872. ctx = canvas.getContext('2d');
  1873. ctx.scale(ratio, ratio);
  1874. progress = new Progress;
  1875. }
  1876. if (!root) return error('#mocha div missing, add it to your document');
  1877. // pass toggle
  1878. on(passesLink, 'click', function(){
  1879. unhide();
  1880. var name = /pass/.test(report.className) ? '' : ' pass';
  1881. report.className = report.className.replace(/fail|pass/g, '') + name;
  1882. if (report.className.trim()) hideSuitesWithout('test pass');
  1883. });
  1884. // failure toggle
  1885. on(failuresLink, 'click', function(){
  1886. unhide();
  1887. var name = /fail/.test(report.className) ? '' : ' fail';
  1888. report.className = report.className.replace(/fail|pass/g, '') + name;
  1889. if (report.className.trim()) hideSuitesWithout('test fail');
  1890. });
  1891. root.appendChild(stat);
  1892. root.appendChild(report);
  1893. if (progress) progress.size(40);
  1894. runner.on('suite', function(suite){
  1895. if (suite.root) return;
  1896. // suite
  1897. var url = '?grep=' + encodeURIComponent(suite.fullTitle());
  1898. var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
  1899. // container
  1900. stack[0].appendChild(el);
  1901. stack.unshift(document.createElement('ul'));
  1902. el.appendChild(stack[0]);
  1903. });
  1904. runner.on('suite end', function(suite){
  1905. if (suite.root) return;
  1906. stack.shift();
  1907. });
  1908. runner.on('fail', function(test, err){
  1909. if ('hook' == test.type) runner.emit('test end', test);
  1910. });
  1911. runner.on('test end', function(test){
  1912. window.scrollTo(0, document.body.scrollHeight);
  1913. // TODO: add to stats
  1914. var percent = stats.tests / this.total * 100 | 0;
  1915. if (progress) progress.update(percent).draw(ctx);
  1916. // update stats
  1917. var ms = new Date - stats.start;
  1918. text(passes, stats.passes);
  1919. text(failures, stats.failures);
  1920. text(duration, (ms / 1000).toFixed(2));
  1921. // test
  1922. if ('passed' == test.state) {
  1923. var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="?grep=%e" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, encodeURIComponent(test.fullTitle()));
  1924. } else if (test.pending) {
  1925. var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
  1926. } else {
  1927. var el = fragment('<li class="test fail"><h2>%e <a href="?grep=%e" class="replay">‣</a></h2></li>', test.title, encodeURIComponent(test.fullTitle()));
  1928. var str = test.err.stack || test.err.toString();
  1929. // FF / Opera do not add the message
  1930. if (!~str.indexOf(test.err.message)) {
  1931. str = test.err.message + '\n' + str;
  1932. }
  1933. // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
  1934. // check for the result of the stringifying.
  1935. if ('[object Error]' == str) str = test.err.message;
  1936. // Safari doesn't give you a stack. Let's at least provide a source line.
  1937. if (!test.err.stack && test.err.sourceURL && test.err.line !== undefined) {
  1938. str += "\n(" + test.err.sourceURL + ":" + test.err.line + ")";
  1939. }
  1940. el.appendChild(fragment('<pre class="error">%e</pre>', str));
  1941. }
  1942. // toggle code
  1943. // TODO: defer
  1944. if (!test.pending) {
  1945. var h2 = el.getElementsByTagName('h2')[0];
  1946. on(h2, 'click', function(){
  1947. pre.style.display = 'none' == pre.style.display
  1948. ? 'block'
  1949. : 'none';
  1950. });
  1951. var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.fn.toString()));
  1952. el.appendChild(pre);
  1953. pre.style.display = 'none';
  1954. }
  1955. // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
  1956. if (stack[0]) stack[0].appendChild(el);
  1957. });
  1958. }
  1959. /**
  1960. * Display error `msg`.
  1961. */
  1962. function error(msg) {
  1963. document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
  1964. }
  1965. /**
  1966. * Return a DOM fragment from `html`.
  1967. */
  1968. function fragment(html) {
  1969. var args = arguments
  1970. , div = document.createElement('div')
  1971. , i = 1;
  1972. div.innerHTML = html.replace(/%([se])/g, function(_, type){
  1973. switch (type) {
  1974. case 's': return String(args[i++]);
  1975. case 'e': return escape(args[i++]);
  1976. }
  1977. });
  1978. return div.firstChild;
  1979. }
  1980. /**
  1981. * Check for suites that do not have elements
  1982. * with `classname`, and hide them.
  1983. */
  1984. function hideSuitesWithout(classname) {
  1985. var suites = document.getElementsByClassName('suite');
  1986. for (var i = 0; i < suites.length; i++) {
  1987. var els = suites[i].getElementsByClassName(classname);
  1988. if (0 == els.length) suites[i].className += ' hidden';
  1989. }
  1990. }
  1991. /**
  1992. * Unhide .hidden suites.
  1993. */
  1994. function unhide() {
  1995. var els = document.getElementsByClassName('suite hidden');
  1996. for (var i = 0; i < els.length; ++i) {
  1997. els[i].className = els[i].className.replace('suite hidden', 'suite');
  1998. }
  1999. }
  2000. /**
  2001. * Set `el` text to `str`.
  2002. */
  2003. function text(el, str) {
  2004. if (el.textContent) {
  2005. el.textContent = str;
  2006. } else {
  2007. el.innerText = str;
  2008. }
  2009. }
  2010. /**
  2011. * Listen on `event` with callback `fn`.
  2012. */
  2013. function on(el, event, fn) {
  2014. if (el.addEventListener) {
  2015. el.addEventListener(event, fn, false);
  2016. } else {
  2017. el.attachEvent('on' + event, fn);
  2018. }
  2019. }
  2020. }); // module: reporters/html.js
  2021. require.register("reporters/index.js", function(module, exports, require){
  2022. exports.Base = require('./base');
  2023. exports.Dot = require('./dot');
  2024. exports.Doc = require('./doc');
  2025. exports.TAP = require('./tap');
  2026. exports.JSON = require('./json');
  2027. exports.HTML = require('./html');
  2028. exports.List = require('./list');
  2029. exports.Min = require('./min');
  2030. exports.Spec = require('./spec');
  2031. exports.Nyan = require('./nyan');
  2032. exports.XUnit = require('./xunit');
  2033. exports.Markdown = require('./markdown');
  2034. exports.Progress = require('./progress');
  2035. exports.Landing = require('./landing');
  2036. exports.JSONCov = require('./json-cov');
  2037. exports.HTMLCov = require('./html-cov');
  2038. exports.JSONStream = require('./json-stream');
  2039. exports.Teamcity = require('./teamcity');
  2040. }); // module: reporters/index.js
  2041. require.register("reporters/json-cov.js", function(module, exports, require){
  2042. /**
  2043. * Module dependencies.
  2044. */
  2045. var Base = require('./base');
  2046. /**
  2047. * Expose `JSONCov`.
  2048. */
  2049. exports = module.exports = JSONCov;
  2050. /**
  2051. * Initialize a new `JsCoverage` reporter.
  2052. *
  2053. * @param {Runner} runner
  2054. * @param {Boolean} output
  2055. * @api public
  2056. */
  2057. function JSONCov(runner, output) {
  2058. var self = this
  2059. , output = 1 == arguments.length ? true : output;
  2060. Base.call(this, runner);
  2061. var tests = []
  2062. , failures = []
  2063. , passes = [];
  2064. runner.on('test end', function(test){
  2065. tests.push(test);
  2066. });
  2067. runner.on('pass', function(test){
  2068. passes.push(test);
  2069. });
  2070. runner.on('fail', function(test){
  2071. failures.push(test);
  2072. });
  2073. runner.on('end', function(){
  2074. var cov = global._$jscoverage || {};
  2075. var result = self.cov = map(cov);
  2076. result.stats = self.stats;
  2077. result.tests = tests.map(clean);
  2078. result.failures = failures.map(clean);
  2079. result.passes = passes.map(clean);
  2080. if (!output) return;
  2081. process.stdout.write(JSON.stringify(result, null, 2 ));
  2082. });
  2083. }
  2084. /**
  2085. * Map jscoverage data to a JSON structure
  2086. * suitable for reporting.
  2087. *
  2088. * @param {Object} cov
  2089. * @return {Object}
  2090. * @api private
  2091. */
  2092. function map(cov) {
  2093. var ret = {
  2094. instrumentation: 'node-jscoverage'
  2095. , sloc: 0
  2096. , hits: 0
  2097. , misses: 0
  2098. , coverage: 0
  2099. , files: []
  2100. };
  2101. for (var filename in cov) {
  2102. var data = coverage(filename, cov[filename]);
  2103. ret.files.push(data);
  2104. ret.hits += data.hits;
  2105. ret.misses += data.misses;
  2106. ret.sloc += data.sloc;
  2107. }
  2108. ret.files.sort(function(a, b) {
  2109. return a.filename.localeCompare(b.filename);
  2110. });
  2111. if (ret.sloc > 0) {
  2112. ret.coverage = (ret.hits / ret.sloc) * 100;
  2113. }
  2114. return ret;
  2115. };
  2116. /**
  2117. * Map jscoverage data for a single source file
  2118. * to a JSON structure suitable for reporting.
  2119. *
  2120. * @param {String} filename name of the source file
  2121. * @param {Object} data jscoverage coverage data
  2122. * @return {Object}
  2123. * @api private
  2124. */
  2125. function coverage(filename, data) {
  2126. var ret = {
  2127. filename: filename,
  2128. coverage: 0,
  2129. hits: 0,
  2130. misses: 0,
  2131. sloc: 0,
  2132. source: {}
  2133. };
  2134. data.source.forEach(function(line, num){
  2135. num++;
  2136. if (data[num] === 0) {
  2137. ret.misses++;
  2138. ret.sloc++;
  2139. } else if (data[num] !== undefined) {
  2140. ret.hits++;
  2141. ret.sloc++;
  2142. }
  2143. ret.source[num] = {
  2144. source: line
  2145. , coverage: data[num] === undefined
  2146. ? ''
  2147. : data[num]
  2148. };
  2149. });
  2150. ret.coverage = ret.hits / ret.sloc * 100;
  2151. return ret;
  2152. }
  2153. /**
  2154. * Return a plain-object representation of `test`
  2155. * free of cyclic properties etc.
  2156. *
  2157. * @param {Object} test
  2158. * @return {Object}
  2159. * @api private
  2160. */
  2161. function clean(test) {
  2162. return {
  2163. title: test.title
  2164. , fullTitle: test.fullTitle()
  2165. , duration: test.duration
  2166. }
  2167. }
  2168. }); // module: reporters/json-cov.js
  2169. require.register("reporters/json-stream.js", function(module, exports, require){
  2170. /**
  2171. * Module dependencies.
  2172. */
  2173. var Base = require('./base')
  2174. , color = Base.color;
  2175. /**
  2176. * Expose `List`.
  2177. */
  2178. exports = module.exports = List;
  2179. /**
  2180. * Initialize a new `List` test reporter.
  2181. *
  2182. * @param {Runner} runner
  2183. * @api public
  2184. */
  2185. function List(runner) {
  2186. Base.call(this, runner);
  2187. var self = this
  2188. , stats = this.stats
  2189. , total = runner.total;
  2190. runner.on('start', function(){
  2191. console.log(JSON.stringify(['start', { total: total }]));
  2192. });
  2193. runner.on('pass', function(test){
  2194. console.log(JSON.stringify(['pass', clean(test)]));
  2195. });
  2196. runner.on('fail', function(test, err){
  2197. console.log(JSON.stringify(['fail', clean(test)]));
  2198. });
  2199. runner.on('end', function(){
  2200. process.stdout.write(JSON.stringify(['end', self.stats]));
  2201. });
  2202. }
  2203. /**
  2204. * Return a plain-object representation of `test`
  2205. * free of cyclic properties etc.
  2206. *
  2207. * @param {Object} test
  2208. * @return {Object}
  2209. * @api private
  2210. */
  2211. function clean(test) {
  2212. return {
  2213. title: test.title
  2214. , fullTitle: test.fullTitle()
  2215. , duration: test.duration
  2216. }
  2217. }
  2218. }); // module: reporters/json-stream.js
  2219. require.register("reporters/json.js", function(module, exports, require){
  2220. /**
  2221. * Module dependencies.
  2222. */
  2223. var Base = require('./base')
  2224. , cursor = Base.cursor
  2225. , color = Base.color;
  2226. /**
  2227. * Expose `JSON`.
  2228. */
  2229. exports = module.exports = JSONReporter;
  2230. /**
  2231. * Initialize a new `JSON` reporter.
  2232. *
  2233. * @param {Runner} runner
  2234. * @api public
  2235. */
  2236. function JSONReporter(runner) {
  2237. var self = this;
  2238. Base.call(this, runner);
  2239. var tests = []
  2240. , failures = []
  2241. , passes = [];
  2242. runner.on('test end', function(test){
  2243. tests.push(test);
  2244. });
  2245. runner.on('pass', function(test){
  2246. passes.push(test);
  2247. });
  2248. runner.on('fail', function(test){
  2249. failures.push(test);
  2250. });
  2251. runner.on('end', function(){
  2252. var obj = {
  2253. stats: self.stats
  2254. , tests: tests.map(clean)
  2255. , failures: failures.map(clean)
  2256. , passes: passes.map(clean)
  2257. };
  2258. process.stdout.write(JSON.stringify(obj, null, 2));
  2259. });
  2260. }
  2261. /**
  2262. * Return a plain-object representation of `test`
  2263. * free of cyclic properties etc.
  2264. *
  2265. * @param {Object} test
  2266. * @return {Object}
  2267. * @api private
  2268. */
  2269. function clean(test) {
  2270. return {
  2271. title: test.title
  2272. , fullTitle: test.fullTitle()
  2273. , duration: test.duration
  2274. }
  2275. }
  2276. }); // module: reporters/json.js
  2277. require.register("reporters/landing.js", function(module, exports, require){
  2278. /**
  2279. * Module dependencies.
  2280. */
  2281. var Base = require('./base')
  2282. , cursor = Base.cursor
  2283. , color = Base.color;
  2284. /**
  2285. * Expose `Landing`.
  2286. */
  2287. exports = module.exports = Landing;
  2288. /**
  2289. * Airplane color.
  2290. */
  2291. Base.colors.plane = 0;
  2292. /**
  2293. * Airplane crash color.
  2294. */
  2295. Base.colors['plane crash'] = 31;
  2296. /**
  2297. * Runway color.
  2298. */
  2299. Base.colors.runway = 90;
  2300. /**
  2301. * Initialize a new `Landing` reporter.
  2302. *
  2303. * @param {Runner} runner
  2304. * @api public
  2305. */
  2306. function Landing(runner) {
  2307. Base.call(this, runner);
  2308. var self = this
  2309. , stats = this.stats
  2310. , width = Base.window.width * .75 | 0
  2311. , total = runner.total
  2312. , stream = process.stdout
  2313. , plane = color('plane', '✈')
  2314. , crashed = -1
  2315. , n = 0;
  2316. function runway() {
  2317. var buf = Array(width).join('-');
  2318. return ' ' + color('runway', buf);
  2319. }
  2320. runner.on('start', function(){
  2321. stream.write('\n ');
  2322. cursor.hide();
  2323. });
  2324. runner.on('test end', function(test){
  2325. // check if the plane crashed
  2326. var col = -1 == crashed
  2327. ? width * ++n / total | 0
  2328. : crashed;
  2329. // show the crash
  2330. if ('failed' == test.state) {
  2331. plane = color('plane crash', '✈');
  2332. crashed = col;
  2333. }
  2334. // render landing strip
  2335. stream.write('\u001b[4F\n\n');
  2336. stream.write(runway());
  2337. stream.write('\n ');
  2338. stream.write(color('runway', Array(col).join('⋅')));
  2339. stream.write(plane)
  2340. stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
  2341. stream.write(runway());
  2342. stream.write('\u001b[0m');
  2343. });
  2344. runner.on('end', function(){
  2345. cursor.show();
  2346. console.log();
  2347. self.epilogue();
  2348. });
  2349. }
  2350. /**
  2351. * Inherit from `Base.prototype`.
  2352. */
  2353. function F(){};
  2354. F.prototype = Base.prototype;
  2355. Landing.prototype = new F;
  2356. Landing.prototype.constructor = Landing;
  2357. }); // module: reporters/landing.js
  2358. require.register("reporters/list.js", function(module, exports, require){
  2359. /**
  2360. * Module dependencies.
  2361. */
  2362. var Base = require('./base')
  2363. , cursor = Base.cursor
  2364. , color = Base.color;
  2365. /**
  2366. * Expose `List`.
  2367. */
  2368. exports = module.exports = List;
  2369. /**
  2370. * Initialize a new `List` test reporter.
  2371. *
  2372. * @param {Runner} runner
  2373. * @api public
  2374. */
  2375. function List(runner) {
  2376. Base.call(this, runner);
  2377. var self = this
  2378. , stats = this.stats
  2379. , n = 0;
  2380. runner.on('start', function(){
  2381. console.log();
  2382. });
  2383. runner.on('test', function(test){
  2384. process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
  2385. });
  2386. runner.on('pending', function(test){
  2387. var fmt = color('checkmark', ' -')
  2388. + color('pending', ' %s');
  2389. console.log(fmt, test.fullTitle());
  2390. });
  2391. runner.on('pass', function(test){
  2392. var fmt = color('checkmark', ' '+Base.symbols.dot)
  2393. + color('pass', ' %s: ')
  2394. + color(test.speed, '%dms');
  2395. cursor.CR();
  2396. console.log(fmt, test.fullTitle(), test.duration);
  2397. });
  2398. runner.on('fail', function(test, err){
  2399. cursor.CR();
  2400. console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
  2401. });
  2402. runner.on('end', self.epilogue.bind(self));
  2403. }
  2404. /**
  2405. * Inherit from `Base.prototype`.
  2406. */
  2407. function F(){};
  2408. F.prototype = Base.prototype;
  2409. List.prototype = new F;
  2410. List.prototype.constructor = List;
  2411. }); // module: reporters/list.js
  2412. require.register("reporters/markdown.js", function(module, exports, require){
  2413. /**
  2414. * Module dependencies.
  2415. */
  2416. var Base = require('./base')
  2417. , utils = require('../utils');
  2418. /**
  2419. * Expose `Markdown`.
  2420. */
  2421. exports = module.exports = Markdown;
  2422. /**
  2423. * Initialize a new `Markdown` reporter.
  2424. *
  2425. * @param {Runner} runner
  2426. * @api public
  2427. */
  2428. function Markdown(runner) {
  2429. Base.call(this, runner);
  2430. var self = this
  2431. , stats = this.stats
  2432. , level = 0
  2433. , buf = '';
  2434. function title(str) {
  2435. return Array(level).join('#') + ' ' + str;
  2436. }
  2437. function indent() {
  2438. return Array(level).join(' ');
  2439. }
  2440. function mapTOC(suite, obj) {
  2441. var ret = obj;
  2442. obj = obj[suite.title] = obj[suite.title] || { suite: suite };
  2443. suite.suites.forEach(function(suite){
  2444. mapTOC(suite, obj);
  2445. });
  2446. return ret;
  2447. }
  2448. function stringifyTOC(obj, level) {
  2449. ++level;
  2450. var buf = '';
  2451. var link;
  2452. for (var key in obj) {
  2453. if ('suite' == key) continue;
  2454. if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
  2455. if (key) buf += Array(level).join(' ') + link;
  2456. buf += stringifyTOC(obj[key], level);
  2457. }
  2458. --level;
  2459. return buf;
  2460. }
  2461. function generateTOC(suite) {
  2462. var obj = mapTOC(suite, {});
  2463. return stringifyTOC(obj, 0);
  2464. }
  2465. generateTOC(runner.suite);
  2466. runner.on('suite', function(suite){
  2467. ++level;
  2468. var slug = utils.slug(suite.fullTitle());
  2469. buf += '<a name="' + slug + '"></a>' + '\n';
  2470. buf += title(suite.title) + '\n';
  2471. });
  2472. runner.on('suite end', function(suite){
  2473. --level;
  2474. });
  2475. runner.on('pass', function(test){
  2476. var code = utils.clean(test.fn.toString());
  2477. buf += test.title + '.\n';
  2478. buf += '\n```js\n';
  2479. buf += code + '\n';
  2480. buf += '```\n\n';
  2481. });
  2482. runner.on('end', function(){
  2483. process.stdout.write('# TOC\n');
  2484. process.stdout.write(generateTOC(runner.suite));
  2485. process.stdout.write(buf);
  2486. });
  2487. }
  2488. }); // module: reporters/markdown.js
  2489. require.register("reporters/min.js", function(module, exports, require){
  2490. /**
  2491. * Module dependencies.
  2492. */
  2493. var Base = require('./base');
  2494. /**
  2495. * Expose `Min`.
  2496. */
  2497. exports = module.exports = Min;
  2498. /**
  2499. * Initialize a new `Min` minimal test reporter (best used with --watch).
  2500. *
  2501. * @param {Runner} runner
  2502. * @api public
  2503. */
  2504. function Min(runner) {
  2505. Base.call(this, runner);
  2506. runner.on('start', function(){
  2507. // clear screen
  2508. process.stdout.write('\u001b[2J');
  2509. // set cursor position
  2510. process.stdout.write('\u001b[1;3H');
  2511. });
  2512. runner.on('end', this.epilogue.bind(this));
  2513. }
  2514. /**
  2515. * Inherit from `Base.prototype`.
  2516. */
  2517. function F(){};
  2518. F.prototype = Base.prototype;
  2519. Min.prototype = new F;
  2520. Min.prototype.constructor = Min;
  2521. }); // module: reporters/min.js
  2522. require.register("reporters/nyan.js", function(module, exports, require){
  2523. /**
  2524. * Module dependencies.
  2525. */
  2526. var Base = require('./base')
  2527. , color = Base.color;
  2528. /**
  2529. * Expose `Dot`.
  2530. */
  2531. exports = module.exports = NyanCat;
  2532. /**
  2533. * Initialize a new `Dot` matrix test reporter.
  2534. *
  2535. * @param {Runner} runner
  2536. * @api public
  2537. */
  2538. function NyanCat(runner) {
  2539. Base.call(this, runner);
  2540. var self = this
  2541. , stats = this.stats
  2542. , width = Base.window.width * .75 | 0
  2543. , rainbowColors = this.rainbowColors = self.generateColors()
  2544. , colorIndex = this.colorIndex = 0
  2545. , numerOfLines = this.numberOfLines = 4
  2546. , trajectories = this.trajectories = [[], [], [], []]
  2547. , nyanCatWidth = this.nyanCatWidth = 11
  2548. , trajectoryWidthMax = this.trajectoryWidthMax = (width - nyanCatWidth)
  2549. , scoreboardWidth = this.scoreboardWidth = 5
  2550. , tick = this.tick = 0
  2551. , n = 0;
  2552. runner.on('start', function(){
  2553. Base.cursor.hide();
  2554. self.draw('start');
  2555. });
  2556. runner.on('pending', function(test){
  2557. self.draw('pending');
  2558. });
  2559. runner.on('pass', function(test){
  2560. self.draw('pass');
  2561. });
  2562. runner.on('fail', function(test, err){
  2563. self.draw('fail');
  2564. });
  2565. runner.on('end', function(){
  2566. Base.cursor.show();
  2567. for (var i = 0; i < self.numberOfLines; i++) write('\n');
  2568. self.epilogue();
  2569. });
  2570. }
  2571. /**
  2572. * Draw the nyan cat with runner `status`.
  2573. *
  2574. * @param {String} status
  2575. * @api private
  2576. */
  2577. NyanCat.prototype.draw = function(status){
  2578. this.appendRainbow();
  2579. this.drawScoreboard();
  2580. this.drawRainbow();
  2581. this.drawNyanCat(status);
  2582. this.tick = !this.tick;
  2583. };
  2584. /**
  2585. * Draw the "scoreboard" showing the number
  2586. * of passes, failures and pending tests.
  2587. *
  2588. * @api private
  2589. */
  2590. NyanCat.prototype.drawScoreboard = function(){
  2591. var stats = this.stats;
  2592. var colors = Base.colors;
  2593. function draw(color, n) {
  2594. write(' ');
  2595. write('\u001b[' + color + 'm' + n + '\u001b[0m');
  2596. write('\n');
  2597. }
  2598. draw(colors.green, stats.passes);
  2599. draw(colors.fail, stats.failures);
  2600. draw(colors.pending, stats.pending);
  2601. write('\n');
  2602. this.cursorUp(this.numberOfLines);
  2603. };
  2604. /**
  2605. * Append the rainbow.
  2606. *
  2607. * @api private
  2608. */
  2609. NyanCat.prototype.appendRainbow = function(){
  2610. var segment = this.tick ? '_' : '-';
  2611. var rainbowified = this.rainbowify(segment);
  2612. for (var index = 0; index < this.numberOfLines; index++) {
  2613. var trajectory = this.trajectories[index];
  2614. if (trajectory.length >= this.trajectoryWidthMax) trajectory.shift();
  2615. trajectory.push(rainbowified);
  2616. }
  2617. };
  2618. /**
  2619. * Draw the rainbow.
  2620. *
  2621. * @api private
  2622. */
  2623. NyanCat.prototype.drawRainbow = function(){
  2624. var self = this;
  2625. this.trajectories.forEach(function(line, index) {
  2626. write('\u001b[' + self.scoreboardWidth + 'C');
  2627. write(line.join(''));
  2628. write('\n');
  2629. });
  2630. this.cursorUp(this.numberOfLines);
  2631. };
  2632. /**
  2633. * Draw the nyan cat with `status`.
  2634. *
  2635. * @param {String} status
  2636. * @api private
  2637. */
  2638. NyanCat.prototype.drawNyanCat = function(status) {
  2639. var self = this;
  2640. var startWidth = this.scoreboardWidth + this.trajectories[0].length;
  2641. [0, 1, 2, 3].forEach(function(index) {
  2642. write('\u001b[' + startWidth + 'C');
  2643. switch (index) {
  2644. case 0:
  2645. write('_,------,');
  2646. write('\n');
  2647. break;
  2648. case 1:
  2649. var padding = self.tick ? ' ' : ' ';
  2650. write('_|' + padding + '/\\_/\\ ');
  2651. write('\n');
  2652. break;
  2653. case 2:
  2654. var padding = self.tick ? '_' : '__';
  2655. var tail = self.tick ? '~' : '^';
  2656. var face;
  2657. switch (status) {
  2658. case 'pass':
  2659. face = '( ^ .^)';
  2660. break;
  2661. case 'fail':
  2662. face = '( o .o)';
  2663. break;
  2664. default:
  2665. face = '( - .-)';
  2666. }
  2667. write(tail + '|' + padding + face + ' ');
  2668. write('\n');
  2669. break;
  2670. case 3:
  2671. var padding = self.tick ? ' ' : ' ';
  2672. write(padding + '"" "" ');
  2673. write('\n');
  2674. break;
  2675. }
  2676. });
  2677. this.cursorUp(this.numberOfLines);
  2678. };
  2679. /**
  2680. * Move cursor up `n`.
  2681. *
  2682. * @param {Number} n
  2683. * @api private
  2684. */
  2685. NyanCat.prototype.cursorUp = function(n) {
  2686. write('\u001b[' + n + 'A');
  2687. };
  2688. /**
  2689. * Move cursor down `n`.
  2690. *
  2691. * @param {Number} n
  2692. * @api private
  2693. */
  2694. NyanCat.prototype.cursorDown = function(n) {
  2695. write('\u001b[' + n + 'B');
  2696. };
  2697. /**
  2698. * Generate rainbow colors.
  2699. *
  2700. * @return {Array}
  2701. * @api private
  2702. */
  2703. NyanCat.prototype.generateColors = function(){
  2704. var colors = [];
  2705. for (var i = 0; i < (6 * 7); i++) {
  2706. var pi3 = Math.floor(Math.PI / 3);
  2707. var n = (i * (1.0 / 6));
  2708. var r = Math.floor(3 * Math.sin(n) + 3);
  2709. var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
  2710. var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
  2711. colors.push(36 * r + 6 * g + b + 16);
  2712. }
  2713. return colors;
  2714. };
  2715. /**
  2716. * Apply rainbow to the given `str`.
  2717. *
  2718. * @param {String} str
  2719. * @return {String}
  2720. * @api private
  2721. */
  2722. NyanCat.prototype.rainbowify = function(str){
  2723. var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
  2724. this.colorIndex += 1;
  2725. return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
  2726. };
  2727. /**
  2728. * Stdout helper.
  2729. */
  2730. function write(string) {
  2731. process.stdout.write(string);
  2732. }
  2733. /**
  2734. * Inherit from `Base.prototype`.
  2735. */
  2736. function F(){};
  2737. F.prototype = Base.prototype;
  2738. NyanCat.prototype = new F;
  2739. NyanCat.prototype.constructor = NyanCat;
  2740. }); // module: reporters/nyan.js
  2741. require.register("reporters/progress.js", function(module, exports, require){
  2742. /**
  2743. * Module dependencies.
  2744. */
  2745. var Base = require('./base')
  2746. , cursor = Base.cursor
  2747. , color = Base.color;
  2748. /**
  2749. * Expose `Progress`.
  2750. */
  2751. exports = module.exports = Progress;
  2752. /**
  2753. * General progress bar color.
  2754. */
  2755. Base.colors.progress = 90;
  2756. /**
  2757. * Initialize a new `Progress` bar test reporter.
  2758. *
  2759. * @param {Runner} runner
  2760. * @param {Object} options
  2761. * @api public
  2762. */
  2763. function Progress(runner, options) {
  2764. Base.call(this, runner);
  2765. var self = this
  2766. , options = options || {}
  2767. , stats = this.stats
  2768. , width = Base.window.width * .50 | 0
  2769. , total = runner.total
  2770. , complete = 0
  2771. , max = Math.max;
  2772. // default chars
  2773. options.open = options.open || '[';
  2774. options.complete = options.complete || '▬';
  2775. options.incomplete = options.incomplete || Base.symbols.dot;
  2776. options.close = options.close || ']';
  2777. options.verbose = false;
  2778. // tests started
  2779. runner.on('start', function(){
  2780. console.log();
  2781. cursor.hide();
  2782. });
  2783. // tests complete
  2784. runner.on('test end', function(){
  2785. complete++;
  2786. var incomplete = total - complete
  2787. , percent = complete / total
  2788. , n = width * percent | 0
  2789. , i = width - n;
  2790. cursor.CR();
  2791. process.stdout.write('\u001b[J');
  2792. process.stdout.write(color('progress', ' ' + options.open));
  2793. process.stdout.write(Array(n).join(options.complete));
  2794. process.stdout.write(Array(i).join(options.incomplete));
  2795. process.stdout.write(color('progress', options.close));
  2796. if (options.verbose) {
  2797. process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
  2798. }
  2799. });
  2800. // tests are complete, output some stats
  2801. // and the failures if any
  2802. runner.on('end', function(){
  2803. cursor.show();
  2804. console.log();
  2805. self.epilogue();
  2806. });
  2807. }
  2808. /**
  2809. * Inherit from `Base.prototype`.
  2810. */
  2811. function F(){};
  2812. F.prototype = Base.prototype;
  2813. Progress.prototype = new F;
  2814. Progress.prototype.constructor = Progress;
  2815. }); // module: reporters/progress.js
  2816. require.register("reporters/spec.js", function(module, exports, require){
  2817. /**
  2818. * Module dependencies.
  2819. */
  2820. var Base = require('./base')
  2821. , cursor = Base.cursor
  2822. , color = Base.color;
  2823. /**
  2824. * Expose `Spec`.
  2825. */
  2826. exports = module.exports = Spec;
  2827. /**
  2828. * Initialize a new `Spec` test reporter.
  2829. *
  2830. * @param {Runner} runner
  2831. * @api public
  2832. */
  2833. function Spec(runner) {
  2834. Base.call(this, runner);
  2835. var self = this
  2836. , stats = this.stats
  2837. , indents = 0
  2838. , n = 0;
  2839. function indent() {
  2840. return Array(indents).join(' ')
  2841. }
  2842. runner.on('start', function(){
  2843. console.log();
  2844. });
  2845. runner.on('suite', function(suite){
  2846. ++indents;
  2847. console.log(color('suite', '%s%s'), indent(), suite.title);
  2848. });
  2849. runner.on('suite end', function(suite){
  2850. --indents;
  2851. if (1 == indents) console.log();
  2852. });
  2853. runner.on('test', function(test){
  2854. process.stdout.write(indent() + color('pass', ' ◦ ' + test.title + ': '));
  2855. });
  2856. runner.on('pending', function(test){
  2857. var fmt = indent() + color('pending', ' - %s');
  2858. console.log(fmt, test.title);
  2859. });
  2860. runner.on('pass', function(test){
  2861. if ('fast' == test.speed) {
  2862. var fmt = indent()
  2863. + color('checkmark', ' ' + Base.symbols.ok)
  2864. + color('pass', ' %s ');
  2865. cursor.CR();
  2866. console.log(fmt, test.title);
  2867. } else {
  2868. var fmt = indent()
  2869. + color('checkmark', ' ' + Base.symbols.ok)
  2870. + color('pass', ' %s ')
  2871. + color(test.speed, '(%dms)');
  2872. cursor.CR();
  2873. console.log(fmt, test.title, test.duration);
  2874. }
  2875. });
  2876. runner.on('fail', function(test, err){
  2877. cursor.CR();
  2878. console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
  2879. });
  2880. runner.on('end', self.epilogue.bind(self));
  2881. }
  2882. /**
  2883. * Inherit from `Base.prototype`.
  2884. */
  2885. function F(){};
  2886. F.prototype = Base.prototype;
  2887. Spec.prototype = new F;
  2888. Spec.prototype.constructor = Spec;
  2889. }); // module: reporters/spec.js
  2890. require.register("reporters/tap.js", function(module, exports, require){
  2891. /**
  2892. * Module dependencies.
  2893. */
  2894. var Base = require('./base')
  2895. , cursor = Base.cursor
  2896. , color = Base.color;
  2897. /**
  2898. * Expose `TAP`.
  2899. */
  2900. exports = module.exports = TAP;
  2901. /**
  2902. * Initialize a new `TAP` reporter.
  2903. *
  2904. * @param {Runner} runner
  2905. * @api public
  2906. */
  2907. function TAP(runner) {
  2908. Base.call(this, runner);
  2909. var self = this
  2910. , stats = this.stats
  2911. , n = 1
  2912. , passes = 0
  2913. , failures = 0;
  2914. runner.on('start', function(){
  2915. var total = runner.grepTotal(runner.suite);
  2916. console.log('%d..%d', 1, total);
  2917. });
  2918. runner.on('test end', function(){
  2919. ++n;
  2920. });
  2921. runner.on('pending', function(test){
  2922. console.log('ok %d %s # SKIP -', n, title(test));
  2923. });
  2924. runner.on('pass', function(test){
  2925. passes++;
  2926. console.log('ok %d %s', n, title(test));
  2927. });
  2928. runner.on('fail', function(test, err){
  2929. failures++;
  2930. console.log('not ok %d %s', n, title(test));
  2931. if (err.stack) console.log(err.stack.replace(/^/gm, ' '));
  2932. });
  2933. runner.on('end', function(){
  2934. console.log('# tests ' + (passes + failures));
  2935. console.log('# pass ' + passes);
  2936. console.log('# fail ' + failures);
  2937. });
  2938. }
  2939. /**
  2940. * Return a TAP-safe title of `test`
  2941. *
  2942. * @param {Object} test
  2943. * @return {String}
  2944. * @api private
  2945. */
  2946. function title(test) {
  2947. return test.fullTitle().replace(/#/g, '');
  2948. }
  2949. }); // module: reporters/tap.js
  2950. require.register("reporters/teamcity.js", function(module, exports, require){
  2951. /**
  2952. * Module dependencies.
  2953. */
  2954. var Base = require('./base');
  2955. /**
  2956. * Expose `Teamcity`.
  2957. */
  2958. exports = module.exports = Teamcity;
  2959. /**
  2960. * Initialize a new `Teamcity` reporter.
  2961. *
  2962. * @param {Runner} runner
  2963. * @api public
  2964. */
  2965. function Teamcity(runner) {
  2966. Base.call(this, runner);
  2967. var stats = this.stats;
  2968. runner.on('start', function() {
  2969. console.log("##teamcity[testSuiteStarted name='mocha.suite']");
  2970. });
  2971. runner.on('test', function(test) {
  2972. console.log("##teamcity[testStarted name='" + escape(test.fullTitle()) + "']");
  2973. });
  2974. runner.on('fail', function(test, err) {
  2975. console.log("##teamcity[testFailed name='" + escape(test.fullTitle()) + "' message='" + escape(err.message) + "']");
  2976. });
  2977. runner.on('pending', function(test) {
  2978. console.log("##teamcity[testIgnored name='" + escape(test.fullTitle()) + "' message='pending']");
  2979. });
  2980. runner.on('test end', function(test) {
  2981. console.log("##teamcity[testFinished name='" + escape(test.fullTitle()) + "' duration='" + test.duration + "']");
  2982. });
  2983. runner.on('end', function() {
  2984. console.log("##teamcity[testSuiteFinished name='mocha.suite' duration='" + stats.duration + "']");
  2985. });
  2986. }
  2987. /**
  2988. * Escape the given `str`.
  2989. */
  2990. function escape(str) {
  2991. return str
  2992. .replace(/\|/g, "||")
  2993. .replace(/\n/g, "|n")
  2994. .replace(/\r/g, "|r")
  2995. .replace(/\[/g, "|[")
  2996. .replace(/\]/g, "|]")
  2997. .replace(/\u0085/g, "|x")
  2998. .replace(/\u2028/g, "|l")
  2999. .replace(/\u2029/g, "|p")
  3000. .replace(/'/g, "|'");
  3001. }
  3002. }); // module: reporters/teamcity.js
  3003. require.register("reporters/xunit.js", function(module, exports, require){
  3004. /**
  3005. * Module dependencies.
  3006. */
  3007. var Base = require('./base')
  3008. , utils = require('../utils')
  3009. , escape = utils.escape;
  3010. /**
  3011. * Save timer references to avoid Sinon interfering (see GH-237).
  3012. */
  3013. var Date = global.Date
  3014. , setTimeout = global.setTimeout
  3015. , setInterval = global.setInterval
  3016. , clearTimeout = global.clearTimeout
  3017. , clearInterval = global.clearInterval;
  3018. /**
  3019. * Expose `XUnit`.
  3020. */
  3021. exports = module.exports = XUnit;
  3022. /**
  3023. * Initialize a new `XUnit` reporter.
  3024. *
  3025. * @param {Runner} runner
  3026. * @api public
  3027. */
  3028. function XUnit(runner) {
  3029. Base.call(this, runner);
  3030. var stats = this.stats
  3031. , tests = []
  3032. , self = this;
  3033. runner.on('pass', function(test){
  3034. tests.push(test);
  3035. });
  3036. runner.on('fail', function(test){
  3037. tests.push(test);
  3038. });
  3039. runner.on('end', function(){
  3040. console.log(tag('testsuite', {
  3041. name: 'Mocha Tests'
  3042. , tests: stats.tests
  3043. , failures: stats.failures
  3044. , errors: stats.failures
  3045. , skip: stats.tests - stats.failures - stats.passes
  3046. , timestamp: (new Date).toUTCString()
  3047. , time: stats.duration / 1000
  3048. }, false));
  3049. tests.forEach(test);
  3050. console.log('</testsuite>');
  3051. });
  3052. }
  3053. /**
  3054. * Inherit from `Base.prototype`.
  3055. */
  3056. function F(){};
  3057. F.prototype = Base.prototype;
  3058. XUnit.prototype = new F;
  3059. XUnit.prototype.constructor = XUnit;
  3060. /**
  3061. * Output tag for the given `test.`
  3062. */
  3063. function test(test) {
  3064. var attrs = {
  3065. classname: test.parent.fullTitle()
  3066. , name: test.title
  3067. , time: test.duration / 1000
  3068. };
  3069. if ('failed' == test.state) {
  3070. var err = test.err;
  3071. attrs.message = escape(err.message);
  3072. console.log(tag('testcase', attrs, false, tag('failure', attrs, false, cdata(err.stack))));
  3073. } else if (test.pending) {
  3074. console.log(tag('testcase', attrs, false, tag('skipped', {}, true)));
  3075. } else {
  3076. console.log(tag('testcase', attrs, true) );
  3077. }
  3078. }
  3079. /**
  3080. * HTML tag helper.
  3081. */
  3082. function tag(name, attrs, close, content) {
  3083. var end = close ? '/>' : '>'
  3084. , pairs = []
  3085. , tag;
  3086. for (var key in attrs) {
  3087. pairs.push(key + '="' + escape(attrs[key]) + '"');
  3088. }
  3089. tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
  3090. if (content) tag += content + '</' + name + end;
  3091. return tag;
  3092. }
  3093. /**
  3094. * Return cdata escaped CDATA `str`.
  3095. */
  3096. function cdata(str) {
  3097. return '<![CDATA[' + escape(str) + ']]>';
  3098. }
  3099. }); // module: reporters/xunit.js
  3100. require.register("runnable.js", function(module, exports, require){
  3101. /**
  3102. * Module dependencies.
  3103. */
  3104. var EventEmitter = require('browser/events').EventEmitter
  3105. , debug = require('browser/debug')('mocha:runnable')
  3106. , milliseconds = require('./ms');
  3107. /**
  3108. * Save timer references to avoid Sinon interfering (see GH-237).
  3109. */
  3110. var Date = global.Date
  3111. , setTimeout = global.setTimeout
  3112. , setInterval = global.setInterval
  3113. , clearTimeout = global.clearTimeout
  3114. , clearInterval = global.clearInterval;
  3115. /**
  3116. * Object#toString().
  3117. */
  3118. var toString = Object.prototype.toString;
  3119. /**
  3120. * Expose `Runnable`.
  3121. */
  3122. module.exports = Runnable;
  3123. /**
  3124. * Initialize a new `Runnable` with the given `title` and callback `fn`.
  3125. *
  3126. * @param {String} title
  3127. * @param {Function} fn
  3128. * @api private
  3129. */
  3130. function Runnable(title, fn) {
  3131. this.title = title;
  3132. this.fn = fn;
  3133. this.async = fn && fn.length;
  3134. this.sync = ! this.async;
  3135. this._timeout = 2000;
  3136. this._slow = 75;
  3137. this.timedOut = false;
  3138. }
  3139. /**
  3140. * Inherit from `EventEmitter.prototype`.
  3141. */
  3142. function F(){};
  3143. F.prototype = EventEmitter.prototype;
  3144. Runnable.prototype = new F;
  3145. Runnable.prototype.constructor = Runnable;
  3146. /**
  3147. * Set & get timeout `ms`.
  3148. *
  3149. * @param {Number|String} ms
  3150. * @return {Runnable|Number} ms or self
  3151. * @api private
  3152. */
  3153. Runnable.prototype.timeout = function(ms){
  3154. if (0 == arguments.length) return this._timeout;
  3155. if ('string' == typeof ms) ms = milliseconds(ms);
  3156. debug('timeout %d', ms);
  3157. this._timeout = ms;
  3158. if (this.timer) this.resetTimeout();
  3159. return this;
  3160. };
  3161. /**
  3162. * Set & get slow `ms`.
  3163. *
  3164. * @param {Number|String} ms
  3165. * @return {Runnable|Number} ms or self
  3166. * @api private
  3167. */
  3168. Runnable.prototype.slow = function(ms){
  3169. if (0 === arguments.length) return this._slow;
  3170. if ('string' == typeof ms) ms = milliseconds(ms);
  3171. debug('timeout %d', ms);
  3172. this._slow = ms;
  3173. return this;
  3174. };
  3175. /**
  3176. * Return the full title generated by recursively
  3177. * concatenating the parent's full title.
  3178. *
  3179. * @return {String}
  3180. * @api public
  3181. */
  3182. Runnable.prototype.fullTitle = function(){
  3183. return this.parent.fullTitle() + ' ' + this.title;
  3184. };
  3185. /**
  3186. * Clear the timeout.
  3187. *
  3188. * @api private
  3189. */
  3190. Runnable.prototype.clearTimeout = function(){
  3191. clearTimeout(this.timer);
  3192. };
  3193. /**
  3194. * Inspect the runnable void of private properties.
  3195. *
  3196. * @return {String}
  3197. * @api private
  3198. */
  3199. Runnable.prototype.inspect = function(){
  3200. return JSON.stringify(this, function(key, val){
  3201. if ('_' == key[0]) return;
  3202. if ('parent' == key) return '#<Suite>';
  3203. if ('ctx' == key) return '#<Context>';
  3204. return val;
  3205. }, 2);
  3206. };
  3207. /**
  3208. * Reset the timeout.
  3209. *
  3210. * @api private
  3211. */
  3212. Runnable.prototype.resetTimeout = function(){
  3213. var self = this
  3214. , ms = this.timeout();
  3215. this.clearTimeout();
  3216. if (ms) {
  3217. this.timer = setTimeout(function(){
  3218. self.callback(new Error('timeout of ' + ms + 'ms exceeded'));
  3219. self.timedOut = true;
  3220. }, ms);
  3221. }
  3222. };
  3223. /**
  3224. * Run the test and invoke `fn(err)`.
  3225. *
  3226. * @param {Function} fn
  3227. * @api private
  3228. */
  3229. Runnable.prototype.run = function(fn){
  3230. var self = this
  3231. , ms = this.timeout()
  3232. , start = new Date
  3233. , ctx = this.ctx
  3234. , finished
  3235. , emitted;
  3236. if (ctx) ctx.runnable(this);
  3237. // timeout
  3238. if (this.async) {
  3239. if (ms) {
  3240. this.timer = setTimeout(function(){
  3241. done(new Error('timeout of ' + ms + 'ms exceeded'));
  3242. self.timedOut = true;
  3243. }, ms);
  3244. }
  3245. }
  3246. // called multiple times
  3247. function multiple(err) {
  3248. if (emitted) return;
  3249. emitted = true;
  3250. self.emit('error', err || new Error('done() called multiple times'));
  3251. }
  3252. // finished
  3253. function done(err) {
  3254. if (self.timedOut) return;
  3255. if (finished) return multiple(err);
  3256. self.clearTimeout();
  3257. self.duration = new Date - start;
  3258. finished = true;
  3259. fn(err);
  3260. }
  3261. // for .resetTimeout()
  3262. this.callback = done;
  3263. // async
  3264. if (this.async) {
  3265. try {
  3266. this.fn.call(ctx, function(err){
  3267. if (err instanceof Error || toString.call(err) === "[object Error]") return done(err);
  3268. if (null != err) return done(new Error('done() invoked with non-Error: ' + err));
  3269. done();
  3270. });
  3271. } catch (err) {
  3272. done(err);
  3273. }
  3274. return;
  3275. }
  3276. if (this.asyncOnly) {
  3277. return done(new Error('--async-only option in use without declaring `done()`'));
  3278. }
  3279. // sync
  3280. try {
  3281. if (!this.pending) this.fn.call(ctx);
  3282. this.duration = new Date - start;
  3283. fn();
  3284. } catch (err) {
  3285. fn(err);
  3286. }
  3287. };
  3288. }); // module: runnable.js
  3289. require.register("runner.js", function(module, exports, require){
  3290. /**
  3291. * Module dependencies.
  3292. */
  3293. var EventEmitter = require('browser/events').EventEmitter
  3294. , debug = require('browser/debug')('mocha:runner')
  3295. , Test = require('./test')
  3296. , utils = require('./utils')
  3297. , filter = utils.filter
  3298. , keys = utils.keys
  3299. , noop = function(){};
  3300. /**
  3301. * Non-enumerable globals.
  3302. */
  3303. var globals = [
  3304. 'setTimeout',
  3305. 'clearTimeout',
  3306. 'setInterval',
  3307. 'clearInterval',
  3308. 'XMLHttpRequest',
  3309. 'Date'
  3310. ];
  3311. /**
  3312. * Expose `Runner`.
  3313. */
  3314. module.exports = Runner;
  3315. /**
  3316. * Initialize a `Runner` for the given `suite`.
  3317. *
  3318. * Events:
  3319. *
  3320. * - `start` execution started
  3321. * - `end` execution complete
  3322. * - `suite` (suite) test suite execution started
  3323. * - `suite end` (suite) all tests (and sub-suites) have finished
  3324. * - `test` (test) test execution started
  3325. * - `test end` (test) test completed
  3326. * - `hook` (hook) hook execution started
  3327. * - `hook end` (hook) hook complete
  3328. * - `pass` (test) test passed
  3329. * - `fail` (test, err) test failed
  3330. *
  3331. * @api public
  3332. */
  3333. function Runner(suite) {
  3334. var self = this;
  3335. this._globals = [];
  3336. this.suite = suite;
  3337. this.total = suite.total();
  3338. this.failures = 0;
  3339. this.on('test end', function(test){ self.checkGlobals(test); });
  3340. this.on('hook end', function(hook){ self.checkGlobals(hook); });
  3341. this.grep(/.*/);
  3342. this.globals(this.globalProps().concat(['errno']));
  3343. }
  3344. /**
  3345. * Inherit from `EventEmitter.prototype`.
  3346. */
  3347. function F(){};
  3348. F.prototype = EventEmitter.prototype;
  3349. Runner.prototype = new F;
  3350. Runner.prototype.constructor = Runner;
  3351. /**
  3352. * Run tests with full titles matching `re`. Updates runner.total
  3353. * with number of tests matched.
  3354. *
  3355. * @param {RegExp} re
  3356. * @param {Boolean} invert
  3357. * @return {Runner} for chaining
  3358. * @api public
  3359. */
  3360. Runner.prototype.grep = function(re, invert){
  3361. debug('grep %s', re);
  3362. this._grep = re;
  3363. this._invert = invert;
  3364. this.total = this.grepTotal(this.suite);
  3365. return this;
  3366. };
  3367. /**
  3368. * Returns the number of tests matching the grep search for the
  3369. * given suite.
  3370. *
  3371. * @param {Suite} suite
  3372. * @return {Number}
  3373. * @api public
  3374. */
  3375. Runner.prototype.grepTotal = function(suite) {
  3376. var self = this;
  3377. var total = 0;
  3378. suite.eachTest(function(test){
  3379. var match = self._grep.test(test.fullTitle());
  3380. if (self._invert) match = !match;
  3381. if (match) total++;
  3382. });
  3383. return total;
  3384. };
  3385. /**
  3386. * Return a list of global properties.
  3387. *
  3388. * @return {Array}
  3389. * @api private
  3390. */
  3391. Runner.prototype.globalProps = function() {
  3392. var props = utils.keys(global);
  3393. // non-enumerables
  3394. for (var i = 0; i < globals.length; ++i) {
  3395. if (~utils.indexOf(props, globals[i])) continue;
  3396. props.push(globals[i]);
  3397. }
  3398. return props;
  3399. };
  3400. /**
  3401. * Allow the given `arr` of globals.
  3402. *
  3403. * @param {Array} arr
  3404. * @return {Runner} for chaining
  3405. * @api public
  3406. */
  3407. Runner.prototype.globals = function(arr){
  3408. if (0 == arguments.length) return this._globals;
  3409. debug('globals %j', arr);
  3410. utils.forEach(arr, function(arr){
  3411. this._globals.push(arr);
  3412. }, this);
  3413. return this;
  3414. };
  3415. /**
  3416. * Check for global variable leaks.
  3417. *
  3418. * @api private
  3419. */
  3420. Runner.prototype.checkGlobals = function(test){
  3421. if (this.ignoreLeaks) return;
  3422. var ok = this._globals;
  3423. var globals = this.globalProps();
  3424. var isNode = process.kill;
  3425. var leaks;
  3426. // check length - 2 ('errno' and 'location' globals)
  3427. if (isNode && 1 == ok.length - globals.length) return
  3428. else if (2 == ok.length - globals.length) return;
  3429. leaks = filterLeaks(ok, globals);
  3430. this._globals = this._globals.concat(leaks);
  3431. if (leaks.length > 1) {
  3432. this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
  3433. } else if (leaks.length) {
  3434. this.fail(test, new Error('global leak detected: ' + leaks[0]));
  3435. }
  3436. };
  3437. /**
  3438. * Fail the given `test`.
  3439. *
  3440. * @param {Test} test
  3441. * @param {Error} err
  3442. * @api private
  3443. */
  3444. Runner.prototype.fail = function(test, err){
  3445. ++this.failures;
  3446. test.state = 'failed';
  3447. if ('string' == typeof err) {
  3448. err = new Error('the string "' + err + '" was thrown, throw an Error :)');
  3449. }
  3450. this.emit('fail', test, err);
  3451. };
  3452. /**
  3453. * Fail the given `hook` with `err`.
  3454. *
  3455. * Hook failures (currently) hard-end due
  3456. * to that fact that a failing hook will
  3457. * surely cause subsequent tests to fail,
  3458. * causing jumbled reporting.
  3459. *
  3460. * @param {Hook} hook
  3461. * @param {Error} err
  3462. * @api private
  3463. */
  3464. Runner.prototype.failHook = function(hook, err){
  3465. this.fail(hook, err);
  3466. this.emit('end');
  3467. };
  3468. /**
  3469. * Run hook `name` callbacks and then invoke `fn()`.
  3470. *
  3471. * @param {String} name
  3472. * @param {Function} function
  3473. * @api private
  3474. */
  3475. Runner.prototype.hook = function(name, fn){
  3476. var suite = this.suite
  3477. , hooks = suite['_' + name]
  3478. , self = this
  3479. , timer;
  3480. function next(i) {
  3481. var hook = hooks[i];
  3482. if (!hook) return fn();
  3483. self.currentRunnable = hook;
  3484. self.emit('hook', hook);
  3485. hook.on('error', function(err){
  3486. self.failHook(hook, err);
  3487. });
  3488. hook.run(function(err){
  3489. hook.removeAllListeners('error');
  3490. var testError = hook.error();
  3491. if (testError) self.fail(self.test, testError);
  3492. if (err) return self.failHook(hook, err);
  3493. self.emit('hook end', hook);
  3494. next(++i);
  3495. });
  3496. }
  3497. process.nextTick(function(){
  3498. next(0);
  3499. });
  3500. };
  3501. /**
  3502. * Run hook `name` for the given array of `suites`
  3503. * in order, and callback `fn(err)`.
  3504. *
  3505. * @param {String} name
  3506. * @param {Array} suites
  3507. * @param {Function} fn
  3508. * @api private
  3509. */
  3510. Runner.prototype.hooks = function(name, suites, fn){
  3511. var self = this
  3512. , orig = this.suite;
  3513. function next(suite) {
  3514. self.suite = suite;
  3515. if (!suite) {
  3516. self.suite = orig;
  3517. return fn();
  3518. }
  3519. self.hook(name, function(err){
  3520. if (err) {
  3521. self.suite = orig;
  3522. return fn(err);
  3523. }
  3524. next(suites.pop());
  3525. });
  3526. }
  3527. next(suites.pop());
  3528. };
  3529. /**
  3530. * Run hooks from the top level down.
  3531. *
  3532. * @param {String} name
  3533. * @param {Function} fn
  3534. * @api private
  3535. */
  3536. Runner.prototype.hookUp = function(name, fn){
  3537. var suites = [this.suite].concat(this.parents()).reverse();
  3538. this.hooks(name, suites, fn);
  3539. };
  3540. /**
  3541. * Run hooks from the bottom up.
  3542. *
  3543. * @param {String} name
  3544. * @param {Function} fn
  3545. * @api private
  3546. */
  3547. Runner.prototype.hookDown = function(name, fn){
  3548. var suites = [this.suite].concat(this.parents());
  3549. this.hooks(name, suites, fn);
  3550. };
  3551. /**
  3552. * Return an array of parent Suites from
  3553. * closest to furthest.
  3554. *
  3555. * @return {Array}
  3556. * @api private
  3557. */
  3558. Runner.prototype.parents = function(){
  3559. var suite = this.suite
  3560. , suites = [];
  3561. while (suite = suite.parent) suites.push(suite);
  3562. return suites;
  3563. };
  3564. /**
  3565. * Run the current test and callback `fn(err)`.
  3566. *
  3567. * @param {Function} fn
  3568. * @api private
  3569. */
  3570. Runner.prototype.runTest = function(fn){
  3571. var test = this.test
  3572. , self = this;
  3573. if (this.asyncOnly) test.asyncOnly = true;
  3574. try {
  3575. test.on('error', function(err){
  3576. self.fail(test, err);
  3577. });
  3578. test.run(fn);
  3579. } catch (err) {
  3580. fn(err);
  3581. }
  3582. };
  3583. /**
  3584. * Run tests in the given `suite` and invoke
  3585. * the callback `fn()` when complete.
  3586. *
  3587. * @param {Suite} suite
  3588. * @param {Function} fn
  3589. * @api private
  3590. */
  3591. Runner.prototype.runTests = function(suite, fn){
  3592. var self = this
  3593. , tests = suite.tests.slice()
  3594. , test;
  3595. function next(err) {
  3596. // if we bail after first err
  3597. if (self.failures && suite._bail) return fn();
  3598. // next test
  3599. test = tests.shift();
  3600. // all done
  3601. if (!test) return fn();
  3602. // grep
  3603. var match = self._grep.test(test.fullTitle());
  3604. if (self._invert) match = !match;
  3605. if (!match) return next();
  3606. // pending
  3607. if (test.pending) {
  3608. self.emit('pending', test);
  3609. self.emit('test end', test);
  3610. return next();
  3611. }
  3612. // execute test and hook(s)
  3613. self.emit('test', self.test = test);
  3614. self.hookDown('beforeEach', function(){
  3615. self.currentRunnable = self.test;
  3616. self.runTest(function(err){
  3617. test = self.test;
  3618. if (err) {
  3619. self.fail(test, err);
  3620. self.emit('test end', test);
  3621. return self.hookUp('afterEach', next);
  3622. }
  3623. test.state = 'passed';
  3624. self.emit('pass', test);
  3625. self.emit('test end', test);
  3626. self.hookUp('afterEach', next);
  3627. });
  3628. });
  3629. }
  3630. this.next = next;
  3631. next();
  3632. };
  3633. /**
  3634. * Run the given `suite` and invoke the
  3635. * callback `fn()` when complete.
  3636. *
  3637. * @param {Suite} suite
  3638. * @param {Function} fn
  3639. * @api private
  3640. */
  3641. Runner.prototype.runSuite = function(suite, fn){
  3642. var total = this.grepTotal(suite)
  3643. , self = this
  3644. , i = 0;
  3645. debug('run suite %s', suite.fullTitle());
  3646. if (!total) return fn();
  3647. this.emit('suite', this.suite = suite);
  3648. function next() {
  3649. var curr = suite.suites[i++];
  3650. if (!curr) return done();
  3651. self.runSuite(curr, next);
  3652. }
  3653. function done() {
  3654. self.suite = suite;
  3655. self.hook('afterAll', function(){
  3656. self.emit('suite end', suite);
  3657. fn();
  3658. });
  3659. }
  3660. this.hook('beforeAll', function(){
  3661. self.runTests(suite, next);
  3662. });
  3663. };
  3664. /**
  3665. * Handle uncaught exceptions.
  3666. *
  3667. * @param {Error} err
  3668. * @api private
  3669. */
  3670. Runner.prototype.uncaught = function(err){
  3671. debug('uncaught exception %s', err.message);
  3672. var runnable = this.currentRunnable;
  3673. if (!runnable || 'failed' == runnable.state) return;
  3674. runnable.clearTimeout();
  3675. err.uncaught = true;
  3676. this.fail(runnable, err);
  3677. // recover from test
  3678. if ('test' == runnable.type) {
  3679. this.emit('test end', runnable);
  3680. this.hookUp('afterEach', this.next);
  3681. return;
  3682. }
  3683. // bail on hooks
  3684. this.emit('end');
  3685. };
  3686. /**
  3687. * Run the root suite and invoke `fn(failures)`
  3688. * on completion.
  3689. *
  3690. * @param {Function} fn
  3691. * @return {Runner} for chaining
  3692. * @api public
  3693. */
  3694. Runner.prototype.run = function(fn){
  3695. var self = this
  3696. , fn = fn || function(){};
  3697. debug('start');
  3698. // callback
  3699. this.on('end', function(){
  3700. debug('end');
  3701. process.removeListener('uncaughtException', function(err){
  3702. self.uncaught(err);
  3703. });
  3704. fn(self.failures);
  3705. });
  3706. // run suites
  3707. this.emit('start');
  3708. this.runSuite(this.suite, function(){
  3709. debug('finished running');
  3710. self.emit('end');
  3711. });
  3712. // uncaught exception
  3713. process.on('uncaughtException', function(err){
  3714. self.uncaught(err);
  3715. });
  3716. return this;
  3717. };
  3718. /**
  3719. * Filter leaks with the given globals flagged as `ok`.
  3720. *
  3721. * @param {Array} ok
  3722. * @param {Array} globals
  3723. * @return {Array}
  3724. * @api private
  3725. */
  3726. function filterLeaks(ok, globals) {
  3727. return filter(globals, function(key){
  3728. var matched = filter(ok, function(ok){
  3729. if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]);
  3730. // Opera and IE expose global variables for HTML element IDs (issue #243)
  3731. if (/^mocha-/.test(key)) return true;
  3732. return key == ok;
  3733. });
  3734. return matched.length == 0 && (!global.navigator || 'onerror' !== key);
  3735. });
  3736. }
  3737. }); // module: runner.js
  3738. require.register("suite.js", function(module, exports, require){
  3739. /**
  3740. * Module dependencies.
  3741. */
  3742. var EventEmitter = require('browser/events').EventEmitter
  3743. , debug = require('browser/debug')('mocha:suite')
  3744. , milliseconds = require('./ms')
  3745. , utils = require('./utils')
  3746. , Hook = require('./hook');
  3747. /**
  3748. * Expose `Suite`.
  3749. */
  3750. exports = module.exports = Suite;
  3751. /**
  3752. * Create a new `Suite` with the given `title`
  3753. * and parent `Suite`. When a suite with the
  3754. * same title is already present, that suite
  3755. * is returned to provide nicer reporter
  3756. * and more flexible meta-testing.
  3757. *
  3758. * @param {Suite} parent
  3759. * @param {String} title
  3760. * @return {Suite}
  3761. * @api public
  3762. */
  3763. exports.create = function(parent, title){
  3764. var suite = new Suite(title, parent.ctx);
  3765. suite.parent = parent;
  3766. if (parent.pending) suite.pending = true;
  3767. title = suite.fullTitle();
  3768. parent.addSuite(suite);
  3769. return suite;
  3770. };
  3771. /**
  3772. * Initialize a new `Suite` with the given
  3773. * `title` and `ctx`.
  3774. *
  3775. * @param {String} title
  3776. * @param {Context} ctx
  3777. * @api private
  3778. */
  3779. function Suite(title, ctx) {
  3780. this.title = title;
  3781. this.ctx = ctx;
  3782. this.suites = [];
  3783. this.tests = [];
  3784. this.pending = false;
  3785. this._beforeEach = [];
  3786. this._beforeAll = [];
  3787. this._afterEach = [];
  3788. this._afterAll = [];
  3789. this.root = !title;
  3790. this._timeout = 2000;
  3791. this._slow = 75;
  3792. this._bail = false;
  3793. }
  3794. /**
  3795. * Inherit from `EventEmitter.prototype`.
  3796. */
  3797. function F(){};
  3798. F.prototype = EventEmitter.prototype;
  3799. Suite.prototype = new F;
  3800. Suite.prototype.constructor = Suite;
  3801. /**
  3802. * Return a clone of this `Suite`.
  3803. *
  3804. * @return {Suite}
  3805. * @api private
  3806. */
  3807. Suite.prototype.clone = function(){
  3808. var suite = new Suite(this.title);
  3809. debug('clone');
  3810. suite.ctx = this.ctx;
  3811. suite.timeout(this.timeout());
  3812. suite.slow(this.slow());
  3813. suite.bail(this.bail());
  3814. return suite;
  3815. };
  3816. /**
  3817. * Set timeout `ms` or short-hand such as "2s".
  3818. *
  3819. * @param {Number|String} ms
  3820. * @return {Suite|Number} for chaining
  3821. * @api private
  3822. */
  3823. Suite.prototype.timeout = function(ms){
  3824. if (0 == arguments.length) return this._timeout;
  3825. if ('string' == typeof ms) ms = milliseconds(ms);
  3826. debug('timeout %d', ms);
  3827. this._timeout = parseInt(ms, 10);
  3828. return this;
  3829. };
  3830. /**
  3831. * Set slow `ms` or short-hand such as "2s".
  3832. *
  3833. * @param {Number|String} ms
  3834. * @return {Suite|Number} for chaining
  3835. * @api private
  3836. */
  3837. Suite.prototype.slow = function(ms){
  3838. if (0 === arguments.length) return this._slow;
  3839. if ('string' == typeof ms) ms = milliseconds(ms);
  3840. debug('slow %d', ms);
  3841. this._slow = ms;
  3842. return this;
  3843. };
  3844. /**
  3845. * Sets whether to bail after first error.
  3846. *
  3847. * @parma {Boolean} bail
  3848. * @return {Suite|Number} for chaining
  3849. * @api private
  3850. */
  3851. Suite.prototype.bail = function(bail){
  3852. if (0 == arguments.length) return this._bail;
  3853. debug('bail %s', bail);
  3854. this._bail = bail;
  3855. return this;
  3856. };
  3857. /**
  3858. * Run `fn(test[, done])` before running tests.
  3859. *
  3860. * @param {Function} fn
  3861. * @return {Suite} for chaining
  3862. * @api private
  3863. */
  3864. Suite.prototype.beforeAll = function(fn){
  3865. if (this.pending) return this;
  3866. var hook = new Hook('"before all" hook', fn);
  3867. hook.parent = this;
  3868. hook.timeout(this.timeout());
  3869. hook.slow(this.slow());
  3870. hook.ctx = this.ctx;
  3871. this._beforeAll.push(hook);
  3872. this.emit('beforeAll', hook);
  3873. return this;
  3874. };
  3875. /**
  3876. * Run `fn(test[, done])` after running tests.
  3877. *
  3878. * @param {Function} fn
  3879. * @return {Suite} for chaining
  3880. * @api private
  3881. */
  3882. Suite.prototype.afterAll = function(fn){
  3883. if (this.pending) return this;
  3884. var hook = new Hook('"after all" hook', fn);
  3885. hook.parent = this;
  3886. hook.timeout(this.timeout());
  3887. hook.slow(this.slow());
  3888. hook.ctx = this.ctx;
  3889. this._afterAll.push(hook);
  3890. this.emit('afterAll', hook);
  3891. return this;
  3892. };
  3893. /**
  3894. * Run `fn(test[, done])` before each test case.
  3895. *
  3896. * @param {Function} fn
  3897. * @return {Suite} for chaining
  3898. * @api private
  3899. */
  3900. Suite.prototype.beforeEach = function(fn){
  3901. if (this.pending) return this;
  3902. var hook = new Hook('"before each" hook', fn);
  3903. hook.parent = this;
  3904. hook.timeout(this.timeout());
  3905. hook.slow(this.slow());
  3906. hook.ctx = this.ctx;
  3907. this._beforeEach.push(hook);
  3908. this.emit('beforeEach', hook);
  3909. return this;
  3910. };
  3911. /**
  3912. * Run `fn(test[, done])` after each test case.
  3913. *
  3914. * @param {Function} fn
  3915. * @return {Suite} for chaining
  3916. * @api private
  3917. */
  3918. Suite.prototype.afterEach = function(fn){
  3919. if (this.pending) return this;
  3920. var hook = new Hook('"after each" hook', fn);
  3921. hook.parent = this;
  3922. hook.timeout(this.timeout());
  3923. hook.slow(this.slow());
  3924. hook.ctx = this.ctx;
  3925. this._afterEach.push(hook);
  3926. this.emit('afterEach', hook);
  3927. return this;
  3928. };
  3929. /**
  3930. * Add a test `suite`.
  3931. *
  3932. * @param {Suite} suite
  3933. * @return {Suite} for chaining
  3934. * @api private
  3935. */
  3936. Suite.prototype.addSuite = function(suite){
  3937. suite.parent = this;
  3938. suite.timeout(this.timeout());
  3939. suite.slow(this.slow());
  3940. suite.bail(this.bail());
  3941. this.suites.push(suite);
  3942. this.emit('suite', suite);
  3943. return this;
  3944. };
  3945. /**
  3946. * Add a `test` to this suite.
  3947. *
  3948. * @param {Test} test
  3949. * @return {Suite} for chaining
  3950. * @api private
  3951. */
  3952. Suite.prototype.addTest = function(test){
  3953. test.parent = this;
  3954. test.timeout(this.timeout());
  3955. test.slow(this.slow());
  3956. test.ctx = this.ctx;
  3957. this.tests.push(test);
  3958. this.emit('test', test);
  3959. return this;
  3960. };
  3961. /**
  3962. * Return the full title generated by recursively
  3963. * concatenating the parent's full title.
  3964. *
  3965. * @return {String}
  3966. * @api public
  3967. */
  3968. Suite.prototype.fullTitle = function(){
  3969. if (this.parent) {
  3970. var full = this.parent.fullTitle();
  3971. if (full) return full + ' ' + this.title;
  3972. }
  3973. return this.title;
  3974. };
  3975. /**
  3976. * Return the total number of tests.
  3977. *
  3978. * @return {Number}
  3979. * @api public
  3980. */
  3981. Suite.prototype.total = function(){
  3982. return utils.reduce(this.suites, function(sum, suite){
  3983. return sum + suite.total();
  3984. }, 0) + this.tests.length;
  3985. };
  3986. /**
  3987. * Iterates through each suite recursively to find
  3988. * all tests. Applies a function in the format
  3989. * `fn(test)`.
  3990. *
  3991. * @param {Function} fn
  3992. * @return {Suite}
  3993. * @api private
  3994. */
  3995. Suite.prototype.eachTest = function(fn){
  3996. utils.forEach(this.tests, fn);
  3997. utils.forEach(this.suites, function(suite){
  3998. suite.eachTest(fn);
  3999. });
  4000. return this;
  4001. };
  4002. }); // module: suite.js
  4003. require.register("test.js", function(module, exports, require){
  4004. /**
  4005. * Module dependencies.
  4006. */
  4007. var Runnable = require('./runnable');
  4008. /**
  4009. * Expose `Test`.
  4010. */
  4011. module.exports = Test;
  4012. /**
  4013. * Initialize a new `Test` with the given `title` and callback `fn`.
  4014. *
  4015. * @param {String} title
  4016. * @param {Function} fn
  4017. * @api private
  4018. */
  4019. function Test(title, fn) {
  4020. Runnable.call(this, title, fn);
  4021. this.pending = !fn;
  4022. this.type = 'test';
  4023. }
  4024. /**
  4025. * Inherit from `Runnable.prototype`.
  4026. */
  4027. function F(){};
  4028. F.prototype = Runnable.prototype;
  4029. Test.prototype = new F;
  4030. Test.prototype.constructor = Test;
  4031. }); // module: test.js
  4032. require.register("utils.js", function(module, exports, require){
  4033. /**
  4034. * Module dependencies.
  4035. */
  4036. var fs = require('browser/fs')
  4037. , path = require('browser/path')
  4038. , join = path.join
  4039. , debug = require('browser/debug')('mocha:watch');
  4040. /**
  4041. * Ignored directories.
  4042. */
  4043. var ignore = ['node_modules', '.git'];
  4044. /**
  4045. * Escape special characters in the given string of html.
  4046. *
  4047. * @param {String} html
  4048. * @return {String}
  4049. * @api private
  4050. */
  4051. exports.escape = function(html){
  4052. return String(html)
  4053. .replace(/&/g, '&amp;')
  4054. .replace(/"/g, '&quot;')
  4055. .replace(/</g, '&lt;')
  4056. .replace(/>/g, '&gt;');
  4057. };
  4058. /**
  4059. * Array#forEach (<=IE8)
  4060. *
  4061. * @param {Array} array
  4062. * @param {Function} fn
  4063. * @param {Object} scope
  4064. * @api private
  4065. */
  4066. exports.forEach = function(arr, fn, scope){
  4067. for (var i = 0, l = arr.length; i < l; i++)
  4068. fn.call(scope, arr[i], i);
  4069. };
  4070. /**
  4071. * Array#indexOf (<=IE8)
  4072. *
  4073. * @parma {Array} arr
  4074. * @param {Object} obj to find index of
  4075. * @param {Number} start
  4076. * @api private
  4077. */
  4078. exports.indexOf = function(arr, obj, start){
  4079. for (var i = start || 0, l = arr.length; i < l; i++) {
  4080. if (arr[i] === obj)
  4081. return i;
  4082. }
  4083. return -1;
  4084. };
  4085. /**
  4086. * Array#reduce (<=IE8)
  4087. *
  4088. * @param {Array} array
  4089. * @param {Function} fn
  4090. * @param {Object} initial value
  4091. * @api private
  4092. */
  4093. exports.reduce = function(arr, fn, val){
  4094. var rval = val;
  4095. for (var i = 0, l = arr.length; i < l; i++) {
  4096. rval = fn(rval, arr[i], i, arr);
  4097. }
  4098. return rval;
  4099. };
  4100. /**
  4101. * Array#filter (<=IE8)
  4102. *
  4103. * @param {Array} array
  4104. * @param {Function} fn
  4105. * @api private
  4106. */
  4107. exports.filter = function(arr, fn){
  4108. var ret = [];
  4109. for (var i = 0, l = arr.length; i < l; i++) {
  4110. var val = arr[i];
  4111. if (fn(val, i, arr)) ret.push(val);
  4112. }
  4113. return ret;
  4114. };
  4115. /**
  4116. * Object.keys (<=IE8)
  4117. *
  4118. * @param {Object} obj
  4119. * @return {Array} keys
  4120. * @api private
  4121. */
  4122. exports.keys = Object.keys || function(obj) {
  4123. var keys = []
  4124. , has = Object.prototype.hasOwnProperty // for `window` on <=IE8
  4125. for (var key in obj) {
  4126. if (has.call(obj, key)) {
  4127. keys.push(key);
  4128. }
  4129. }
  4130. return keys;
  4131. };
  4132. /**
  4133. * Watch the given `files` for changes
  4134. * and invoke `fn(file)` on modification.
  4135. *
  4136. * @param {Array} files
  4137. * @param {Function} fn
  4138. * @api private
  4139. */
  4140. exports.watch = function(files, fn){
  4141. var options = { interval: 100 };
  4142. files.forEach(function(file){
  4143. debug('file %s', file);
  4144. fs.watchFile(file, options, function(curr, prev){
  4145. if (prev.mtime < curr.mtime) fn(file);
  4146. });
  4147. });
  4148. };
  4149. /**
  4150. * Ignored files.
  4151. */
  4152. function ignored(path){
  4153. return !~ignore.indexOf(path);
  4154. }
  4155. /**
  4156. * Lookup files in the given `dir`.
  4157. *
  4158. * @return {Array}
  4159. * @api private
  4160. */
  4161. exports.files = function(dir, ret){
  4162. ret = ret || [];
  4163. fs.readdirSync(dir)
  4164. .filter(ignored)
  4165. .forEach(function(path){
  4166. path = join(dir, path);
  4167. if (fs.statSync(path).isDirectory()) {
  4168. exports.files(path, ret);
  4169. } else if (path.match(/\.(js|coffee)$/)) {
  4170. ret.push(path);
  4171. }
  4172. });
  4173. return ret;
  4174. };
  4175. /**
  4176. * Compute a slug from the given `str`.
  4177. *
  4178. * @param {String} str
  4179. * @return {String}
  4180. * @api private
  4181. */
  4182. exports.slug = function(str){
  4183. return str
  4184. .toLowerCase()
  4185. .replace(/ +/g, '-')
  4186. .replace(/[^-\w]/g, '');
  4187. };
  4188. /**
  4189. * Strip the function definition from `str`,
  4190. * and re-indent for pre whitespace.
  4191. */
  4192. exports.clean = function(str) {
  4193. str = str
  4194. .replace(/^function *\(.*\) *{/, '')
  4195. .replace(/\s+\}$/, '');
  4196. var spaces = str.match(/^\n?( *)/)[1].length
  4197. , re = new RegExp('^ {' + spaces + '}', 'gm');
  4198. str = str.replace(re, '');
  4199. return exports.trim(str);
  4200. };
  4201. /**
  4202. * Escape regular expression characters in `str`.
  4203. *
  4204. * @param {String} str
  4205. * @return {String}
  4206. * @api private
  4207. */
  4208. exports.escapeRegexp = function(str){
  4209. return str.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&");
  4210. };
  4211. /**
  4212. * Trim the given `str`.
  4213. *
  4214. * @param {String} str
  4215. * @return {String}
  4216. * @api private
  4217. */
  4218. exports.trim = function(str){
  4219. return str.replace(/^\s+|\s+$/g, '');
  4220. };
  4221. /**
  4222. * Parse the given `qs`.
  4223. *
  4224. * @param {String} qs
  4225. * @return {Object}
  4226. * @api private
  4227. */
  4228. exports.parseQuery = function(qs){
  4229. return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair){
  4230. var i = pair.indexOf('=')
  4231. , key = pair.slice(0, i)
  4232. , val = pair.slice(++i);
  4233. obj[key] = decodeURIComponent(val);
  4234. return obj;
  4235. }, {});
  4236. };
  4237. /**
  4238. * Highlight the given string of `js`.
  4239. *
  4240. * @param {String} js
  4241. * @return {String}
  4242. * @api private
  4243. */
  4244. function highlight(js) {
  4245. return js
  4246. .replace(/</g, '&lt;')
  4247. .replace(/>/g, '&gt;')
  4248. .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
  4249. .replace(/('.*?')/gm, '<span class="string">$1</span>')
  4250. .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
  4251. .replace(/(\d+)/gm, '<span class="number">$1</span>')
  4252. .replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
  4253. .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')
  4254. }
  4255. /**
  4256. * Highlight the contents of tag `name`.
  4257. *
  4258. * @param {String} name
  4259. * @api private
  4260. */
  4261. exports.highlightTags = function(name) {
  4262. var code = document.getElementsByTagName(name);
  4263. for (var i = 0, len = code.length; i < len; ++i) {
  4264. code[i].innerHTML = highlight(code[i].innerHTML);
  4265. }
  4266. };
  4267. }); // module: utils.js
  4268. /**
  4269. * Node shims.
  4270. *
  4271. * These are meant only to allow
  4272. * mocha.js to run untouched, not
  4273. * to allow running node code in
  4274. * the browser.
  4275. */
  4276. process = {};
  4277. process.exit = function(status){};
  4278. process.stdout = {};
  4279. global = window;
  4280. /**
  4281. * next tick implementation.
  4282. */
  4283. process.nextTick = (function(){
  4284. // postMessage behaves badly on IE8
  4285. if (window.ActiveXObject || !window.postMessage) {
  4286. return function(fn){ fn() };
  4287. }
  4288. // based on setZeroTimeout by David Baron
  4289. // - http://dbaron.org/log/20100309-faster-timeouts
  4290. var timeouts = []
  4291. , name = 'mocha-zero-timeout'
  4292. window.addEventListener('message', function(e){
  4293. if (e.source == window && e.data == name) {
  4294. if (e.stopPropagation) e.stopPropagation();
  4295. if (timeouts.length) timeouts.shift()();
  4296. }
  4297. }, true);
  4298. return function(fn){
  4299. timeouts.push(fn);
  4300. window.postMessage(name, '*');
  4301. }
  4302. })();
  4303. /**
  4304. * Remove uncaughtException listener.
  4305. */
  4306. process.removeListener = function(e){
  4307. if ('uncaughtException' == e) {
  4308. window.onerror = null;
  4309. }
  4310. };
  4311. /**
  4312. * Implements uncaughtException listener.
  4313. */
  4314. process.on = function(e, fn){
  4315. if ('uncaughtException' == e) {
  4316. window.onerror = function(err, url, line){
  4317. fn(new Error(err + ' (' + url + ':' + line + ')'));
  4318. };
  4319. }
  4320. };
  4321. // boot
  4322. ;(function(){
  4323. /**
  4324. * Expose mocha.
  4325. */
  4326. var Mocha = window.Mocha = require('mocha'),
  4327. mocha = window.mocha = new Mocha({ reporter: 'html' });
  4328. /**
  4329. * Override ui to ensure that the ui functions are initialized.
  4330. * Normally this would happen in Mocha.prototype.loadFiles.
  4331. */
  4332. mocha.ui = function(ui){
  4333. Mocha.prototype.ui.call(this, ui);
  4334. this.suite.emit('pre-require', window, null, this);
  4335. return this;
  4336. };
  4337. /**
  4338. * Setup mocha with the given setting options.
  4339. */
  4340. mocha.setup = function(opts){
  4341. if ('string' == typeof opts) opts = { ui: opts };
  4342. for (var opt in opts) this[opt](opts[opt]);
  4343. return this;
  4344. };
  4345. /**
  4346. * Run mocha, returning the Runner.
  4347. */
  4348. mocha.run = function(fn){
  4349. var options = mocha.options;
  4350. mocha.globals('location');
  4351. var query = Mocha.utils.parseQuery(window.location.search || '');
  4352. if (query.grep) mocha.grep(query.grep);
  4353. if (query.invert) mocha.invert();
  4354. return Mocha.prototype.run.call(mocha, function(){
  4355. Mocha.utils.highlightTags('code');
  4356. if (fn) fn();
  4357. });
  4358. };
  4359. })();
  4360. })();