No Description

mocha.js 128KB

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