1
0

mocha-1.9.0.js 108 KB

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