mocha.js 117 KB

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