mocha.js 111 KB

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