test.js 285 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297
  1. ;(function(){
  2. // CommonJS require()
  3. function require(p){
  4. var path = require.resolve(p)
  5. , mod = require.modules[path];
  6. if (!mod) throw new Error('failed to require "' + p + '"');
  7. if (!mod.exports) {
  8. mod.exports = {};
  9. mod.call(mod.exports, mod, mod.exports, require.relative(path));
  10. }
  11. return mod.exports;
  12. }
  13. require.modules = {};
  14. require.resolve = function (path){
  15. var orig = path
  16. , reg = path + '.js'
  17. , index = path + '/index.js';
  18. return require.modules[reg] && reg
  19. || require.modules[index] && index
  20. || orig;
  21. };
  22. require.register = function (path, fn){
  23. require.modules[path] = fn;
  24. };
  25. require.relative = function (parent) {
  26. return function(p){
  27. if ('.' != p.charAt(0)) return require(p);
  28. var path = parent.split('/')
  29. , segs = p.split('/');
  30. path.pop();
  31. for (var i = 0; i < segs.length; i++) {
  32. var seg = segs[i];
  33. if ('..' == seg) path.pop();
  34. else if ('.' != seg) path.push(seg);
  35. }
  36. return require(path.join('/'));
  37. };
  38. };
  39. require.register("browser/debug.js", function(module, exports, require){
  40. module.exports = function(type){
  41. return function(){
  42. }
  43. };
  44. }); // module: browser/debug.js
  45. require.register("browser/diff.js", function(module, exports, require){
  46. /* See LICENSE file for terms of use */
  47. /*
  48. * Text diff implementation.
  49. *
  50. * This library supports the following APIS:
  51. * JsDiff.diffChars: Character by character diff
  52. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  53. * JsDiff.diffLines: Line based diff
  54. *
  55. * JsDiff.diffCss: Diff targeted at CSS content
  56. *
  57. * These methods are based on the implementation proposed in
  58. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  59. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  60. */
  61. var JsDiff = (function() {
  62. /*jshint maxparams: 5*/
  63. function clonePath(path) {
  64. return { newPos: path.newPos, components: path.components.slice(0) };
  65. }
  66. function removeEmpty(array) {
  67. var ret = [];
  68. for (var i = 0; i < array.length; i++) {
  69. if (array[i]) {
  70. ret.push(array[i]);
  71. }
  72. }
  73. return ret;
  74. }
  75. function escapeHTML(s) {
  76. var n = s;
  77. n = n.replace(/&/g, '&amp;');
  78. n = n.replace(/</g, '&lt;');
  79. n = n.replace(/>/g, '&gt;');
  80. n = n.replace(/"/g, '&quot;');
  81. return n;
  82. }
  83. var Diff = function(ignoreWhitespace) {
  84. this.ignoreWhitespace = ignoreWhitespace;
  85. };
  86. Diff.prototype = {
  87. diff: function(oldString, newString) {
  88. // Handle the identity case (this is due to unrolling editLength == 0
  89. if (newString === oldString) {
  90. return [{ value: newString }];
  91. }
  92. if (!newString) {
  93. return [{ value: oldString, removed: true }];
  94. }
  95. if (!oldString) {
  96. return [{ value: newString, added: true }];
  97. }
  98. newString = this.tokenize(newString);
  99. oldString = this.tokenize(oldString);
  100. var newLen = newString.length, oldLen = oldString.length;
  101. var maxEditLength = newLen + oldLen;
  102. var bestPath = [{ newPos: -1, components: [] }];
  103. // Seed editLength = 0
  104. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  105. if (bestPath[0].newPos+1 >= newLen && oldPos+1 >= oldLen) {
  106. return bestPath[0].components;
  107. }
  108. for (var editLength = 1; editLength <= maxEditLength; editLength++) {
  109. for (var diagonalPath = -1*editLength; diagonalPath <= editLength; diagonalPath+=2) {
  110. var basePath;
  111. var addPath = bestPath[diagonalPath-1],
  112. removePath = bestPath[diagonalPath+1];
  113. oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  114. if (addPath) {
  115. // No one else is going to attempt to use this value, clear it
  116. bestPath[diagonalPath-1] = undefined;
  117. }
  118. var canAdd = addPath && addPath.newPos+1 < newLen;
  119. var canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  120. if (!canAdd && !canRemove) {
  121. bestPath[diagonalPath] = undefined;
  122. continue;
  123. }
  124. // Select the diagonal that we want to branch from. We select the prior
  125. // path whose position in the new string is the farthest from the origin
  126. // and does not pass the bounds of the diff graph
  127. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  128. basePath = clonePath(removePath);
  129. this.pushComponent(basePath.components, oldString[oldPos], undefined, true);
  130. } else {
  131. basePath = clonePath(addPath);
  132. basePath.newPos++;
  133. this.pushComponent(basePath.components, newString[basePath.newPos], true, undefined);
  134. }
  135. var oldPos = this.extractCommon(basePath, newString, oldString, diagonalPath);
  136. if (basePath.newPos+1 >= newLen && oldPos+1 >= oldLen) {
  137. return basePath.components;
  138. } else {
  139. bestPath[diagonalPath] = basePath;
  140. }
  141. }
  142. }
  143. },
  144. pushComponent: function(components, value, added, removed) {
  145. var last = components[components.length-1];
  146. if (last && last.added === added && last.removed === removed) {
  147. // We need to clone here as the component clone operation is just
  148. // as shallow array clone
  149. components[components.length-1] =
  150. {value: this.join(last.value, value), added: added, removed: removed };
  151. } else {
  152. components.push({value: value, added: added, removed: removed });
  153. }
  154. },
  155. extractCommon: function(basePath, newString, oldString, diagonalPath) {
  156. var newLen = newString.length,
  157. oldLen = oldString.length,
  158. newPos = basePath.newPos,
  159. oldPos = newPos - diagonalPath;
  160. while (newPos+1 < newLen && oldPos+1 < oldLen && this.equals(newString[newPos+1], oldString[oldPos+1])) {
  161. newPos++;
  162. oldPos++;
  163. this.pushComponent(basePath.components, newString[newPos], undefined, undefined);
  164. }
  165. basePath.newPos = newPos;
  166. return oldPos;
  167. },
  168. equals: function(left, right) {
  169. var reWhitespace = /\S/;
  170. if (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right)) {
  171. return true;
  172. } else {
  173. return left === right;
  174. }
  175. },
  176. join: function(left, right) {
  177. return left + right;
  178. },
  179. tokenize: function(value) {
  180. return value;
  181. }
  182. };
  183. var CharDiff = new Diff();
  184. var WordDiff = new Diff(true);
  185. var WordWithSpaceDiff = new Diff();
  186. WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) {
  187. return removeEmpty(value.split(/(\s+|\b)/));
  188. };
  189. var CssDiff = new Diff(true);
  190. CssDiff.tokenize = function(value) {
  191. return removeEmpty(value.split(/([{}:;,]|\s+)/));
  192. };
  193. var LineDiff = new Diff();
  194. LineDiff.tokenize = function(value) {
  195. return value.split(/^/m);
  196. };
  197. return {
  198. Diff: Diff,
  199. diffChars: function(oldStr, newStr) { return CharDiff.diff(oldStr, newStr); },
  200. diffWords: function(oldStr, newStr) { return WordDiff.diff(oldStr, newStr); },
  201. diffWordsWithSpace: function(oldStr, newStr) { return WordWithSpaceDiff.diff(oldStr, newStr); },
  202. diffLines: function(oldStr, newStr) { return LineDiff.diff(oldStr, newStr); },
  203. diffCss: function(oldStr, newStr) { return CssDiff.diff(oldStr, newStr); },
  204. createPatch: function(fileName, oldStr, newStr, oldHeader, newHeader) {
  205. var ret = [];
  206. ret.push('Index: ' + fileName);
  207. ret.push('===================================================================');
  208. ret.push('--- ' + fileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader));
  209. ret.push('+++ ' + fileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader));
  210. var diff = LineDiff.diff(oldStr, newStr);
  211. if (!diff[diff.length-1].value) {
  212. diff.pop(); // Remove trailing newline add
  213. }
  214. diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier
  215. function contextLines(lines) {
  216. return lines.map(function(entry) { return ' ' + entry; });
  217. }
  218. function eofNL(curRange, i, current) {
  219. var last = diff[diff.length-2],
  220. isLast = i === diff.length-2,
  221. isLastOfType = i === diff.length-3 && (current.added !== last.added || current.removed !== last.removed);
  222. // Figure out if this is the last line for the given file and missing NL
  223. if (!/\n$/.test(current.value) && (isLast || isLastOfType)) {
  224. curRange.push('\\ No newline at end of file');
  225. }
  226. }
  227. var oldRangeStart = 0, newRangeStart = 0, curRange = [],
  228. oldLine = 1, newLine = 1;
  229. for (var i = 0; i < diff.length; i++) {
  230. var current = diff[i],
  231. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  232. current.lines = lines;
  233. if (current.added || current.removed) {
  234. if (!oldRangeStart) {
  235. var prev = diff[i-1];
  236. oldRangeStart = oldLine;
  237. newRangeStart = newLine;
  238. if (prev) {
  239. curRange = contextLines(prev.lines.slice(-4));
  240. oldRangeStart -= curRange.length;
  241. newRangeStart -= curRange.length;
  242. }
  243. }
  244. curRange.push.apply(curRange, lines.map(function(entry) { return (current.added?'+':'-') + entry; }));
  245. eofNL(curRange, i, current);
  246. if (current.added) {
  247. newLine += lines.length;
  248. } else {
  249. oldLine += lines.length;
  250. }
  251. } else {
  252. if (oldRangeStart) {
  253. // Close out any changes that have been output (or join overlapping)
  254. if (lines.length <= 8 && i < diff.length-2) {
  255. // Overlapping
  256. curRange.push.apply(curRange, contextLines(lines));
  257. } else {
  258. // end the range and output
  259. var contextSize = Math.min(lines.length, 4);
  260. ret.push(
  261. '@@ -' + oldRangeStart + ',' + (oldLine-oldRangeStart+contextSize)
  262. + ' +' + newRangeStart + ',' + (newLine-newRangeStart+contextSize)
  263. + ' @@');
  264. ret.push.apply(ret, curRange);
  265. ret.push.apply(ret, contextLines(lines.slice(0, contextSize)));
  266. if (lines.length <= 4) {
  267. eofNL(ret, i, current);
  268. }
  269. oldRangeStart = 0; newRangeStart = 0; curRange = [];
  270. }
  271. }
  272. oldLine += lines.length;
  273. newLine += lines.length;
  274. }
  275. }
  276. return ret.join('\n') + '\n';
  277. },
  278. applyPatch: function(oldStr, uniDiff) {
  279. var diffstr = uniDiff.split('\n');
  280. var diff = [];
  281. var remEOFNL = false,
  282. addEOFNL = false;
  283. for (var i = (diffstr[0][0]==='I'?4:0); i < diffstr.length; i++) {
  284. if(diffstr[i][0] === '@') {
  285. var meh = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);
  286. diff.unshift({
  287. start:meh[3],
  288. oldlength:meh[2],
  289. oldlines:[],
  290. newlength:meh[4],
  291. newlines:[]
  292. });
  293. } else if(diffstr[i][0] === '+') {
  294. diff[0].newlines.push(diffstr[i].substr(1));
  295. } else if(diffstr[i][0] === '-') {
  296. diff[0].oldlines.push(diffstr[i].substr(1));
  297. } else if(diffstr[i][0] === ' ') {
  298. diff[0].newlines.push(diffstr[i].substr(1));
  299. diff[0].oldlines.push(diffstr[i].substr(1));
  300. } else if(diffstr[i][0] === '\\') {
  301. if (diffstr[i-1][0] === '+') {
  302. remEOFNL = true;
  303. } else if(diffstr[i-1][0] === '-') {
  304. addEOFNL = true;
  305. }
  306. }
  307. }
  308. var str = oldStr.split('\n');
  309. for (var i = diff.length - 1; i >= 0; i--) {
  310. var d = diff[i];
  311. for (var j = 0; j < d.oldlength; j++) {
  312. if(str[d.start-1+j] !== d.oldlines[j]) {
  313. return false;
  314. }
  315. }
  316. Array.prototype.splice.apply(str,[d.start-1,+d.oldlength].concat(d.newlines));
  317. }
  318. if (remEOFNL) {
  319. while (!str[str.length-1]) {
  320. str.pop();
  321. }
  322. } else if (addEOFNL) {
  323. str.push('');
  324. }
  325. return str.join('\n');
  326. },
  327. convertChangesToXML: function(changes){
  328. var ret = [];
  329. for ( var i = 0; i < changes.length; i++) {
  330. var change = changes[i];
  331. if (change.added) {
  332. ret.push('<ins>');
  333. } else if (change.removed) {
  334. ret.push('<del>');
  335. }
  336. ret.push(escapeHTML(change.value));
  337. if (change.added) {
  338. ret.push('</ins>');
  339. } else if (change.removed) {
  340. ret.push('</del>');
  341. }
  342. }
  343. return ret.join('');
  344. },
  345. // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  346. convertChangesToDMP: function(changes){
  347. var ret = [], change;
  348. for ( var i = 0; i < changes.length; i++) {
  349. change = changes[i];
  350. ret.push([(change.added ? 1 : change.removed ? -1 : 0), change.value]);
  351. }
  352. return ret;
  353. }
  354. };
  355. })();
  356. if (typeof module !== 'undefined') {
  357. module.exports = JsDiff;
  358. }
  359. }); // module: browser/diff.js
  360. require.register("browser/escape-string-regexp.js", function(module, exports, require){
  361. 'use strict';
  362. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  363. module.exports = function (str) {
  364. if (typeof str !== 'string') {
  365. throw new TypeError('Expected a string');
  366. }
  367. return str.replace(matchOperatorsRe, '\\$&');
  368. };
  369. }); // module: browser/escape-string-regexp.js
  370. require.register("browser/events.js", function(module, exports, require){
  371. /**
  372. * Module exports.
  373. */
  374. exports.EventEmitter = EventEmitter;
  375. /**
  376. * Check if `obj` is an array.
  377. */
  378. function isArray(obj) {
  379. return '[object Array]' == {}.toString.call(obj);
  380. }
  381. /**
  382. * Event emitter constructor.
  383. *
  384. * @api public
  385. */
  386. function EventEmitter(){};
  387. /**
  388. * Adds a listener.
  389. *
  390. * @api public
  391. */
  392. EventEmitter.prototype.on = function (name, fn) {
  393. if (!this.$events) {
  394. this.$events = {};
  395. }
  396. if (!this.$events[name]) {
  397. this.$events[name] = fn;
  398. } else if (isArray(this.$events[name])) {
  399. this.$events[name].push(fn);
  400. } else {
  401. this.$events[name] = [this.$events[name], fn];
  402. }
  403. return this;
  404. };
  405. EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  406. /**
  407. * Adds a volatile listener.
  408. *
  409. * @api public
  410. */
  411. EventEmitter.prototype.once = function (name, fn) {
  412. var self = this;
  413. function on () {
  414. self.removeListener(name, on);
  415. fn.apply(this, arguments);
  416. };
  417. on.listener = fn;
  418. this.on(name, on);
  419. return this;
  420. };
  421. /**
  422. * Removes a listener.
  423. *
  424. * @api public
  425. */
  426. EventEmitter.prototype.removeListener = function (name, fn) {
  427. if (this.$events && this.$events[name]) {
  428. var list = this.$events[name];
  429. if (isArray(list)) {
  430. var pos = -1;
  431. for (var i = 0, l = list.length; i < l; i++) {
  432. if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
  433. pos = i;
  434. break;
  435. }
  436. }
  437. if (pos < 0) {
  438. return this;
  439. }
  440. list.splice(pos, 1);
  441. if (!list.length) {
  442. delete this.$events[name];
  443. }
  444. } else if (list === fn || (list.listener && list.listener === fn)) {
  445. delete this.$events[name];
  446. }
  447. }
  448. return this;
  449. };
  450. /**
  451. * Removes all listeners for an event.
  452. *
  453. * @api public
  454. */
  455. EventEmitter.prototype.removeAllListeners = function (name) {
  456. if (name === undefined) {
  457. this.$events = {};
  458. return this;
  459. }
  460. if (this.$events && this.$events[name]) {
  461. this.$events[name] = null;
  462. }
  463. return this;
  464. };
  465. /**
  466. * Gets all listeners for a certain event.
  467. *
  468. * @api public
  469. */
  470. EventEmitter.prototype.listeners = function (name) {
  471. if (!this.$events) {
  472. this.$events = {};
  473. }
  474. if (!this.$events[name]) {
  475. this.$events[name] = [];
  476. }
  477. if (!isArray(this.$events[name])) {
  478. this.$events[name] = [this.$events[name]];
  479. }
  480. return this.$events[name];
  481. };
  482. /**
  483. * Emits an event.
  484. *
  485. * @api public
  486. */
  487. EventEmitter.prototype.emit = function (name) {
  488. if (!this.$events) {
  489. return false;
  490. }
  491. var handler = this.$events[name];
  492. if (!handler) {
  493. return false;
  494. }
  495. var args = [].slice.call(arguments, 1);
  496. if ('function' == typeof handler) {
  497. handler.apply(this, args);
  498. } else if (isArray(handler)) {
  499. var listeners = handler.slice();
  500. for (var i = 0, l = listeners.length; i < l; i++) {
  501. listeners[i].apply(this, args);
  502. }
  503. } else {
  504. return false;
  505. }
  506. return true;
  507. };
  508. }); // module: browser/events.js
  509. require.register("browser/fs.js", function(module, exports, require){
  510. }); // module: browser/fs.js
  511. require.register("browser/glob.js", function(module, exports, require){
  512. }); // module: browser/glob.js
  513. require.register("browser/path.js", function(module, exports, require){
  514. }); // module: browser/path.js
  515. require.register("browser/progress.js", function(module, exports, require){
  516. /**
  517. * Expose `Progress`.
  518. */
  519. module.exports = Progress;
  520. /**
  521. * Initialize a new `Progress` indicator.
  522. */
  523. function Progress() {
  524. this.percent = 0;
  525. this.size(0);
  526. this.fontSize(11);
  527. this.font('helvetica, arial, sans-serif');
  528. }
  529. /**
  530. * Set progress size to `n`.
  531. *
  532. * @param {Number} n
  533. * @return {Progress} for chaining
  534. * @api public
  535. */
  536. Progress.prototype.size = function(n){
  537. this._size = n;
  538. return this;
  539. };
  540. /**
  541. * Set text to `str`.
  542. *
  543. * @param {String} str
  544. * @return {Progress} for chaining
  545. * @api public
  546. */
  547. Progress.prototype.text = function(str){
  548. this._text = str;
  549. return this;
  550. };
  551. /**
  552. * Set font size to `n`.
  553. *
  554. * @param {Number} n
  555. * @return {Progress} for chaining
  556. * @api public
  557. */
  558. Progress.prototype.fontSize = function(n){
  559. this._fontSize = n;
  560. return this;
  561. };
  562. /**
  563. * Set font `family`.
  564. *
  565. * @param {String} family
  566. * @return {Progress} for chaining
  567. */
  568. Progress.prototype.font = function(family){
  569. this._font = family;
  570. return this;
  571. };
  572. /**
  573. * Update percentage to `n`.
  574. *
  575. * @param {Number} n
  576. * @return {Progress} for chaining
  577. */
  578. Progress.prototype.update = function(n){
  579. this.percent = n;
  580. return this;
  581. };
  582. /**
  583. * Draw on `ctx`.
  584. *
  585. * @param {CanvasRenderingContext2d} ctx
  586. * @return {Progress} for chaining
  587. */
  588. Progress.prototype.draw = function(ctx){
  589. try {
  590. var percent = Math.min(this.percent, 100)
  591. , size = this._size
  592. , half = size / 2
  593. , x = half
  594. , y = half
  595. , rad = half - 1
  596. , fontSize = this._fontSize;
  597. ctx.font = fontSize + 'px ' + this._font;
  598. var angle = Math.PI * 2 * (percent / 100);
  599. ctx.clearRect(0, 0, size, size);
  600. // outer circle
  601. ctx.strokeStyle = '#9f9f9f';
  602. ctx.beginPath();
  603. ctx.arc(x, y, rad, 0, angle, false);
  604. ctx.stroke();
  605. // inner circle
  606. ctx.strokeStyle = '#eee';
  607. ctx.beginPath();
  608. ctx.arc(x, y, rad - 1, 0, angle, true);
  609. ctx.stroke();
  610. // text
  611. var text = this._text || (percent | 0) + '%'
  612. , w = ctx.measureText(text).width;
  613. ctx.fillText(
  614. text
  615. , x - w / 2 + 1
  616. , y + fontSize / 2 - 1);
  617. } catch (ex) {} //don't fail if we can't render progress
  618. return this;
  619. };
  620. }); // module: browser/progress.js
  621. require.register("browser/tty.js", function(module, exports, require){
  622. exports.isatty = function(){
  623. return true;
  624. };
  625. exports.getWindowSize = function(){
  626. if ('innerHeight' in global) {
  627. return [global.innerHeight, global.innerWidth];
  628. } else {
  629. // In a Web Worker, the DOM Window is not available.
  630. return [640, 480];
  631. }
  632. };
  633. }); // module: browser/tty.js
  634. require.register("context.js", function(module, exports, require){
  635. /**
  636. * Expose `Context`.
  637. */
  638. module.exports = Context;
  639. /**
  640. * Initialize a new `Context`.
  641. *
  642. * @api private
  643. */
  644. function Context(){}
  645. /**
  646. * Set or get the context `Runnable` to `runnable`.
  647. *
  648. * @param {Runnable} runnable
  649. * @return {Context}
  650. * @api private
  651. */
  652. Context.prototype.runnable = function(runnable){
  653. if (0 == arguments.length) return this._runnable;
  654. this.test = this._runnable = runnable;
  655. return this;
  656. };
  657. /**
  658. * Set test timeout `ms`.
  659. *
  660. * @param {Number} ms
  661. * @return {Context} self
  662. * @api private
  663. */
  664. Context.prototype.timeout = function(ms){
  665. if (arguments.length === 0) return this.runnable().timeout();
  666. this.runnable().timeout(ms);
  667. return this;
  668. };
  669. /**
  670. * Set test timeout `enabled`.
  671. *
  672. * @param {Boolean} enabled
  673. * @return {Context} self
  674. * @api private
  675. */
  676. Context.prototype.enableTimeouts = function (enabled) {
  677. this.runnable().enableTimeouts(enabled);
  678. return this;
  679. };
  680. /**
  681. * Set test slowness threshold `ms`.
  682. *
  683. * @param {Number} ms
  684. * @return {Context} self
  685. * @api private
  686. */
  687. Context.prototype.slow = function(ms){
  688. this.runnable().slow(ms);
  689. return this;
  690. };
  691. /**
  692. * Inspect the context void of `._runnable`.
  693. *
  694. * @return {String}
  695. * @api private
  696. */
  697. Context.prototype.inspect = function(){
  698. return JSON.stringify(this, function(key, val){
  699. if ('_runnable' == key) return;
  700. if ('test' == key) return;
  701. return val;
  702. }, 2);
  703. };
  704. }); // module: context.js
  705. require.register("hook.js", function(module, exports, require){
  706. /**
  707. * Module dependencies.
  708. */
  709. var Runnable = require('./runnable');
  710. /**
  711. * Expose `Hook`.
  712. */
  713. module.exports = Hook;
  714. /**
  715. * Initialize a new `Hook` with the given `title` and callback `fn`.
  716. *
  717. * @param {String} title
  718. * @param {Function} fn
  719. * @api private
  720. */
  721. function Hook(title, fn) {
  722. Runnable.call(this, title, fn);
  723. this.type = 'hook';
  724. }
  725. /**
  726. * Inherit from `Runnable.prototype`.
  727. */
  728. function F(){};
  729. F.prototype = Runnable.prototype;
  730. Hook.prototype = new F;
  731. Hook.prototype.constructor = Hook;
  732. /**
  733. * Get or set the test `err`.
  734. *
  735. * @param {Error} err
  736. * @return {Error}
  737. * @api public
  738. */
  739. Hook.prototype.error = function(err){
  740. if (0 == arguments.length) {
  741. var err = this._error;
  742. this._error = null;
  743. return err;
  744. }
  745. this._error = err;
  746. };
  747. }); // module: hook.js
  748. require.register("interfaces/bdd.js", function(module, exports, require){
  749. /**
  750. * Module dependencies.
  751. */
  752. var Suite = require('../suite')
  753. , Test = require('../test')
  754. , utils = require('../utils')
  755. , escapeRe = require('browser/escape-string-regexp');
  756. /**
  757. * BDD-style interface:
  758. *
  759. * describe('Array', function(){
  760. * describe('#indexOf()', function(){
  761. * it('should return -1 when not present', function(){
  762. *
  763. * });
  764. *
  765. * it('should return the index when present', function(){
  766. *
  767. * });
  768. * });
  769. * });
  770. *
  771. */
  772. module.exports = function(suite){
  773. var suites = [suite];
  774. suite.on('pre-require', function(context, file, mocha){
  775. /**
  776. * Execute before running tests.
  777. */
  778. context.before = function(name, fn){
  779. suites[0].beforeAll(name, fn);
  780. };
  781. /**
  782. * Execute after running tests.
  783. */
  784. context.after = function(name, fn){
  785. suites[0].afterAll(name, fn);
  786. };
  787. /**
  788. * Execute before each test case.
  789. */
  790. context.beforeEach = function(name, fn){
  791. suites[0].beforeEach(name, fn);
  792. };
  793. /**
  794. * Execute after each test case.
  795. */
  796. context.afterEach = function(name, fn){
  797. suites[0].afterEach(name, fn);
  798. };
  799. /**
  800. * Describe a "suite" with the given `title`
  801. * and callback `fn` containing nested suites
  802. * and/or tests.
  803. */
  804. context.describe = context.context = function(title, fn){
  805. var suite = Suite.create(suites[0], title);
  806. suite.file = file;
  807. suites.unshift(suite);
  808. fn.call(suite);
  809. suites.shift();
  810. return suite;
  811. };
  812. /**
  813. * Pending describe.
  814. */
  815. context.xdescribe =
  816. context.xcontext =
  817. context.describe.skip = function(title, fn){
  818. var suite = Suite.create(suites[0], title);
  819. suite.pending = true;
  820. suites.unshift(suite);
  821. fn.call(suite);
  822. suites.shift();
  823. };
  824. /**
  825. * Exclusive suite.
  826. */
  827. context.describe.only = function(title, fn){
  828. var suite = context.describe(title, fn);
  829. mocha.grep(suite.fullTitle());
  830. return suite;
  831. };
  832. /**
  833. * Describe a specification or test-case
  834. * with the given `title` and callback `fn`
  835. * acting as a thunk.
  836. */
  837. context.it = context.specify = function(title, fn){
  838. var suite = suites[0];
  839. if (suite.pending) fn = null;
  840. var test = new Test(title, fn);
  841. test.file = file;
  842. suite.addTest(test);
  843. return test;
  844. };
  845. /**
  846. * Exclusive test-case.
  847. */
  848. context.it.only = function(title, fn){
  849. var test = context.it(title, fn);
  850. var reString = '^' + escapeRe(test.fullTitle()) + '$';
  851. mocha.grep(new RegExp(reString));
  852. return test;
  853. };
  854. /**
  855. * Pending test case.
  856. */
  857. context.xit =
  858. context.xspecify =
  859. context.it.skip = function(title){
  860. context.it(title);
  861. };
  862. });
  863. };
  864. }); // module: interfaces/bdd.js
  865. require.register("interfaces/exports.js", function(module, exports, require){
  866. /**
  867. * Module dependencies.
  868. */
  869. var Suite = require('../suite')
  870. , Test = require('../test');
  871. /**
  872. * TDD-style interface:
  873. *
  874. * exports.Array = {
  875. * '#indexOf()': {
  876. * 'should return -1 when the value is not present': function(){
  877. *
  878. * },
  879. *
  880. * 'should return the correct index when the value is present': function(){
  881. *
  882. * }
  883. * }
  884. * };
  885. *
  886. */
  887. module.exports = function(suite){
  888. var suites = [suite];
  889. suite.on('require', visit);
  890. function visit(obj, file) {
  891. var suite;
  892. for (var key in obj) {
  893. if ('function' == typeof obj[key]) {
  894. var fn = obj[key];
  895. switch (key) {
  896. case 'before':
  897. suites[0].beforeAll(fn);
  898. break;
  899. case 'after':
  900. suites[0].afterAll(fn);
  901. break;
  902. case 'beforeEach':
  903. suites[0].beforeEach(fn);
  904. break;
  905. case 'afterEach':
  906. suites[0].afterEach(fn);
  907. break;
  908. default:
  909. var test = new Test(key, fn);
  910. test.file = file;
  911. suites[0].addTest(test);
  912. }
  913. } else {
  914. suite = Suite.create(suites[0], key);
  915. suites.unshift(suite);
  916. visit(obj[key]);
  917. suites.shift();
  918. }
  919. }
  920. }
  921. };
  922. }); // module: interfaces/exports.js
  923. require.register("interfaces/index.js", function(module, exports, require){
  924. exports.bdd = require('./bdd');
  925. exports.tdd = require('./tdd');
  926. exports.qunit = require('./qunit');
  927. exports.exports = require('./exports');
  928. }); // module: interfaces/index.js
  929. require.register("interfaces/qunit.js", function(module, exports, require){
  930. /**
  931. * Module dependencies.
  932. */
  933. var Suite = require('../suite')
  934. , Test = require('../test')
  935. , escapeRe = require('browser/escape-string-regexp')
  936. , utils = require('../utils');
  937. /**
  938. * QUnit-style interface:
  939. *
  940. * suite('Array');
  941. *
  942. * test('#length', function(){
  943. * var arr = [1,2,3];
  944. * ok(arr.length == 3);
  945. * });
  946. *
  947. * test('#indexOf()', function(){
  948. * var arr = [1,2,3];
  949. * ok(arr.indexOf(1) == 0);
  950. * ok(arr.indexOf(2) == 1);
  951. * ok(arr.indexOf(3) == 2);
  952. * });
  953. *
  954. * suite('String');
  955. *
  956. * test('#length', function(){
  957. * ok('foo'.length == 3);
  958. * });
  959. *
  960. */
  961. module.exports = function(suite){
  962. var suites = [suite];
  963. suite.on('pre-require', function(context, file, mocha){
  964. /**
  965. * Execute before running tests.
  966. */
  967. context.before = function(name, fn){
  968. suites[0].beforeAll(name, fn);
  969. };
  970. /**
  971. * Execute after running tests.
  972. */
  973. context.after = function(name, fn){
  974. suites[0].afterAll(name, fn);
  975. };
  976. /**
  977. * Execute before each test case.
  978. */
  979. context.beforeEach = function(name, fn){
  980. suites[0].beforeEach(name, fn);
  981. };
  982. /**
  983. * Execute after each test case.
  984. */
  985. context.afterEach = function(name, fn){
  986. suites[0].afterEach(name, fn);
  987. };
  988. /**
  989. * Describe a "suite" with the given `title`.
  990. */
  991. context.suite = function(title){
  992. if (suites.length > 1) suites.shift();
  993. var suite = Suite.create(suites[0], title);
  994. suite.file = file;
  995. suites.unshift(suite);
  996. return suite;
  997. };
  998. /**
  999. * Exclusive test-case.
  1000. */
  1001. context.suite.only = function(title, fn){
  1002. var suite = context.suite(title, fn);
  1003. mocha.grep(suite.fullTitle());
  1004. };
  1005. /**
  1006. * Describe a specification or test-case
  1007. * with the given `title` and callback `fn`
  1008. * acting as a thunk.
  1009. */
  1010. context.test = function(title, fn){
  1011. var test = new Test(title, fn);
  1012. test.file = file;
  1013. suites[0].addTest(test);
  1014. return test;
  1015. };
  1016. /**
  1017. * Exclusive test-case.
  1018. */
  1019. context.test.only = function(title, fn){
  1020. var test = context.test(title, fn);
  1021. var reString = '^' + escapeRe(test.fullTitle()) + '$';
  1022. mocha.grep(new RegExp(reString));
  1023. };
  1024. /**
  1025. * Pending test case.
  1026. */
  1027. context.test.skip = function(title){
  1028. context.test(title);
  1029. };
  1030. });
  1031. };
  1032. }); // module: interfaces/qunit.js
  1033. require.register("interfaces/tdd.js", function(module, exports, require){
  1034. /**
  1035. * Module dependencies.
  1036. */
  1037. var Suite = require('../suite')
  1038. , Test = require('../test')
  1039. , escapeRe = require('browser/escape-string-regexp')
  1040. , utils = require('../utils');
  1041. /**
  1042. * TDD-style interface:
  1043. *
  1044. * suite('Array', function(){
  1045. * suite('#indexOf()', function(){
  1046. * suiteSetup(function(){
  1047. *
  1048. * });
  1049. *
  1050. * test('should return -1 when not present', function(){
  1051. *
  1052. * });
  1053. *
  1054. * test('should return the index when present', function(){
  1055. *
  1056. * });
  1057. *
  1058. * suiteTeardown(function(){
  1059. *
  1060. * });
  1061. * });
  1062. * });
  1063. *
  1064. */
  1065. module.exports = function(suite){
  1066. var suites = [suite];
  1067. suite.on('pre-require', function(context, file, mocha){
  1068. /**
  1069. * Execute before each test case.
  1070. */
  1071. context.setup = function(name, fn){
  1072. suites[0].beforeEach(name, fn);
  1073. };
  1074. /**
  1075. * Execute after each test case.
  1076. */
  1077. context.teardown = function(name, fn){
  1078. suites[0].afterEach(name, fn);
  1079. };
  1080. /**
  1081. * Execute before the suite.
  1082. */
  1083. context.suiteSetup = function(name, fn){
  1084. suites[0].beforeAll(name, fn);
  1085. };
  1086. /**
  1087. * Execute after the suite.
  1088. */
  1089. context.suiteTeardown = function(name, fn){
  1090. suites[0].afterAll(name, fn);
  1091. };
  1092. /**
  1093. * Describe a "suite" with the given `title`
  1094. * and callback `fn` containing nested suites
  1095. * and/or tests.
  1096. */
  1097. context.suite = function(title, fn){
  1098. var suite = Suite.create(suites[0], title);
  1099. suite.file = file;
  1100. suites.unshift(suite);
  1101. fn.call(suite);
  1102. suites.shift();
  1103. return suite;
  1104. };
  1105. /**
  1106. * Pending suite.
  1107. */
  1108. context.suite.skip = function(title, fn) {
  1109. var suite = Suite.create(suites[0], title);
  1110. suite.pending = true;
  1111. suites.unshift(suite);
  1112. fn.call(suite);
  1113. suites.shift();
  1114. };
  1115. /**
  1116. * Exclusive test-case.
  1117. */
  1118. context.suite.only = function(title, fn){
  1119. var suite = context.suite(title, fn);
  1120. mocha.grep(suite.fullTitle());
  1121. };
  1122. /**
  1123. * Describe a specification or test-case
  1124. * with the given `title` and callback `fn`
  1125. * acting as a thunk.
  1126. */
  1127. context.test = function(title, fn){
  1128. var suite = suites[0];
  1129. if (suite.pending) fn = null;
  1130. var test = new Test(title, fn);
  1131. test.file = file;
  1132. suite.addTest(test);
  1133. return test;
  1134. };
  1135. /**
  1136. * Exclusive test-case.
  1137. */
  1138. context.test.only = function(title, fn){
  1139. var test = context.test(title, fn);
  1140. var reString = '^' + escapeRe(test.fullTitle()) + '$';
  1141. mocha.grep(new RegExp(reString));
  1142. };
  1143. /**
  1144. * Pending test case.
  1145. */
  1146. context.test.skip = function(title){
  1147. context.test(title);
  1148. };
  1149. });
  1150. };
  1151. }); // module: interfaces/tdd.js
  1152. require.register("mocha.js", function(module, exports, require){
  1153. /*!
  1154. * mocha
  1155. * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
  1156. * MIT Licensed
  1157. */
  1158. /**
  1159. * Module dependencies.
  1160. */
  1161. var path = require('browser/path')
  1162. , escapeRe = require('browser/escape-string-regexp')
  1163. , utils = require('./utils');
  1164. /**
  1165. * Expose `Mocha`.
  1166. */
  1167. exports = module.exports = Mocha;
  1168. /**
  1169. * To require local UIs and reporters when running in node.
  1170. */
  1171. if (typeof process !== 'undefined' && typeof process.cwd === 'function') {
  1172. var join = path.join
  1173. , cwd = process.cwd();
  1174. module.paths.push(cwd, join(cwd, 'node_modules'));
  1175. }
  1176. /**
  1177. * Expose internals.
  1178. */
  1179. exports.utils = utils;
  1180. exports.interfaces = require('./interfaces');
  1181. exports.reporters = require('./reporters');
  1182. exports.Runnable = require('./runnable');
  1183. exports.Context = require('./context');
  1184. exports.Runner = require('./runner');
  1185. exports.Suite = require('./suite');
  1186. exports.Hook = require('./hook');
  1187. exports.Test = require('./test');
  1188. /**
  1189. * Return image `name` path.
  1190. *
  1191. * @param {String} name
  1192. * @return {String}
  1193. * @api private
  1194. */
  1195. function image(name) {
  1196. return __dirname + '/../images/' + name + '.png';
  1197. }
  1198. /**
  1199. * Setup mocha with `options`.
  1200. *
  1201. * Options:
  1202. *
  1203. * - `ui` name "bdd", "tdd", "exports" etc
  1204. * - `reporter` reporter instance, defaults to `mocha.reporters.spec`
  1205. * - `globals` array of accepted globals
  1206. * - `timeout` timeout in milliseconds
  1207. * - `bail` bail on the first test failure
  1208. * - `slow` milliseconds to wait before considering a test slow
  1209. * - `ignoreLeaks` ignore global leaks
  1210. * - `grep` string or regexp to filter tests with
  1211. *
  1212. * @param {Object} options
  1213. * @api public
  1214. */
  1215. function Mocha(options) {
  1216. options = options || {};
  1217. this.files = [];
  1218. this.options = options;
  1219. this.grep(options.grep);
  1220. this.suite = new exports.Suite('', new exports.Context);
  1221. this.ui(options.ui);
  1222. this.bail(options.bail);
  1223. this.reporter(options.reporter);
  1224. if (null != options.timeout) this.timeout(options.timeout);
  1225. this.useColors(options.useColors)
  1226. if (options.enableTimeouts !== null) this.enableTimeouts(options.enableTimeouts);
  1227. if (options.slow) this.slow(options.slow);
  1228. this.suite.on('pre-require', function (context) {
  1229. exports.afterEach = context.afterEach || context.teardown;
  1230. exports.after = context.after || context.suiteTeardown;
  1231. exports.beforeEach = context.beforeEach || context.setup;
  1232. exports.before = context.before || context.suiteSetup;
  1233. exports.describe = context.describe || context.suite;
  1234. exports.it = context.it || context.test;
  1235. exports.setup = context.setup || context.beforeEach;
  1236. exports.suiteSetup = context.suiteSetup || context.before;
  1237. exports.suiteTeardown = context.suiteTeardown || context.after;
  1238. exports.suite = context.suite || context.describe;
  1239. exports.teardown = context.teardown || context.afterEach;
  1240. exports.test = context.test || context.it;
  1241. });
  1242. }
  1243. /**
  1244. * Enable or disable bailing on the first failure.
  1245. *
  1246. * @param {Boolean} [bail]
  1247. * @api public
  1248. */
  1249. Mocha.prototype.bail = function(bail){
  1250. if (0 == arguments.length) bail = true;
  1251. this.suite.bail(bail);
  1252. return this;
  1253. };
  1254. /**
  1255. * Add test `file`.
  1256. *
  1257. * @param {String} file
  1258. * @api public
  1259. */
  1260. Mocha.prototype.addFile = function(file){
  1261. this.files.push(file);
  1262. return this;
  1263. };
  1264. /**
  1265. * Set reporter to `reporter`, defaults to "spec".
  1266. *
  1267. * @param {String|Function} reporter name or constructor
  1268. * @api public
  1269. */
  1270. Mocha.prototype.reporter = function(reporter){
  1271. if ('function' == typeof reporter) {
  1272. this._reporter = reporter;
  1273. } else {
  1274. reporter = reporter || 'spec';
  1275. var _reporter;
  1276. try { _reporter = require('./reporters/' + reporter); } catch (err) {};
  1277. if (!_reporter) try { _reporter = require(reporter); } catch (err) {};
  1278. if (!_reporter && reporter === 'teamcity')
  1279. console.warn('The Teamcity reporter was moved to a package named ' +
  1280. 'mocha-teamcity-reporter ' +
  1281. '(https://npmjs.org/package/mocha-teamcity-reporter).');
  1282. if (!_reporter) throw new Error('invalid reporter "' + reporter + '"');
  1283. this._reporter = _reporter;
  1284. }
  1285. return this;
  1286. };
  1287. /**
  1288. * Set test UI `name`, defaults to "bdd".
  1289. *
  1290. * @param {String} bdd
  1291. * @api public
  1292. */
  1293. Mocha.prototype.ui = function(name){
  1294. name = name || 'bdd';
  1295. this._ui = exports.interfaces[name];
  1296. if (!this._ui) try { this._ui = require(name); } catch (err) {};
  1297. if (!this._ui) throw new Error('invalid interface "' + name + '"');
  1298. this._ui = this._ui(this.suite);
  1299. return this;
  1300. };
  1301. /**
  1302. * Load registered files.
  1303. *
  1304. * @api private
  1305. */
  1306. Mocha.prototype.loadFiles = function(fn){
  1307. var self = this;
  1308. var suite = this.suite;
  1309. var pending = this.files.length;
  1310. this.files.forEach(function(file){
  1311. file = path.resolve(file);
  1312. suite.emit('pre-require', global, file, self);
  1313. suite.emit('require', require(file), file, self);
  1314. suite.emit('post-require', global, file, self);
  1315. --pending || (fn && fn());
  1316. });
  1317. };
  1318. /**
  1319. * Enable growl support.
  1320. *
  1321. * @api private
  1322. */
  1323. Mocha.prototype._growl = function(runner, reporter) {
  1324. var notify = require('growl');
  1325. runner.on('end', function(){
  1326. var stats = reporter.stats;
  1327. if (stats.failures) {
  1328. var msg = stats.failures + ' of ' + runner.total + ' tests failed';
  1329. notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
  1330. } else {
  1331. notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
  1332. name: 'mocha'
  1333. , title: 'Passed'
  1334. , image: image('ok')
  1335. });
  1336. }
  1337. });
  1338. };
  1339. /**
  1340. * Add regexp to grep, if `re` is a string it is escaped.
  1341. *
  1342. * @param {RegExp|String} re
  1343. * @return {Mocha}
  1344. * @api public
  1345. */
  1346. Mocha.prototype.grep = function(re){
  1347. this.options.grep = 'string' == typeof re
  1348. ? new RegExp(escapeRe(re))
  1349. : re;
  1350. return this;
  1351. };
  1352. /**
  1353. * Invert `.grep()` matches.
  1354. *
  1355. * @return {Mocha}
  1356. * @api public
  1357. */
  1358. Mocha.prototype.invert = function(){
  1359. this.options.invert = true;
  1360. return this;
  1361. };
  1362. /**
  1363. * Ignore global leaks.
  1364. *
  1365. * @param {Boolean} ignore
  1366. * @return {Mocha}
  1367. * @api public
  1368. */
  1369. Mocha.prototype.ignoreLeaks = function(ignore){
  1370. this.options.ignoreLeaks = !!ignore;
  1371. return this;
  1372. };
  1373. /**
  1374. * Enable global leak checking.
  1375. *
  1376. * @return {Mocha}
  1377. * @api public
  1378. */
  1379. Mocha.prototype.checkLeaks = function(){
  1380. this.options.ignoreLeaks = false;
  1381. return this;
  1382. };
  1383. /**
  1384. * Enable growl support.
  1385. *
  1386. * @return {Mocha}
  1387. * @api public
  1388. */
  1389. Mocha.prototype.growl = function(){
  1390. this.options.growl = true;
  1391. return this;
  1392. };
  1393. /**
  1394. * Ignore `globals` array or string.
  1395. *
  1396. * @param {Array|String} globals
  1397. * @return {Mocha}
  1398. * @api public
  1399. */
  1400. Mocha.prototype.globals = function(globals){
  1401. this.options.globals = (this.options.globals || []).concat(globals);
  1402. return this;
  1403. };
  1404. /**
  1405. * Emit color output.
  1406. *
  1407. * @param {Boolean} colors
  1408. * @return {Mocha}
  1409. * @api public
  1410. */
  1411. Mocha.prototype.useColors = function(colors){
  1412. this.options.useColors = arguments.length && colors != undefined
  1413. ? colors
  1414. : true;
  1415. return this;
  1416. };
  1417. /**
  1418. * Use inline diffs rather than +/-.
  1419. *
  1420. * @param {Boolean} inlineDiffs
  1421. * @return {Mocha}
  1422. * @api public
  1423. */
  1424. Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
  1425. this.options.useInlineDiffs = arguments.length && inlineDiffs != undefined
  1426. ? inlineDiffs
  1427. : false;
  1428. return this;
  1429. };
  1430. /**
  1431. * Set the timeout in milliseconds.
  1432. *
  1433. * @param {Number} timeout
  1434. * @return {Mocha}
  1435. * @api public
  1436. */
  1437. Mocha.prototype.timeout = function(timeout){
  1438. this.suite.timeout(timeout);
  1439. return this;
  1440. };
  1441. /**
  1442. * Set slowness threshold in milliseconds.
  1443. *
  1444. * @param {Number} slow
  1445. * @return {Mocha}
  1446. * @api public
  1447. */
  1448. Mocha.prototype.slow = function(slow){
  1449. this.suite.slow(slow);
  1450. return this;
  1451. };
  1452. /**
  1453. * Enable timeouts.
  1454. *
  1455. * @param {Boolean} enabled
  1456. * @return {Mocha}
  1457. * @api public
  1458. */
  1459. Mocha.prototype.enableTimeouts = function(enabled) {
  1460. this.suite.enableTimeouts(arguments.length && enabled !== undefined
  1461. ? enabled
  1462. : true);
  1463. return this
  1464. };
  1465. /**
  1466. * Makes all tests async (accepting a callback)
  1467. *
  1468. * @return {Mocha}
  1469. * @api public
  1470. */
  1471. Mocha.prototype.asyncOnly = function(){
  1472. this.options.asyncOnly = true;
  1473. return this;
  1474. };
  1475. /**
  1476. * Disable syntax highlighting (in browser).
  1477. * @returns {Mocha}
  1478. * @api public
  1479. */
  1480. Mocha.prototype.noHighlighting = function() {
  1481. this.options.noHighlighting = true;
  1482. return this;
  1483. };
  1484. /**
  1485. * Run tests and invoke `fn()` when complete.
  1486. *
  1487. * @param {Function} fn
  1488. * @return {Runner}
  1489. * @api public
  1490. */
  1491. Mocha.prototype.run = function(fn){
  1492. if (this.files.length) this.loadFiles();
  1493. var suite = this.suite;
  1494. var options = this.options;
  1495. options.files = this.files;
  1496. var runner = new exports.Runner(suite);
  1497. var reporter = new this._reporter(runner, options);
  1498. runner.ignoreLeaks = false !== options.ignoreLeaks;
  1499. runner.asyncOnly = options.asyncOnly;
  1500. if (options.grep) runner.grep(options.grep, options.invert);
  1501. if (options.globals) runner.globals(options.globals);
  1502. if (options.growl) this._growl(runner, reporter);
  1503. exports.reporters.Base.useColors = options.useColors;
  1504. exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
  1505. return runner.run(fn);
  1506. };
  1507. }); // module: mocha.js
  1508. require.register("ms.js", function(module, exports, require){
  1509. /**
  1510. * Helpers.
  1511. */
  1512. var s = 1000;
  1513. var m = s * 60;
  1514. var h = m * 60;
  1515. var d = h * 24;
  1516. var y = d * 365.25;
  1517. /**
  1518. * Parse or format the given `val`.
  1519. *
  1520. * Options:
  1521. *
  1522. * - `long` verbose formatting [false]
  1523. *
  1524. * @param {String|Number} val
  1525. * @param {Object} options
  1526. * @return {String|Number}
  1527. * @api public
  1528. */
  1529. module.exports = function(val, options){
  1530. options = options || {};
  1531. if ('string' == typeof val) return parse(val);
  1532. return options['long'] ? longFormat(val) : shortFormat(val);
  1533. };
  1534. /**
  1535. * Parse the given `str` and return milliseconds.
  1536. *
  1537. * @param {String} str
  1538. * @return {Number}
  1539. * @api private
  1540. */
  1541. function parse(str) {
  1542. var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str);
  1543. if (!match) return;
  1544. var n = parseFloat(match[1]);
  1545. var type = (match[2] || 'ms').toLowerCase();
  1546. switch (type) {
  1547. case 'years':
  1548. case 'year':
  1549. case 'y':
  1550. return n * y;
  1551. case 'days':
  1552. case 'day':
  1553. case 'd':
  1554. return n * d;
  1555. case 'hours':
  1556. case 'hour':
  1557. case 'h':
  1558. return n * h;
  1559. case 'minutes':
  1560. case 'minute':
  1561. case 'm':
  1562. return n * m;
  1563. case 'seconds':
  1564. case 'second':
  1565. case 's':
  1566. return n * s;
  1567. case 'ms':
  1568. return n;
  1569. }
  1570. }
  1571. /**
  1572. * Short format for `ms`.
  1573. *
  1574. * @param {Number} ms
  1575. * @return {String}
  1576. * @api private
  1577. */
  1578. function shortFormat(ms) {
  1579. if (ms >= d) return Math.round(ms / d) + 'd';
  1580. if (ms >= h) return Math.round(ms / h) + 'h';
  1581. if (ms >= m) return Math.round(ms / m) + 'm';
  1582. if (ms >= s) return Math.round(ms / s) + 's';
  1583. return ms + 'ms';
  1584. }
  1585. /**
  1586. * Long format for `ms`.
  1587. *
  1588. * @param {Number} ms
  1589. * @return {String}
  1590. * @api private
  1591. */
  1592. function longFormat(ms) {
  1593. return plural(ms, d, 'day')
  1594. || plural(ms, h, 'hour')
  1595. || plural(ms, m, 'minute')
  1596. || plural(ms, s, 'second')
  1597. || ms + ' ms';
  1598. }
  1599. /**
  1600. * Pluralization helper.
  1601. */
  1602. function plural(ms, n, name) {
  1603. if (ms < n) return;
  1604. if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
  1605. return Math.ceil(ms / n) + ' ' + name + 's';
  1606. }
  1607. }); // module: ms.js
  1608. require.register("reporters/base.js", function(module, exports, require){
  1609. /**
  1610. * Module dependencies.
  1611. */
  1612. var tty = require('browser/tty')
  1613. , diff = require('browser/diff')
  1614. , ms = require('../ms')
  1615. , utils = require('../utils');
  1616. /**
  1617. * Save timer references to avoid Sinon interfering (see GH-237).
  1618. */
  1619. var Date = global.Date
  1620. , setTimeout = global.setTimeout
  1621. , setInterval = global.setInterval
  1622. , clearTimeout = global.clearTimeout
  1623. , clearInterval = global.clearInterval;
  1624. /**
  1625. * Check if both stdio streams are associated with a tty.
  1626. */
  1627. var isatty = tty.isatty(1) && tty.isatty(2);
  1628. /**
  1629. * Expose `Base`.
  1630. */
  1631. exports = module.exports = Base;
  1632. /**
  1633. * Enable coloring by default.
  1634. */
  1635. exports.useColors = isatty || (process.env.MOCHA_COLORS !== undefined);
  1636. /**
  1637. * Inline diffs instead of +/-
  1638. */
  1639. exports.inlineDiffs = false;
  1640. /**
  1641. * Default color map.
  1642. */
  1643. exports.colors = {
  1644. 'pass': 90
  1645. , 'fail': 31
  1646. , 'bright pass': 92
  1647. , 'bright fail': 91
  1648. , 'bright yellow': 93
  1649. , 'pending': 36
  1650. , 'suite': 0
  1651. , 'error title': 0
  1652. , 'error message': 31
  1653. , 'error stack': 90
  1654. , 'checkmark': 32
  1655. , 'fast': 90
  1656. , 'medium': 33
  1657. , 'slow': 31
  1658. , 'green': 32
  1659. , 'light': 90
  1660. , 'diff gutter': 90
  1661. , 'diff added': 42
  1662. , 'diff removed': 41
  1663. };
  1664. /**
  1665. * Default symbol map.
  1666. */
  1667. exports.symbols = {
  1668. ok: '✓',
  1669. err: '✖',
  1670. dot: '․'
  1671. };
  1672. // With node.js on Windows: use symbols available in terminal default fonts
  1673. if ('win32' == process.platform) {
  1674. exports.symbols.ok = '\u221A';
  1675. exports.symbols.err = '\u00D7';
  1676. exports.symbols.dot = '.';
  1677. }
  1678. /**
  1679. * Color `str` with the given `type`,
  1680. * allowing colors to be disabled,
  1681. * as well as user-defined color
  1682. * schemes.
  1683. *
  1684. * @param {String} type
  1685. * @param {String} str
  1686. * @return {String}
  1687. * @api private
  1688. */
  1689. var color = exports.color = function(type, str) {
  1690. if (!exports.useColors) return str;
  1691. return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
  1692. };
  1693. /**
  1694. * Expose term window size, with some
  1695. * defaults for when stderr is not a tty.
  1696. */
  1697. exports.window = {
  1698. width: isatty
  1699. ? process.stdout.getWindowSize
  1700. ? process.stdout.getWindowSize(1)[0]
  1701. : tty.getWindowSize()[1]
  1702. : 75
  1703. };
  1704. /**
  1705. * Expose some basic cursor interactions
  1706. * that are common among reporters.
  1707. */
  1708. exports.cursor = {
  1709. hide: function(){
  1710. isatty && process.stdout.write('\u001b[?25l');
  1711. },
  1712. show: function(){
  1713. isatty && process.stdout.write('\u001b[?25h');
  1714. },
  1715. deleteLine: function(){
  1716. isatty && process.stdout.write('\u001b[2K');
  1717. },
  1718. beginningOfLine: function(){
  1719. isatty && process.stdout.write('\u001b[0G');
  1720. },
  1721. CR: function(){
  1722. if (isatty) {
  1723. exports.cursor.deleteLine();
  1724. exports.cursor.beginningOfLine();
  1725. } else {
  1726. process.stdout.write('\r');
  1727. }
  1728. }
  1729. };
  1730. /**
  1731. * Outut the given `failures` as a list.
  1732. *
  1733. * @param {Array} failures
  1734. * @api public
  1735. */
  1736. exports.list = function(failures){
  1737. console.error();
  1738. failures.forEach(function(test, i){
  1739. // format
  1740. var fmt = color('error title', ' %s) %s:\n')
  1741. + color('error message', ' %s')
  1742. + color('error stack', '\n%s\n');
  1743. // msg
  1744. var err = test.err
  1745. , message = err.message || ''
  1746. , stack = err.stack || message
  1747. , index = stack.indexOf(message) + message.length
  1748. , msg = stack.slice(0, index)
  1749. , actual = err.actual
  1750. , expected = err.expected
  1751. , escape = true;
  1752. // uncaught
  1753. if (err.uncaught) {
  1754. msg = 'Uncaught ' + msg;
  1755. }
  1756. // explicitly show diff
  1757. if (err.showDiff && sameType(actual, expected)) {
  1758. escape = false;
  1759. err.actual = actual = utils.stringify(actual);
  1760. err.expected = expected = utils.stringify(expected);
  1761. }
  1762. // actual / expected diff
  1763. if (err.showDiff && 'string' == typeof actual && 'string' == typeof expected) {
  1764. fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
  1765. var match = message.match(/^([^:]+): expected/);
  1766. msg = '\n ' + color('error message', match ? match[1] : msg);
  1767. if (exports.inlineDiffs) {
  1768. msg += inlineDiff(err, escape);
  1769. } else {
  1770. msg += unifiedDiff(err, escape);
  1771. }
  1772. }
  1773. // indent stack trace without msg
  1774. stack = stack.slice(index ? index + 1 : index)
  1775. .replace(/^/gm, ' ');
  1776. console.error(fmt, (i + 1), test.fullTitle(), msg, stack);
  1777. });
  1778. };
  1779. /**
  1780. * Initialize a new `Base` reporter.
  1781. *
  1782. * All other reporters generally
  1783. * inherit from this reporter, providing
  1784. * stats such as test duration, number
  1785. * of tests passed / failed etc.
  1786. *
  1787. * @param {Runner} runner
  1788. * @api public
  1789. */
  1790. function Base(runner) {
  1791. var self = this
  1792. , stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
  1793. , failures = this.failures = [];
  1794. if (!runner) return;
  1795. this.runner = runner;
  1796. runner.stats = stats;
  1797. runner.on('start', function(){
  1798. stats.start = new Date;
  1799. });
  1800. runner.on('suite', function(suite){
  1801. stats.suites = stats.suites || 0;
  1802. suite.root || stats.suites++;
  1803. });
  1804. runner.on('test end', function(test){
  1805. stats.tests = stats.tests || 0;
  1806. stats.tests++;
  1807. });
  1808. runner.on('pass', function(test){
  1809. stats.passes = stats.passes || 0;
  1810. var medium = test.slow() / 2;
  1811. test.speed = test.duration > test.slow()
  1812. ? 'slow'
  1813. : test.duration > medium
  1814. ? 'medium'
  1815. : 'fast';
  1816. stats.passes++;
  1817. });
  1818. runner.on('fail', function(test, err){
  1819. stats.failures = stats.failures || 0;
  1820. stats.failures++;
  1821. test.err = err;
  1822. failures.push(test);
  1823. });
  1824. runner.on('end', function(){
  1825. stats.end = new Date;
  1826. stats.duration = new Date - stats.start;
  1827. });
  1828. runner.on('pending', function(){
  1829. stats.pending++;
  1830. });
  1831. }
  1832. /**
  1833. * Output common epilogue used by many of
  1834. * the bundled reporters.
  1835. *
  1836. * @api public
  1837. */
  1838. Base.prototype.epilogue = function(){
  1839. var stats = this.stats;
  1840. var tests;
  1841. var fmt;
  1842. console.log();
  1843. // passes
  1844. fmt = color('bright pass', ' ')
  1845. + color('green', ' %d passing')
  1846. + color('light', ' (%s)');
  1847. console.log(fmt,
  1848. stats.passes || 0,
  1849. ms(stats.duration));
  1850. // pending
  1851. if (stats.pending) {
  1852. fmt = color('pending', ' ')
  1853. + color('pending', ' %d pending');
  1854. console.log(fmt, stats.pending);
  1855. }
  1856. // failures
  1857. if (stats.failures) {
  1858. fmt = color('fail', ' %d failing');
  1859. console.error(fmt,
  1860. stats.failures);
  1861. Base.list(this.failures);
  1862. console.error();
  1863. }
  1864. console.log();
  1865. };
  1866. /**
  1867. * Pad the given `str` to `len`.
  1868. *
  1869. * @param {String} str
  1870. * @param {String} len
  1871. * @return {String}
  1872. * @api private
  1873. */
  1874. function pad(str, len) {
  1875. str = String(str);
  1876. return Array(len - str.length + 1).join(' ') + str;
  1877. }
  1878. /**
  1879. * Returns an inline diff between 2 strings with coloured ANSI output
  1880. *
  1881. * @param {Error} Error with actual/expected
  1882. * @return {String} Diff
  1883. * @api private
  1884. */
  1885. function inlineDiff(err, escape) {
  1886. var msg = errorDiff(err, 'WordsWithSpace', escape);
  1887. // linenos
  1888. var lines = msg.split('\n');
  1889. if (lines.length > 4) {
  1890. var width = String(lines.length).length;
  1891. msg = lines.map(function(str, i){
  1892. return pad(++i, width) + ' |' + ' ' + str;
  1893. }).join('\n');
  1894. }
  1895. // legend
  1896. msg = '\n'
  1897. + color('diff removed', 'actual')
  1898. + ' '
  1899. + color('diff added', 'expected')
  1900. + '\n\n'
  1901. + msg
  1902. + '\n';
  1903. // indent
  1904. msg = msg.replace(/^/gm, ' ');
  1905. return msg;
  1906. }
  1907. /**
  1908. * Returns a unified diff between 2 strings
  1909. *
  1910. * @param {Error} Error with actual/expected
  1911. * @return {String} Diff
  1912. * @api private
  1913. */
  1914. function unifiedDiff(err, escape) {
  1915. var indent = ' ';
  1916. function cleanUp(line) {
  1917. if (escape) {
  1918. line = escapeInvisibles(line);
  1919. }
  1920. if (line[0] === '+') return indent + colorLines('diff added', line);
  1921. if (line[0] === '-') return indent + colorLines('diff removed', line);
  1922. if (line.match(/\@\@/)) return null;
  1923. if (line.match(/\\ No newline/)) return null;
  1924. else return indent + line;
  1925. }
  1926. function notBlank(line) {
  1927. return line != null;
  1928. }
  1929. msg = diff.createPatch('string', err.actual, err.expected);
  1930. var lines = msg.split('\n').splice(4);
  1931. return '\n '
  1932. + colorLines('diff added', '+ expected') + ' '
  1933. + colorLines('diff removed', '- actual')
  1934. + '\n\n'
  1935. + lines.map(cleanUp).filter(notBlank).join('\n');
  1936. }
  1937. /**
  1938. * Return a character diff for `err`.
  1939. *
  1940. * @param {Error} err
  1941. * @return {String}
  1942. * @api private
  1943. */
  1944. function errorDiff(err, type, escape) {
  1945. var actual = escape ? escapeInvisibles(err.actual) : err.actual;
  1946. var expected = escape ? escapeInvisibles(err.expected) : err.expected;
  1947. return diff['diff' + type](actual, expected).map(function(str){
  1948. if (str.added) return colorLines('diff added', str.value);
  1949. if (str.removed) return colorLines('diff removed', str.value);
  1950. return str.value;
  1951. }).join('');
  1952. }
  1953. /**
  1954. * Returns a string with all invisible characters in plain text
  1955. *
  1956. * @param {String} line
  1957. * @return {String}
  1958. * @api private
  1959. */
  1960. function escapeInvisibles(line) {
  1961. return line.replace(/\t/g, '<tab>')
  1962. .replace(/\r/g, '<CR>')
  1963. .replace(/\n/g, '<LF>\n');
  1964. }
  1965. /**
  1966. * Color lines for `str`, using the color `name`.
  1967. *
  1968. * @param {String} name
  1969. * @param {String} str
  1970. * @return {String}
  1971. * @api private
  1972. */
  1973. function colorLines(name, str) {
  1974. return str.split('\n').map(function(str){
  1975. return color(name, str);
  1976. }).join('\n');
  1977. }
  1978. /**
  1979. * Check that a / b have the same type.
  1980. *
  1981. * @param {Object} a
  1982. * @param {Object} b
  1983. * @return {Boolean}
  1984. * @api private
  1985. */
  1986. function sameType(a, b) {
  1987. a = Object.prototype.toString.call(a);
  1988. b = Object.prototype.toString.call(b);
  1989. return a == b;
  1990. }
  1991. }); // module: reporters/base.js
  1992. require.register("reporters/doc.js", function(module, exports, require){
  1993. /**
  1994. * Module dependencies.
  1995. */
  1996. var Base = require('./base')
  1997. , utils = require('../utils');
  1998. /**
  1999. * Expose `Doc`.
  2000. */
  2001. exports = module.exports = Doc;
  2002. /**
  2003. * Initialize a new `Doc` reporter.
  2004. *
  2005. * @param {Runner} runner
  2006. * @api public
  2007. */
  2008. function Doc(runner) {
  2009. Base.call(this, runner);
  2010. var self = this
  2011. , stats = this.stats
  2012. , total = runner.total
  2013. , indents = 2;
  2014. function indent() {
  2015. return Array(indents).join(' ');
  2016. }
  2017. runner.on('suite', function(suite){
  2018. if (suite.root) return;
  2019. ++indents;
  2020. console.log('%s<section class="suite">', indent());
  2021. ++indents;
  2022. console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
  2023. console.log('%s<dl>', indent());
  2024. });
  2025. runner.on('suite end', function(suite){
  2026. if (suite.root) return;
  2027. console.log('%s</dl>', indent());
  2028. --indents;
  2029. console.log('%s</section>', indent());
  2030. --indents;
  2031. });
  2032. runner.on('pass', function(test){
  2033. console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
  2034. var code = utils.escape(utils.clean(test.fn.toString()));
  2035. console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
  2036. });
  2037. runner.on('fail', function(test, err){
  2038. console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
  2039. var code = utils.escape(utils.clean(test.fn.toString()));
  2040. console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
  2041. console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
  2042. });
  2043. }
  2044. }); // module: reporters/doc.js
  2045. require.register("reporters/dot.js", function(module, exports, require){
  2046. /**
  2047. * Module dependencies.
  2048. */
  2049. var Base = require('./base')
  2050. , color = Base.color;
  2051. /**
  2052. * Expose `Dot`.
  2053. */
  2054. exports = module.exports = Dot;
  2055. /**
  2056. * Initialize a new `Dot` matrix test reporter.
  2057. *
  2058. * @param {Runner} runner
  2059. * @api public
  2060. */
  2061. function Dot(runner) {
  2062. Base.call(this, runner);
  2063. var self = this
  2064. , stats = this.stats
  2065. , width = Base.window.width * .75 | 0
  2066. , n = -1;
  2067. runner.on('start', function(){
  2068. process.stdout.write('\n ');
  2069. });
  2070. runner.on('pending', function(test){
  2071. if (++n % width == 0) process.stdout.write('\n ');
  2072. process.stdout.write(color('pending', Base.symbols.dot));
  2073. });
  2074. runner.on('pass', function(test){
  2075. if (++n % width == 0) process.stdout.write('\n ');
  2076. if ('slow' == test.speed) {
  2077. process.stdout.write(color('bright yellow', Base.symbols.dot));
  2078. } else {
  2079. process.stdout.write(color(test.speed, Base.symbols.dot));
  2080. }
  2081. });
  2082. runner.on('fail', function(test, err){
  2083. if (++n % width == 0) process.stdout.write('\n ');
  2084. process.stdout.write(color('fail', Base.symbols.dot));
  2085. });
  2086. runner.on('end', function(){
  2087. console.log();
  2088. self.epilogue();
  2089. });
  2090. }
  2091. /**
  2092. * Inherit from `Base.prototype`.
  2093. */
  2094. function F(){};
  2095. F.prototype = Base.prototype;
  2096. Dot.prototype = new F;
  2097. Dot.prototype.constructor = Dot;
  2098. }); // module: reporters/dot.js
  2099. require.register("reporters/html-cov.js", function(module, exports, require){
  2100. /**
  2101. * Module dependencies.
  2102. */
  2103. var JSONCov = require('./json-cov')
  2104. , fs = require('browser/fs');
  2105. /**
  2106. * Expose `HTMLCov`.
  2107. */
  2108. exports = module.exports = HTMLCov;
  2109. /**
  2110. * Initialize a new `JsCoverage` reporter.
  2111. *
  2112. * @param {Runner} runner
  2113. * @api public
  2114. */
  2115. function HTMLCov(runner) {
  2116. var jade = require('jade')
  2117. , file = __dirname + '/templates/coverage.jade'
  2118. , str = fs.readFileSync(file, 'utf8')
  2119. , fn = jade.compile(str, { filename: file })
  2120. , self = this;
  2121. JSONCov.call(this, runner, false);
  2122. runner.on('end', function(){
  2123. process.stdout.write(fn({
  2124. cov: self.cov
  2125. , coverageClass: coverageClass
  2126. }));
  2127. });
  2128. }
  2129. /**
  2130. * Return coverage class for `n`.
  2131. *
  2132. * @return {String}
  2133. * @api private
  2134. */
  2135. function coverageClass(n) {
  2136. if (n >= 75) return 'high';
  2137. if (n >= 50) return 'medium';
  2138. if (n >= 25) return 'low';
  2139. return 'terrible';
  2140. }
  2141. }); // module: reporters/html-cov.js
  2142. require.register("reporters/html.js", function(module, exports, require){
  2143. /**
  2144. * Module dependencies.
  2145. */
  2146. var Base = require('./base')
  2147. , utils = require('../utils')
  2148. , Progress = require('../browser/progress')
  2149. , escape = utils.escape;
  2150. /**
  2151. * Save timer references to avoid Sinon interfering (see GH-237).
  2152. */
  2153. var Date = global.Date
  2154. , setTimeout = global.setTimeout
  2155. , setInterval = global.setInterval
  2156. , clearTimeout = global.clearTimeout
  2157. , clearInterval = global.clearInterval;
  2158. /**
  2159. * Expose `HTML`.
  2160. */
  2161. exports = module.exports = HTML;
  2162. /**
  2163. * Stats template.
  2164. */
  2165. var statsTemplate = '<ul id="mocha-stats">'
  2166. + '<li class="progress"><canvas width="40" height="40"></canvas></li>'
  2167. + '<li class="passes"><a href="#">passes:</a> <em>0</em></li>'
  2168. + '<li class="failures"><a href="#">failures:</a> <em>0</em></li>'
  2169. + '<li class="duration">duration: <em>0</em>s</li>'
  2170. + '</ul>';
  2171. /**
  2172. * Initialize a new `HTML` reporter.
  2173. *
  2174. * @param {Runner} runner
  2175. * @api public
  2176. */
  2177. function HTML(runner) {
  2178. Base.call(this, runner);
  2179. var self = this
  2180. , stats = this.stats
  2181. , total = runner.total
  2182. , stat = fragment(statsTemplate)
  2183. , items = stat.getElementsByTagName('li')
  2184. , passes = items[1].getElementsByTagName('em')[0]
  2185. , passesLink = items[1].getElementsByTagName('a')[0]
  2186. , failures = items[2].getElementsByTagName('em')[0]
  2187. , failuresLink = items[2].getElementsByTagName('a')[0]
  2188. , duration = items[3].getElementsByTagName('em')[0]
  2189. , canvas = stat.getElementsByTagName('canvas')[0]
  2190. , report = fragment('<ul id="mocha-report"></ul>')
  2191. , stack = [report]
  2192. , progress
  2193. , ctx
  2194. , root = document.getElementById('mocha');
  2195. if (canvas.getContext) {
  2196. var ratio = window.devicePixelRatio || 1;
  2197. canvas.style.width = canvas.width;
  2198. canvas.style.height = canvas.height;
  2199. canvas.width *= ratio;
  2200. canvas.height *= ratio;
  2201. ctx = canvas.getContext('2d');
  2202. ctx.scale(ratio, ratio);
  2203. progress = new Progress;
  2204. }
  2205. if (!root) return error('#mocha div missing, add it to your document');
  2206. // pass toggle
  2207. on(passesLink, 'click', function(){
  2208. unhide();
  2209. var name = /pass/.test(report.className) ? '' : ' pass';
  2210. report.className = report.className.replace(/fail|pass/g, '') + name;
  2211. if (report.className.trim()) hideSuitesWithout('test pass');
  2212. });
  2213. // failure toggle
  2214. on(failuresLink, 'click', function(){
  2215. unhide();
  2216. var name = /fail/.test(report.className) ? '' : ' fail';
  2217. report.className = report.className.replace(/fail|pass/g, '') + name;
  2218. if (report.className.trim()) hideSuitesWithout('test fail');
  2219. });
  2220. root.appendChild(stat);
  2221. root.appendChild(report);
  2222. if (progress) progress.size(40);
  2223. runner.on('suite', function(suite){
  2224. if (suite.root) return;
  2225. // suite
  2226. var url = self.suiteURL(suite);
  2227. var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
  2228. // container
  2229. stack[0].appendChild(el);
  2230. stack.unshift(document.createElement('ul'));
  2231. el.appendChild(stack[0]);
  2232. });
  2233. runner.on('suite end', function(suite){
  2234. if (suite.root) return;
  2235. stack.shift();
  2236. });
  2237. runner.on('fail', function(test, err){
  2238. if ('hook' == test.type) runner.emit('test end', test);
  2239. });
  2240. runner.on('test end', function(test){
  2241. // TODO: add to stats
  2242. var percent = stats.tests / this.total * 100 | 0;
  2243. if (progress) progress.update(percent).draw(ctx);
  2244. // update stats
  2245. var ms = new Date - stats.start;
  2246. text(passes, stats.passes);
  2247. text(failures, stats.failures);
  2248. text(duration, (ms / 1000).toFixed(2));
  2249. // test
  2250. if ('passed' == test.state) {
  2251. var url = self.testURL(test);
  2252. var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="%s" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, url);
  2253. } else if (test.pending) {
  2254. var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
  2255. } else {
  2256. var el = fragment('<li class="test fail"><h2>%e <a href="?grep=%e" class="replay">‣</a></h2></li>', test.title, encodeURIComponent(test.fullTitle()));
  2257. var str = test.err.stack || test.err.toString();
  2258. // FF / Opera do not add the message
  2259. if (!~str.indexOf(test.err.message)) {
  2260. str = test.err.message + '\n' + str;
  2261. }
  2262. // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
  2263. // check for the result of the stringifying.
  2264. if ('[object Error]' == str) str = test.err.message;
  2265. // Safari doesn't give you a stack. Let's at least provide a source line.
  2266. if (!test.err.stack && test.err.sourceURL && test.err.line !== undefined) {
  2267. str += "\n(" + test.err.sourceURL + ":" + test.err.line + ")";
  2268. }
  2269. el.appendChild(fragment('<pre class="error">%e</pre>', str));
  2270. }
  2271. // toggle code
  2272. // TODO: defer
  2273. if (!test.pending) {
  2274. var h2 = el.getElementsByTagName('h2')[0];
  2275. on(h2, 'click', function(){
  2276. pre.style.display = 'none' == pre.style.display
  2277. ? 'block'
  2278. : 'none';
  2279. });
  2280. var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.fn.toString()));
  2281. el.appendChild(pre);
  2282. pre.style.display = 'none';
  2283. }
  2284. // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
  2285. if (stack[0]) stack[0].appendChild(el);
  2286. });
  2287. }
  2288. /**
  2289. * Makes a URL, preserving querystring ("search") parameters.
  2290. * @param {string} s
  2291. * @returns {string} your new URL
  2292. */
  2293. var makeUrl = function makeUrl(s) {
  2294. var search = window.location.search;
  2295. return (search ? search + '&' : '?' ) + 'grep=' + encodeURIComponent(s);
  2296. };
  2297. /**
  2298. * Provide suite URL
  2299. *
  2300. * @param {Object} [suite]
  2301. */
  2302. HTML.prototype.suiteURL = function(suite){
  2303. return makeUrl(suite.fullTitle());
  2304. };
  2305. /**
  2306. * Provide test URL
  2307. *
  2308. * @param {Object} [test]
  2309. */
  2310. HTML.prototype.testURL = function(test){
  2311. return makeUrl(test.fullTitle());
  2312. };
  2313. /**
  2314. * Display error `msg`.
  2315. */
  2316. function error(msg) {
  2317. document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
  2318. }
  2319. /**
  2320. * Return a DOM fragment from `html`.
  2321. */
  2322. function fragment(html) {
  2323. var args = arguments
  2324. , div = document.createElement('div')
  2325. , i = 1;
  2326. div.innerHTML = html.replace(/%([se])/g, function(_, type){
  2327. switch (type) {
  2328. case 's': return String(args[i++]);
  2329. case 'e': return escape(args[i++]);
  2330. }
  2331. });
  2332. return div.firstChild;
  2333. }
  2334. /**
  2335. * Check for suites that do not have elements
  2336. * with `classname`, and hide them.
  2337. */
  2338. function hideSuitesWithout(classname) {
  2339. var suites = document.getElementsByClassName('suite');
  2340. for (var i = 0; i < suites.length; i++) {
  2341. var els = suites[i].getElementsByClassName(classname);
  2342. if (0 == els.length) suites[i].className += ' hidden';
  2343. }
  2344. }
  2345. /**
  2346. * Unhide .hidden suites.
  2347. */
  2348. function unhide() {
  2349. var els = document.getElementsByClassName('suite hidden');
  2350. for (var i = 0; i < els.length; ++i) {
  2351. els[i].className = els[i].className.replace('suite hidden', 'suite');
  2352. }
  2353. }
  2354. /**
  2355. * Set `el` text to `str`.
  2356. */
  2357. function text(el, str) {
  2358. if (el.textContent) {
  2359. el.textContent = str;
  2360. } else {
  2361. el.innerText = str;
  2362. }
  2363. }
  2364. /**
  2365. * Listen on `event` with callback `fn`.
  2366. */
  2367. function on(el, event, fn) {
  2368. if (el.addEventListener) {
  2369. el.addEventListener(event, fn, false);
  2370. } else {
  2371. el.attachEvent('on' + event, fn);
  2372. }
  2373. }
  2374. }); // module: reporters/html.js
  2375. require.register("reporters/index.js", function(module, exports, require){
  2376. exports.Base = require('./base');
  2377. exports.Dot = require('./dot');
  2378. exports.Doc = require('./doc');
  2379. exports.TAP = require('./tap');
  2380. exports.JSON = require('./json');
  2381. exports.HTML = require('./html');
  2382. exports.List = require('./list');
  2383. exports.Min = require('./min');
  2384. exports.Spec = require('./spec');
  2385. exports.Nyan = require('./nyan');
  2386. exports.XUnit = require('./xunit');
  2387. exports.Markdown = require('./markdown');
  2388. exports.Progress = require('./progress');
  2389. exports.Landing = require('./landing');
  2390. exports.JSONCov = require('./json-cov');
  2391. exports.HTMLCov = require('./html-cov');
  2392. exports.JSONStream = require('./json-stream');
  2393. }); // module: reporters/index.js
  2394. require.register("reporters/json-cov.js", function(module, exports, require){
  2395. /**
  2396. * Module dependencies.
  2397. */
  2398. var Base = require('./base');
  2399. /**
  2400. * Expose `JSONCov`.
  2401. */
  2402. exports = module.exports = JSONCov;
  2403. /**
  2404. * Initialize a new `JsCoverage` reporter.
  2405. *
  2406. * @param {Runner} runner
  2407. * @param {Boolean} output
  2408. * @api public
  2409. */
  2410. function JSONCov(runner, output) {
  2411. var self = this
  2412. , output = 1 == arguments.length ? true : output;
  2413. Base.call(this, runner);
  2414. var tests = []
  2415. , failures = []
  2416. , passes = [];
  2417. runner.on('test end', function(test){
  2418. tests.push(test);
  2419. });
  2420. runner.on('pass', function(test){
  2421. passes.push(test);
  2422. });
  2423. runner.on('fail', function(test){
  2424. failures.push(test);
  2425. });
  2426. runner.on('end', function(){
  2427. var cov = global._$jscoverage || {};
  2428. var result = self.cov = map(cov);
  2429. result.stats = self.stats;
  2430. result.tests = tests.map(clean);
  2431. result.failures = failures.map(clean);
  2432. result.passes = passes.map(clean);
  2433. if (!output) return;
  2434. process.stdout.write(JSON.stringify(result, null, 2 ));
  2435. });
  2436. }
  2437. /**
  2438. * Map jscoverage data to a JSON structure
  2439. * suitable for reporting.
  2440. *
  2441. * @param {Object} cov
  2442. * @return {Object}
  2443. * @api private
  2444. */
  2445. function map(cov) {
  2446. var ret = {
  2447. instrumentation: 'node-jscoverage'
  2448. , sloc: 0
  2449. , hits: 0
  2450. , misses: 0
  2451. , coverage: 0
  2452. , files: []
  2453. };
  2454. for (var filename in cov) {
  2455. var data = coverage(filename, cov[filename]);
  2456. ret.files.push(data);
  2457. ret.hits += data.hits;
  2458. ret.misses += data.misses;
  2459. ret.sloc += data.sloc;
  2460. }
  2461. ret.files.sort(function(a, b) {
  2462. return a.filename.localeCompare(b.filename);
  2463. });
  2464. if (ret.sloc > 0) {
  2465. ret.coverage = (ret.hits / ret.sloc) * 100;
  2466. }
  2467. return ret;
  2468. }
  2469. /**
  2470. * Map jscoverage data for a single source file
  2471. * to a JSON structure suitable for reporting.
  2472. *
  2473. * @param {String} filename name of the source file
  2474. * @param {Object} data jscoverage coverage data
  2475. * @return {Object}
  2476. * @api private
  2477. */
  2478. function coverage(filename, data) {
  2479. var ret = {
  2480. filename: filename,
  2481. coverage: 0,
  2482. hits: 0,
  2483. misses: 0,
  2484. sloc: 0,
  2485. source: {}
  2486. };
  2487. data.source.forEach(function(line, num){
  2488. num++;
  2489. if (data[num] === 0) {
  2490. ret.misses++;
  2491. ret.sloc++;
  2492. } else if (data[num] !== undefined) {
  2493. ret.hits++;
  2494. ret.sloc++;
  2495. }
  2496. ret.source[num] = {
  2497. source: line
  2498. , coverage: data[num] === undefined
  2499. ? ''
  2500. : data[num]
  2501. };
  2502. });
  2503. ret.coverage = ret.hits / ret.sloc * 100;
  2504. return ret;
  2505. }
  2506. /**
  2507. * Return a plain-object representation of `test`
  2508. * free of cyclic properties etc.
  2509. *
  2510. * @param {Object} test
  2511. * @return {Object}
  2512. * @api private
  2513. */
  2514. function clean(test) {
  2515. return {
  2516. title: test.title
  2517. , fullTitle: test.fullTitle()
  2518. , duration: test.duration
  2519. }
  2520. }
  2521. }); // module: reporters/json-cov.js
  2522. require.register("reporters/json-stream.js", function(module, exports, require){
  2523. /**
  2524. * Module dependencies.
  2525. */
  2526. var Base = require('./base')
  2527. , color = Base.color;
  2528. /**
  2529. * Expose `List`.
  2530. */
  2531. exports = module.exports = List;
  2532. /**
  2533. * Initialize a new `List` test reporter.
  2534. *
  2535. * @param {Runner} runner
  2536. * @api public
  2537. */
  2538. function List(runner) {
  2539. Base.call(this, runner);
  2540. var self = this
  2541. , stats = this.stats
  2542. , total = runner.total;
  2543. runner.on('start', function(){
  2544. console.log(JSON.stringify(['start', { total: total }]));
  2545. });
  2546. runner.on('pass', function(test){
  2547. console.log(JSON.stringify(['pass', clean(test)]));
  2548. });
  2549. runner.on('fail', function(test, err){
  2550. test = clean(test);
  2551. test.err = err.message;
  2552. console.log(JSON.stringify(['fail', test]));
  2553. });
  2554. runner.on('end', function(){
  2555. process.stdout.write(JSON.stringify(['end', self.stats]));
  2556. });
  2557. }
  2558. /**
  2559. * Return a plain-object representation of `test`
  2560. * free of cyclic properties etc.
  2561. *
  2562. * @param {Object} test
  2563. * @return {Object}
  2564. * @api private
  2565. */
  2566. function clean(test) {
  2567. return {
  2568. title: test.title
  2569. , fullTitle: test.fullTitle()
  2570. , duration: test.duration
  2571. }
  2572. }
  2573. }); // module: reporters/json-stream.js
  2574. require.register("reporters/json.js", function(module, exports, require){
  2575. /**
  2576. * Module dependencies.
  2577. */
  2578. var Base = require('./base')
  2579. , cursor = Base.cursor
  2580. , color = Base.color;
  2581. /**
  2582. * Expose `JSON`.
  2583. */
  2584. exports = module.exports = JSONReporter;
  2585. /**
  2586. * Initialize a new `JSON` reporter.
  2587. *
  2588. * @param {Runner} runner
  2589. * @api public
  2590. */
  2591. function JSONReporter(runner) {
  2592. var self = this;
  2593. Base.call(this, runner);
  2594. var tests = []
  2595. , pending = []
  2596. , failures = []
  2597. , passes = [];
  2598. runner.on('test end', function(test){
  2599. tests.push(test);
  2600. });
  2601. runner.on('pass', function(test){
  2602. passes.push(test);
  2603. });
  2604. runner.on('fail', function(test){
  2605. failures.push(test);
  2606. });
  2607. runner.on('pending', function(test){
  2608. pending.push(test);
  2609. });
  2610. runner.on('end', function(){
  2611. var obj = {
  2612. stats: self.stats,
  2613. tests: tests.map(clean),
  2614. pending: pending.map(clean),
  2615. failures: failures.map(clean),
  2616. passes: passes.map(clean)
  2617. };
  2618. runner.testResults = obj;
  2619. process.stdout.write(JSON.stringify(obj, null, 2));
  2620. });
  2621. }
  2622. /**
  2623. * Return a plain-object representation of `test`
  2624. * free of cyclic properties etc.
  2625. *
  2626. * @param {Object} test
  2627. * @return {Object}
  2628. * @api private
  2629. */
  2630. function clean(test) {
  2631. return {
  2632. title: test.title,
  2633. fullTitle: test.fullTitle(),
  2634. duration: test.duration,
  2635. err: errorJSON(test.err || {})
  2636. }
  2637. }
  2638. /**
  2639. * Transform `error` into a JSON object.
  2640. * @param {Error} err
  2641. * @return {Object}
  2642. */
  2643. function errorJSON(err) {
  2644. var res = {};
  2645. Object.getOwnPropertyNames(err).forEach(function(key) {
  2646. res[key] = err[key];
  2647. }, err);
  2648. return res;
  2649. }
  2650. }); // module: reporters/json.js
  2651. require.register("reporters/landing.js", function(module, exports, require){
  2652. /**
  2653. * Module dependencies.
  2654. */
  2655. var Base = require('./base')
  2656. , cursor = Base.cursor
  2657. , color = Base.color;
  2658. /**
  2659. * Expose `Landing`.
  2660. */
  2661. exports = module.exports = Landing;
  2662. /**
  2663. * Airplane color.
  2664. */
  2665. Base.colors.plane = 0;
  2666. /**
  2667. * Airplane crash color.
  2668. */
  2669. Base.colors['plane crash'] = 31;
  2670. /**
  2671. * Runway color.
  2672. */
  2673. Base.colors.runway = 90;
  2674. /**
  2675. * Initialize a new `Landing` reporter.
  2676. *
  2677. * @param {Runner} runner
  2678. * @api public
  2679. */
  2680. function Landing(runner) {
  2681. Base.call(this, runner);
  2682. var self = this
  2683. , stats = this.stats
  2684. , width = Base.window.width * .75 | 0
  2685. , total = runner.total
  2686. , stream = process.stdout
  2687. , plane = color('plane', '✈')
  2688. , crashed = -1
  2689. , n = 0;
  2690. function runway() {
  2691. var buf = Array(width).join('-');
  2692. return ' ' + color('runway', buf);
  2693. }
  2694. runner.on('start', function(){
  2695. stream.write('\n\n\n ');
  2696. cursor.hide();
  2697. });
  2698. runner.on('test end', function(test){
  2699. // check if the plane crashed
  2700. var col = -1 == crashed
  2701. ? width * ++n / total | 0
  2702. : crashed;
  2703. // show the crash
  2704. if ('failed' == test.state) {
  2705. plane = color('plane crash', '✈');
  2706. crashed = col;
  2707. }
  2708. // render landing strip
  2709. stream.write('\u001b['+(width+1)+'D\u001b[2A');
  2710. stream.write(runway());
  2711. stream.write('\n ');
  2712. stream.write(color('runway', Array(col).join('⋅')));
  2713. stream.write(plane)
  2714. stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
  2715. stream.write(runway());
  2716. stream.write('\u001b[0m');
  2717. });
  2718. runner.on('end', function(){
  2719. cursor.show();
  2720. console.log();
  2721. self.epilogue();
  2722. });
  2723. }
  2724. /**
  2725. * Inherit from `Base.prototype`.
  2726. */
  2727. function F(){};
  2728. F.prototype = Base.prototype;
  2729. Landing.prototype = new F;
  2730. Landing.prototype.constructor = Landing;
  2731. }); // module: reporters/landing.js
  2732. require.register("reporters/list.js", function(module, exports, require){
  2733. /**
  2734. * Module dependencies.
  2735. */
  2736. var Base = require('./base')
  2737. , cursor = Base.cursor
  2738. , color = Base.color;
  2739. /**
  2740. * Expose `List`.
  2741. */
  2742. exports = module.exports = List;
  2743. /**
  2744. * Initialize a new `List` test reporter.
  2745. *
  2746. * @param {Runner} runner
  2747. * @api public
  2748. */
  2749. function List(runner) {
  2750. Base.call(this, runner);
  2751. var self = this
  2752. , stats = this.stats
  2753. , n = 0;
  2754. runner.on('start', function(){
  2755. console.log();
  2756. });
  2757. runner.on('test', function(test){
  2758. process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
  2759. });
  2760. runner.on('pending', function(test){
  2761. var fmt = color('checkmark', ' -')
  2762. + color('pending', ' %s');
  2763. console.log(fmt, test.fullTitle());
  2764. });
  2765. runner.on('pass', function(test){
  2766. var fmt = color('checkmark', ' '+Base.symbols.dot)
  2767. + color('pass', ' %s: ')
  2768. + color(test.speed, '%dms');
  2769. cursor.CR();
  2770. console.log(fmt, test.fullTitle(), test.duration);
  2771. });
  2772. runner.on('fail', function(test, err){
  2773. cursor.CR();
  2774. console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
  2775. });
  2776. runner.on('end', self.epilogue.bind(self));
  2777. }
  2778. /**
  2779. * Inherit from `Base.prototype`.
  2780. */
  2781. function F(){};
  2782. F.prototype = Base.prototype;
  2783. List.prototype = new F;
  2784. List.prototype.constructor = List;
  2785. }); // module: reporters/list.js
  2786. require.register("reporters/markdown.js", function(module, exports, require){
  2787. /**
  2788. * Module dependencies.
  2789. */
  2790. var Base = require('./base')
  2791. , utils = require('../utils');
  2792. /**
  2793. * Expose `Markdown`.
  2794. */
  2795. exports = module.exports = Markdown;
  2796. /**
  2797. * Initialize a new `Markdown` reporter.
  2798. *
  2799. * @param {Runner} runner
  2800. * @api public
  2801. */
  2802. function Markdown(runner) {
  2803. Base.call(this, runner);
  2804. var self = this
  2805. , stats = this.stats
  2806. , level = 0
  2807. , buf = '';
  2808. function title(str) {
  2809. return Array(level).join('#') + ' ' + str;
  2810. }
  2811. function indent() {
  2812. return Array(level).join(' ');
  2813. }
  2814. function mapTOC(suite, obj) {
  2815. var ret = obj;
  2816. obj = obj[suite.title] = obj[suite.title] || { suite: suite };
  2817. suite.suites.forEach(function(suite){
  2818. mapTOC(suite, obj);
  2819. });
  2820. return ret;
  2821. }
  2822. function stringifyTOC(obj, level) {
  2823. ++level;
  2824. var buf = '';
  2825. var link;
  2826. for (var key in obj) {
  2827. if ('suite' == key) continue;
  2828. if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
  2829. if (key) buf += Array(level).join(' ') + link;
  2830. buf += stringifyTOC(obj[key], level);
  2831. }
  2832. --level;
  2833. return buf;
  2834. }
  2835. function generateTOC(suite) {
  2836. var obj = mapTOC(suite, {});
  2837. return stringifyTOC(obj, 0);
  2838. }
  2839. generateTOC(runner.suite);
  2840. runner.on('suite', function(suite){
  2841. ++level;
  2842. var slug = utils.slug(suite.fullTitle());
  2843. buf += '<a name="' + slug + '"></a>' + '\n';
  2844. buf += title(suite.title) + '\n';
  2845. });
  2846. runner.on('suite end', function(suite){
  2847. --level;
  2848. });
  2849. runner.on('pass', function(test){
  2850. var code = utils.clean(test.fn.toString());
  2851. buf += test.title + '.\n';
  2852. buf += '\n```js\n';
  2853. buf += code + '\n';
  2854. buf += '```\n\n';
  2855. });
  2856. runner.on('end', function(){
  2857. process.stdout.write('# TOC\n');
  2858. process.stdout.write(generateTOC(runner.suite));
  2859. process.stdout.write(buf);
  2860. });
  2861. }
  2862. }); // module: reporters/markdown.js
  2863. require.register("reporters/min.js", function(module, exports, require){
  2864. /**
  2865. * Module dependencies.
  2866. */
  2867. var Base = require('./base');
  2868. /**
  2869. * Expose `Min`.
  2870. */
  2871. exports = module.exports = Min;
  2872. /**
  2873. * Initialize a new `Min` minimal test reporter (best used with --watch).
  2874. *
  2875. * @param {Runner} runner
  2876. * @api public
  2877. */
  2878. function Min(runner) {
  2879. Base.call(this, runner);
  2880. runner.on('start', function(){
  2881. // clear screen
  2882. process.stdout.write('\u001b[2J');
  2883. // set cursor position
  2884. process.stdout.write('\u001b[1;3H');
  2885. });
  2886. runner.on('end', this.epilogue.bind(this));
  2887. }
  2888. /**
  2889. * Inherit from `Base.prototype`.
  2890. */
  2891. function F(){};
  2892. F.prototype = Base.prototype;
  2893. Min.prototype = new F;
  2894. Min.prototype.constructor = Min;
  2895. }); // module: reporters/min.js
  2896. require.register("reporters/nyan.js", function(module, exports, require){
  2897. /**
  2898. * Module dependencies.
  2899. */
  2900. var Base = require('./base')
  2901. , color = Base.color;
  2902. /**
  2903. * Expose `Dot`.
  2904. */
  2905. exports = module.exports = NyanCat;
  2906. /**
  2907. * Initialize a new `Dot` matrix test reporter.
  2908. *
  2909. * @param {Runner} runner
  2910. * @api public
  2911. */
  2912. function NyanCat(runner) {
  2913. Base.call(this, runner);
  2914. var self = this
  2915. , stats = this.stats
  2916. , width = Base.window.width * .75 | 0
  2917. , rainbowColors = this.rainbowColors = self.generateColors()
  2918. , colorIndex = this.colorIndex = 0
  2919. , numerOfLines = this.numberOfLines = 4
  2920. , trajectories = this.trajectories = [[], [], [], []]
  2921. , nyanCatWidth = this.nyanCatWidth = 11
  2922. , trajectoryWidthMax = this.trajectoryWidthMax = (width - nyanCatWidth)
  2923. , scoreboardWidth = this.scoreboardWidth = 5
  2924. , tick = this.tick = 0
  2925. , n = 0;
  2926. runner.on('start', function(){
  2927. Base.cursor.hide();
  2928. self.draw();
  2929. });
  2930. runner.on('pending', function(test){
  2931. self.draw();
  2932. });
  2933. runner.on('pass', function(test){
  2934. self.draw();
  2935. });
  2936. runner.on('fail', function(test, err){
  2937. self.draw();
  2938. });
  2939. runner.on('end', function(){
  2940. Base.cursor.show();
  2941. for (var i = 0; i < self.numberOfLines; i++) write('\n');
  2942. self.epilogue();
  2943. });
  2944. }
  2945. /**
  2946. * Draw the nyan cat
  2947. *
  2948. * @api private
  2949. */
  2950. NyanCat.prototype.draw = function(){
  2951. this.appendRainbow();
  2952. this.drawScoreboard();
  2953. this.drawRainbow();
  2954. this.drawNyanCat();
  2955. this.tick = !this.tick;
  2956. };
  2957. /**
  2958. * Draw the "scoreboard" showing the number
  2959. * of passes, failures and pending tests.
  2960. *
  2961. * @api private
  2962. */
  2963. NyanCat.prototype.drawScoreboard = function(){
  2964. var stats = this.stats;
  2965. var colors = Base.colors;
  2966. function draw(color, n) {
  2967. write(' ');
  2968. write('\u001b[' + color + 'm' + n + '\u001b[0m');
  2969. write('\n');
  2970. }
  2971. draw(colors.green, stats.passes);
  2972. draw(colors.fail, stats.failures);
  2973. draw(colors.pending, stats.pending);
  2974. write('\n');
  2975. this.cursorUp(this.numberOfLines);
  2976. };
  2977. /**
  2978. * Append the rainbow.
  2979. *
  2980. * @api private
  2981. */
  2982. NyanCat.prototype.appendRainbow = function(){
  2983. var segment = this.tick ? '_' : '-';
  2984. var rainbowified = this.rainbowify(segment);
  2985. for (var index = 0; index < this.numberOfLines; index++) {
  2986. var trajectory = this.trajectories[index];
  2987. if (trajectory.length >= this.trajectoryWidthMax) trajectory.shift();
  2988. trajectory.push(rainbowified);
  2989. }
  2990. };
  2991. /**
  2992. * Draw the rainbow.
  2993. *
  2994. * @api private
  2995. */
  2996. NyanCat.prototype.drawRainbow = function(){
  2997. var self = this;
  2998. this.trajectories.forEach(function(line, index) {
  2999. write('\u001b[' + self.scoreboardWidth + 'C');
  3000. write(line.join(''));
  3001. write('\n');
  3002. });
  3003. this.cursorUp(this.numberOfLines);
  3004. };
  3005. /**
  3006. * Draw the nyan cat
  3007. *
  3008. * @api private
  3009. */
  3010. NyanCat.prototype.drawNyanCat = function() {
  3011. var self = this;
  3012. var startWidth = this.scoreboardWidth + this.trajectories[0].length;
  3013. var color = '\u001b[' + startWidth + 'C';
  3014. var padding = '';
  3015. write(color);
  3016. write('_,------,');
  3017. write('\n');
  3018. write(color);
  3019. padding = self.tick ? ' ' : ' ';
  3020. write('_|' + padding + '/\\_/\\ ');
  3021. write('\n');
  3022. write(color);
  3023. padding = self.tick ? '_' : '__';
  3024. var tail = self.tick ? '~' : '^';
  3025. var face;
  3026. write(tail + '|' + padding + this.face() + ' ');
  3027. write('\n');
  3028. write(color);
  3029. padding = self.tick ? ' ' : ' ';
  3030. write(padding + '"" "" ');
  3031. write('\n');
  3032. this.cursorUp(this.numberOfLines);
  3033. };
  3034. /**
  3035. * Draw nyan cat face.
  3036. *
  3037. * @return {String}
  3038. * @api private
  3039. */
  3040. NyanCat.prototype.face = function() {
  3041. var stats = this.stats;
  3042. if (stats.failures) {
  3043. return '( x .x)';
  3044. } else if (stats.pending) {
  3045. return '( o .o)';
  3046. } else if(stats.passes) {
  3047. return '( ^ .^)';
  3048. } else {
  3049. return '( - .-)';
  3050. }
  3051. };
  3052. /**
  3053. * Move cursor up `n`.
  3054. *
  3055. * @param {Number} n
  3056. * @api private
  3057. */
  3058. NyanCat.prototype.cursorUp = function(n) {
  3059. write('\u001b[' + n + 'A');
  3060. };
  3061. /**
  3062. * Move cursor down `n`.
  3063. *
  3064. * @param {Number} n
  3065. * @api private
  3066. */
  3067. NyanCat.prototype.cursorDown = function(n) {
  3068. write('\u001b[' + n + 'B');
  3069. };
  3070. /**
  3071. * Generate rainbow colors.
  3072. *
  3073. * @return {Array}
  3074. * @api private
  3075. */
  3076. NyanCat.prototype.generateColors = function(){
  3077. var colors = [];
  3078. for (var i = 0; i < (6 * 7); i++) {
  3079. var pi3 = Math.floor(Math.PI / 3);
  3080. var n = (i * (1.0 / 6));
  3081. var r = Math.floor(3 * Math.sin(n) + 3);
  3082. var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
  3083. var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
  3084. colors.push(36 * r + 6 * g + b + 16);
  3085. }
  3086. return colors;
  3087. };
  3088. /**
  3089. * Apply rainbow to the given `str`.
  3090. *
  3091. * @param {String} str
  3092. * @return {String}
  3093. * @api private
  3094. */
  3095. NyanCat.prototype.rainbowify = function(str){
  3096. var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
  3097. this.colorIndex += 1;
  3098. return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
  3099. };
  3100. /**
  3101. * Stdout helper.
  3102. */
  3103. function write(string) {
  3104. process.stdout.write(string);
  3105. }
  3106. /**
  3107. * Inherit from `Base.prototype`.
  3108. */
  3109. function F(){};
  3110. F.prototype = Base.prototype;
  3111. NyanCat.prototype = new F;
  3112. NyanCat.prototype.constructor = NyanCat;
  3113. }); // module: reporters/nyan.js
  3114. require.register("reporters/progress.js", function(module, exports, require){
  3115. /**
  3116. * Module dependencies.
  3117. */
  3118. var Base = require('./base')
  3119. , cursor = Base.cursor
  3120. , color = Base.color;
  3121. /**
  3122. * Expose `Progress`.
  3123. */
  3124. exports = module.exports = Progress;
  3125. /**
  3126. * General progress bar color.
  3127. */
  3128. Base.colors.progress = 90;
  3129. /**
  3130. * Initialize a new `Progress` bar test reporter.
  3131. *
  3132. * @param {Runner} runner
  3133. * @param {Object} options
  3134. * @api public
  3135. */
  3136. function Progress(runner, options) {
  3137. Base.call(this, runner);
  3138. var self = this
  3139. , options = options || {}
  3140. , stats = this.stats
  3141. , width = Base.window.width * .50 | 0
  3142. , total = runner.total
  3143. , complete = 0
  3144. , max = Math.max
  3145. , lastN = -1;
  3146. // default chars
  3147. options.open = options.open || '[';
  3148. options.complete = options.complete || '▬';
  3149. options.incomplete = options.incomplete || Base.symbols.dot;
  3150. options.close = options.close || ']';
  3151. options.verbose = false;
  3152. // tests started
  3153. runner.on('start', function(){
  3154. console.log();
  3155. cursor.hide();
  3156. });
  3157. // tests complete
  3158. runner.on('test end', function(){
  3159. complete++;
  3160. var incomplete = total - complete
  3161. , percent = complete / total
  3162. , n = width * percent | 0
  3163. , i = width - n;
  3164. if (lastN === n && !options.verbose) {
  3165. // Don't re-render the line if it hasn't changed
  3166. return;
  3167. }
  3168. lastN = n;
  3169. cursor.CR();
  3170. process.stdout.write('\u001b[J');
  3171. process.stdout.write(color('progress', ' ' + options.open));
  3172. process.stdout.write(Array(n).join(options.complete));
  3173. process.stdout.write(Array(i).join(options.incomplete));
  3174. process.stdout.write(color('progress', options.close));
  3175. if (options.verbose) {
  3176. process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
  3177. }
  3178. });
  3179. // tests are complete, output some stats
  3180. // and the failures if any
  3181. runner.on('end', function(){
  3182. cursor.show();
  3183. console.log();
  3184. self.epilogue();
  3185. });
  3186. }
  3187. /**
  3188. * Inherit from `Base.prototype`.
  3189. */
  3190. function F(){};
  3191. F.prototype = Base.prototype;
  3192. Progress.prototype = new F;
  3193. Progress.prototype.constructor = Progress;
  3194. }); // module: reporters/progress.js
  3195. require.register("reporters/spec.js", function(module, exports, require){
  3196. /**
  3197. * Module dependencies.
  3198. */
  3199. var Base = require('./base')
  3200. , cursor = Base.cursor
  3201. , color = Base.color;
  3202. /**
  3203. * Expose `Spec`.
  3204. */
  3205. exports = module.exports = Spec;
  3206. /**
  3207. * Initialize a new `Spec` test reporter.
  3208. *
  3209. * @param {Runner} runner
  3210. * @api public
  3211. */
  3212. function Spec(runner) {
  3213. Base.call(this, runner);
  3214. var self = this
  3215. , stats = this.stats
  3216. , indents = 0
  3217. , n = 0;
  3218. function indent() {
  3219. return Array(indents).join(' ')
  3220. }
  3221. runner.on('start', function(){
  3222. console.log();
  3223. });
  3224. runner.on('suite', function(suite){
  3225. ++indents;
  3226. console.log(color('suite', '%s%s'), indent(), suite.title);
  3227. });
  3228. runner.on('suite end', function(suite){
  3229. --indents;
  3230. if (1 == indents) console.log();
  3231. });
  3232. runner.on('pending', function(test){
  3233. var fmt = indent() + color('pending', ' - %s');
  3234. console.log(fmt, test.title);
  3235. });
  3236. runner.on('pass', function(test){
  3237. if ('fast' == test.speed) {
  3238. var fmt = indent()
  3239. + color('checkmark', ' ' + Base.symbols.ok)
  3240. + color('pass', ' %s ');
  3241. cursor.CR();
  3242. console.log(fmt, test.title);
  3243. } else {
  3244. var fmt = indent()
  3245. + color('checkmark', ' ' + Base.symbols.ok)
  3246. + color('pass', ' %s ')
  3247. + color(test.speed, '(%dms)');
  3248. cursor.CR();
  3249. console.log(fmt, test.title, test.duration);
  3250. }
  3251. });
  3252. runner.on('fail', function(test, err){
  3253. cursor.CR();
  3254. console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
  3255. });
  3256. runner.on('end', self.epilogue.bind(self));
  3257. }
  3258. /**
  3259. * Inherit from `Base.prototype`.
  3260. */
  3261. function F(){};
  3262. F.prototype = Base.prototype;
  3263. Spec.prototype = new F;
  3264. Spec.prototype.constructor = Spec;
  3265. }); // module: reporters/spec.js
  3266. require.register("reporters/tap.js", function(module, exports, require){
  3267. /**
  3268. * Module dependencies.
  3269. */
  3270. var Base = require('./base')
  3271. , cursor = Base.cursor
  3272. , color = Base.color;
  3273. /**
  3274. * Expose `TAP`.
  3275. */
  3276. exports = module.exports = TAP;
  3277. /**
  3278. * Initialize a new `TAP` reporter.
  3279. *
  3280. * @param {Runner} runner
  3281. * @api public
  3282. */
  3283. function TAP(runner) {
  3284. Base.call(this, runner);
  3285. var self = this
  3286. , stats = this.stats
  3287. , n = 1
  3288. , passes = 0
  3289. , failures = 0;
  3290. runner.on('start', function(){
  3291. var total = runner.grepTotal(runner.suite);
  3292. console.log('%d..%d', 1, total);
  3293. });
  3294. runner.on('test end', function(){
  3295. ++n;
  3296. });
  3297. runner.on('pending', function(test){
  3298. console.log('ok %d %s # SKIP -', n, title(test));
  3299. });
  3300. runner.on('pass', function(test){
  3301. passes++;
  3302. console.log('ok %d %s', n, title(test));
  3303. });
  3304. runner.on('fail', function(test, err){
  3305. failures++;
  3306. console.log('not ok %d %s', n, title(test));
  3307. if (err.stack) console.log(err.stack.replace(/^/gm, ' '));
  3308. });
  3309. runner.on('end', function(){
  3310. console.log('# tests ' + (passes + failures));
  3311. console.log('# pass ' + passes);
  3312. console.log('# fail ' + failures);
  3313. });
  3314. }
  3315. /**
  3316. * Return a TAP-safe title of `test`
  3317. *
  3318. * @param {Object} test
  3319. * @return {String}
  3320. * @api private
  3321. */
  3322. function title(test) {
  3323. return test.fullTitle().replace(/#/g, '');
  3324. }
  3325. }); // module: reporters/tap.js
  3326. require.register("reporters/xunit.js", function(module, exports, require){
  3327. /**
  3328. * Module dependencies.
  3329. */
  3330. var Base = require('./base')
  3331. , utils = require('../utils')
  3332. , escape = utils.escape;
  3333. /**
  3334. * Save timer references to avoid Sinon interfering (see GH-237).
  3335. */
  3336. var Date = global.Date
  3337. , setTimeout = global.setTimeout
  3338. , setInterval = global.setInterval
  3339. , clearTimeout = global.clearTimeout
  3340. , clearInterval = global.clearInterval;
  3341. /**
  3342. * Expose `XUnit`.
  3343. */
  3344. exports = module.exports = XUnit;
  3345. /**
  3346. * Initialize a new `XUnit` reporter.
  3347. *
  3348. * @param {Runner} runner
  3349. * @api public
  3350. */
  3351. function XUnit(runner) {
  3352. Base.call(this, runner);
  3353. var stats = this.stats
  3354. , tests = []
  3355. , self = this;
  3356. runner.on('pending', function(test){
  3357. tests.push(test);
  3358. });
  3359. runner.on('pass', function(test){
  3360. tests.push(test);
  3361. });
  3362. runner.on('fail', function(test){
  3363. tests.push(test);
  3364. });
  3365. runner.on('end', function(){
  3366. console.log(tag('testsuite', {
  3367. name: 'Mocha Tests'
  3368. , tests: stats.tests
  3369. , failures: stats.failures
  3370. , errors: stats.failures
  3371. , skipped: stats.tests - stats.failures - stats.passes
  3372. , timestamp: (new Date).toUTCString()
  3373. , time: (stats.duration / 1000) || 0
  3374. }, false));
  3375. tests.forEach(test);
  3376. console.log('</testsuite>');
  3377. });
  3378. }
  3379. /**
  3380. * Inherit from `Base.prototype`.
  3381. */
  3382. function F(){};
  3383. F.prototype = Base.prototype;
  3384. XUnit.prototype = new F;
  3385. XUnit.prototype.constructor = XUnit;
  3386. /**
  3387. * Output tag for the given `test.`
  3388. */
  3389. function test(test) {
  3390. var attrs = {
  3391. classname: test.parent.fullTitle()
  3392. , name: test.title
  3393. , time: (test.duration / 1000) || 0
  3394. };
  3395. if ('failed' == test.state) {
  3396. var err = test.err;
  3397. console.log(tag('testcase', attrs, false, tag('failure', {}, false, cdata(escape(err.message) + "\n" + err.stack))));
  3398. } else if (test.pending) {
  3399. console.log(tag('testcase', attrs, false, tag('skipped', {}, true)));
  3400. } else {
  3401. console.log(tag('testcase', attrs, true) );
  3402. }
  3403. }
  3404. /**
  3405. * HTML tag helper.
  3406. */
  3407. function tag(name, attrs, close, content) {
  3408. var end = close ? '/>' : '>'
  3409. , pairs = []
  3410. , tag;
  3411. for (var key in attrs) {
  3412. pairs.push(key + '="' + escape(attrs[key]) + '"');
  3413. }
  3414. tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
  3415. if (content) tag += content + '</' + name + end;
  3416. return tag;
  3417. }
  3418. /**
  3419. * Return cdata escaped CDATA `str`.
  3420. */
  3421. function cdata(str) {
  3422. return '<![CDATA[' + escape(str) + ']]>';
  3423. }
  3424. }); // module: reporters/xunit.js
  3425. require.register("runnable.js", function(module, exports, require){
  3426. /**
  3427. * Module dependencies.
  3428. */
  3429. var EventEmitter = require('browser/events').EventEmitter
  3430. , debug = require('browser/debug')('mocha:runnable')
  3431. , milliseconds = require('./ms');
  3432. /**
  3433. * Save timer references to avoid Sinon interfering (see GH-237).
  3434. */
  3435. var Date = global.Date
  3436. , setTimeout = global.setTimeout
  3437. , setInterval = global.setInterval
  3438. , clearTimeout = global.clearTimeout
  3439. , clearInterval = global.clearInterval;
  3440. /**
  3441. * Object#toString().
  3442. */
  3443. var toString = Object.prototype.toString;
  3444. /**
  3445. * Expose `Runnable`.
  3446. */
  3447. module.exports = Runnable;
  3448. /**
  3449. * Initialize a new `Runnable` with the given `title` and callback `fn`.
  3450. *
  3451. * @param {String} title
  3452. * @param {Function} fn
  3453. * @api private
  3454. */
  3455. function Runnable(title, fn) {
  3456. this.title = title;
  3457. this.fn = fn;
  3458. this.async = fn && fn.length;
  3459. this.sync = ! this.async;
  3460. this._timeout = 2000;
  3461. this._slow = 75;
  3462. this._enableTimeouts = true;
  3463. this.timedOut = false;
  3464. this._trace = new Error('done() called multiple times')
  3465. }
  3466. /**
  3467. * Inherit from `EventEmitter.prototype`.
  3468. */
  3469. function F(){};
  3470. F.prototype = EventEmitter.prototype;
  3471. Runnable.prototype = new F;
  3472. Runnable.prototype.constructor = Runnable;
  3473. /**
  3474. * Set & get timeout `ms`.
  3475. *
  3476. * @param {Number|String} ms
  3477. * @return {Runnable|Number} ms or self
  3478. * @api private
  3479. */
  3480. Runnable.prototype.timeout = function(ms){
  3481. if (0 == arguments.length) return this._timeout;
  3482. if (ms === 0) this._enableTimeouts = false;
  3483. if ('string' == typeof ms) ms = milliseconds(ms);
  3484. debug('timeout %d', ms);
  3485. this._timeout = ms;
  3486. if (this.timer) this.resetTimeout();
  3487. return this;
  3488. };
  3489. /**
  3490. * Set & get slow `ms`.
  3491. *
  3492. * @param {Number|String} ms
  3493. * @return {Runnable|Number} ms or self
  3494. * @api private
  3495. */
  3496. Runnable.prototype.slow = function(ms){
  3497. if (0 === arguments.length) return this._slow;
  3498. if ('string' == typeof ms) ms = milliseconds(ms);
  3499. debug('timeout %d', ms);
  3500. this._slow = ms;
  3501. return this;
  3502. };
  3503. /**
  3504. * Set and & get timeout `enabled`.
  3505. *
  3506. * @param {Boolean} enabled
  3507. * @return {Runnable|Boolean} enabled or self
  3508. * @api private
  3509. */
  3510. Runnable.prototype.enableTimeouts = function(enabled){
  3511. if (arguments.length === 0) return this._enableTimeouts;
  3512. debug('enableTimeouts %s', enabled);
  3513. this._enableTimeouts = enabled;
  3514. return this;
  3515. };
  3516. /**
  3517. * Return the full title generated by recursively
  3518. * concatenating the parent's full title.
  3519. *
  3520. * @return {String}
  3521. * @api public
  3522. */
  3523. Runnable.prototype.fullTitle = function(){
  3524. return this.parent.fullTitle() + ' ' + this.title;
  3525. };
  3526. /**
  3527. * Clear the timeout.
  3528. *
  3529. * @api private
  3530. */
  3531. Runnable.prototype.clearTimeout = function(){
  3532. clearTimeout(this.timer);
  3533. };
  3534. /**
  3535. * Inspect the runnable void of private properties.
  3536. *
  3537. * @return {String}
  3538. * @api private
  3539. */
  3540. Runnable.prototype.inspect = function(){
  3541. return JSON.stringify(this, function(key, val){
  3542. if ('_' == key[0]) return;
  3543. if ('parent' == key) return '#<Suite>';
  3544. if ('ctx' == key) return '#<Context>';
  3545. return val;
  3546. }, 2);
  3547. };
  3548. /**
  3549. * Reset the timeout.
  3550. *
  3551. * @api private
  3552. */
  3553. Runnable.prototype.resetTimeout = function(){
  3554. var self = this;
  3555. var ms = this.timeout() || 1e9;
  3556. if (!this._enableTimeouts) return;
  3557. this.clearTimeout();
  3558. this.timer = setTimeout(function(){
  3559. if (!self._enableTimeouts) return;
  3560. self.callback(new Error('timeout of ' + ms + 'ms exceeded'));
  3561. self.timedOut = true;
  3562. }, ms);
  3563. };
  3564. /**
  3565. * Whitelist these globals for this test run
  3566. *
  3567. * @api private
  3568. */
  3569. Runnable.prototype.globals = function(arr){
  3570. var self = this;
  3571. this._allowedGlobals = arr;
  3572. };
  3573. /**
  3574. * Run the test and invoke `fn(err)`.
  3575. *
  3576. * @param {Function} fn
  3577. * @api private
  3578. */
  3579. Runnable.prototype.run = function(fn){
  3580. var self = this
  3581. , start = new Date
  3582. , ctx = this.ctx
  3583. , finished
  3584. , emitted;
  3585. // Some times the ctx exists but it is not runnable
  3586. if (ctx && ctx.runnable) ctx.runnable(this);
  3587. // called multiple times
  3588. function multiple(err) {
  3589. if (emitted) return;
  3590. emitted = true;
  3591. self.emit('error', err || new Error('done() called multiple times; stacktrace may be inaccurate'));
  3592. }
  3593. // finished
  3594. function done(err) {
  3595. var ms = self.timeout();
  3596. if (self.timedOut) return;
  3597. if (finished) return multiple(err || self._trace);
  3598. self.clearTimeout();
  3599. self.duration = new Date - start;
  3600. finished = true;
  3601. if (!err && self.duration > ms && self._enableTimeouts) err = new Error('timeout of ' + ms + 'ms exceeded');
  3602. fn(err);
  3603. }
  3604. // for .resetTimeout()
  3605. this.callback = done;
  3606. // explicit async with `done` argument
  3607. if (this.async) {
  3608. this.resetTimeout();
  3609. try {
  3610. this.fn.call(ctx, function(err){
  3611. if (err instanceof Error || toString.call(err) === "[object Error]") return done(err);
  3612. if (null != err) {
  3613. if (Object.prototype.toString.call(err) === '[object Object]') {
  3614. return done(new Error('done() invoked with non-Error: ' + JSON.stringify(err)));
  3615. } else {
  3616. return done(new Error('done() invoked with non-Error: ' + err));
  3617. }
  3618. }
  3619. done();
  3620. });
  3621. } catch (err) {
  3622. done(err);
  3623. }
  3624. return;
  3625. }
  3626. if (this.asyncOnly) {
  3627. return done(new Error('--async-only option in use without declaring `done()`'));
  3628. }
  3629. // sync or promise-returning
  3630. try {
  3631. if (this.pending) {
  3632. done();
  3633. } else {
  3634. callFn(this.fn);
  3635. }
  3636. } catch (err) {
  3637. done(err);
  3638. }
  3639. function callFn(fn) {
  3640. var result = fn.call(ctx);
  3641. if (result && typeof result.then === 'function') {
  3642. self.resetTimeout();
  3643. result
  3644. .then(function() {
  3645. done()
  3646. },
  3647. function(reason) {
  3648. done(reason || new Error('Promise rejected with no or falsy reason'))
  3649. });
  3650. } else {
  3651. done();
  3652. }
  3653. }
  3654. };
  3655. }); // module: runnable.js
  3656. require.register("runner.js", function(module, exports, require){
  3657. /**
  3658. * Module dependencies.
  3659. */
  3660. var EventEmitter = require('browser/events').EventEmitter
  3661. , debug = require('browser/debug')('mocha:runner')
  3662. , Test = require('./test')
  3663. , utils = require('./utils')
  3664. , filter = utils.filter
  3665. , keys = utils.keys;
  3666. /**
  3667. * Non-enumerable globals.
  3668. */
  3669. var globals = [
  3670. 'setTimeout',
  3671. 'clearTimeout',
  3672. 'setInterval',
  3673. 'clearInterval',
  3674. 'XMLHttpRequest',
  3675. 'Date'
  3676. ];
  3677. /**
  3678. * Expose `Runner`.
  3679. */
  3680. module.exports = Runner;
  3681. /**
  3682. * Initialize a `Runner` for the given `suite`.
  3683. *
  3684. * Events:
  3685. *
  3686. * - `start` execution started
  3687. * - `end` execution complete
  3688. * - `suite` (suite) test suite execution started
  3689. * - `suite end` (suite) all tests (and sub-suites) have finished
  3690. * - `test` (test) test execution started
  3691. * - `test end` (test) test completed
  3692. * - `hook` (hook) hook execution started
  3693. * - `hook end` (hook) hook complete
  3694. * - `pass` (test) test passed
  3695. * - `fail` (test, err) test failed
  3696. * - `pending` (test) test pending
  3697. *
  3698. * @api public
  3699. */
  3700. function Runner(suite) {
  3701. var self = this;
  3702. this._globals = [];
  3703. this._abort = false;
  3704. this.suite = suite;
  3705. this.total = suite.total();
  3706. this.failures = 0;
  3707. this.on('test end', function(test){ self.checkGlobals(test); });
  3708. this.on('hook end', function(hook){ self.checkGlobals(hook); });
  3709. this.grep(/.*/);
  3710. this.globals(this.globalProps().concat(extraGlobals()));
  3711. }
  3712. /**
  3713. * Wrapper for setImmediate, process.nextTick, or browser polyfill.
  3714. *
  3715. * @param {Function} fn
  3716. * @api private
  3717. */
  3718. Runner.immediately = global.setImmediate || process.nextTick;
  3719. /**
  3720. * Inherit from `EventEmitter.prototype`.
  3721. */
  3722. function F(){};
  3723. F.prototype = EventEmitter.prototype;
  3724. Runner.prototype = new F;
  3725. Runner.prototype.constructor = Runner;
  3726. /**
  3727. * Run tests with full titles matching `re`. Updates runner.total
  3728. * with number of tests matched.
  3729. *
  3730. * @param {RegExp} re
  3731. * @param {Boolean} invert
  3732. * @return {Runner} for chaining
  3733. * @api public
  3734. */
  3735. Runner.prototype.grep = function(re, invert){
  3736. debug('grep %s', re);
  3737. this._grep = re;
  3738. this._invert = invert;
  3739. this.total = this.grepTotal(this.suite);
  3740. return this;
  3741. };
  3742. /**
  3743. * Returns the number of tests matching the grep search for the
  3744. * given suite.
  3745. *
  3746. * @param {Suite} suite
  3747. * @return {Number}
  3748. * @api public
  3749. */
  3750. Runner.prototype.grepTotal = function(suite) {
  3751. var self = this;
  3752. var total = 0;
  3753. suite.eachTest(function(test){
  3754. var match = self._grep.test(test.fullTitle());
  3755. if (self._invert) match = !match;
  3756. if (match) total++;
  3757. });
  3758. return total;
  3759. };
  3760. /**
  3761. * Return a list of global properties.
  3762. *
  3763. * @return {Array}
  3764. * @api private
  3765. */
  3766. Runner.prototype.globalProps = function() {
  3767. var props = utils.keys(global);
  3768. // non-enumerables
  3769. for (var i = 0; i < globals.length; ++i) {
  3770. if (~utils.indexOf(props, globals[i])) continue;
  3771. props.push(globals[i]);
  3772. }
  3773. return props;
  3774. };
  3775. /**
  3776. * Allow the given `arr` of globals.
  3777. *
  3778. * @param {Array} arr
  3779. * @return {Runner} for chaining
  3780. * @api public
  3781. */
  3782. Runner.prototype.globals = function(arr){
  3783. if (0 == arguments.length) return this._globals;
  3784. debug('globals %j', arr);
  3785. this._globals = this._globals.concat(arr);
  3786. return this;
  3787. };
  3788. /**
  3789. * Check for global variable leaks.
  3790. *
  3791. * @api private
  3792. */
  3793. Runner.prototype.checkGlobals = function(test){
  3794. if (this.ignoreLeaks) return;
  3795. var ok = this._globals;
  3796. var globals = this.globalProps();
  3797. var leaks;
  3798. if (test) {
  3799. ok = ok.concat(test._allowedGlobals || []);
  3800. }
  3801. if(this.prevGlobalsLength == globals.length) return;
  3802. this.prevGlobalsLength = globals.length;
  3803. leaks = filterLeaks(ok, globals);
  3804. this._globals = this._globals.concat(leaks);
  3805. if (leaks.length > 1) {
  3806. this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
  3807. } else if (leaks.length) {
  3808. this.fail(test, new Error('global leak detected: ' + leaks[0]));
  3809. }
  3810. };
  3811. /**
  3812. * Fail the given `test`.
  3813. *
  3814. * @param {Test} test
  3815. * @param {Error} err
  3816. * @api private
  3817. */
  3818. Runner.prototype.fail = function(test, err){
  3819. ++this.failures;
  3820. test.state = 'failed';
  3821. if ('string' == typeof err) {
  3822. err = new Error('the string "' + err + '" was thrown, throw an Error :)');
  3823. }
  3824. this.emit('fail', test, err);
  3825. };
  3826. /**
  3827. * Fail the given `hook` with `err`.
  3828. *
  3829. * Hook failures work in the following pattern:
  3830. * - If bail, then exit
  3831. * - Failed `before` hook skips all tests in a suite and subsuites,
  3832. * but jumps to corresponding `after` hook
  3833. * - Failed `before each` hook skips remaining tests in a
  3834. * suite and jumps to corresponding `after each` hook,
  3835. * which is run only once
  3836. * - Failed `after` hook does not alter
  3837. * execution order
  3838. * - Failed `after each` hook skips remaining tests in a
  3839. * suite and subsuites, but executes other `after each`
  3840. * hooks
  3841. *
  3842. * @param {Hook} hook
  3843. * @param {Error} err
  3844. * @api private
  3845. */
  3846. Runner.prototype.failHook = function(hook, err){
  3847. this.fail(hook, err);
  3848. if (this.suite.bail()) {
  3849. this.emit('end');
  3850. }
  3851. };
  3852. /**
  3853. * Run hook `name` callbacks and then invoke `fn()`.
  3854. *
  3855. * @param {String} name
  3856. * @param {Function} function
  3857. * @api private
  3858. */
  3859. Runner.prototype.hook = function(name, fn){
  3860. var suite = this.suite
  3861. , hooks = suite['_' + name]
  3862. , self = this
  3863. , timer;
  3864. function next(i) {
  3865. var hook = hooks[i];
  3866. if (!hook) return fn();
  3867. if (self.failures && suite.bail()) return fn();
  3868. self.currentRunnable = hook;
  3869. hook.ctx.currentTest = self.test;
  3870. self.emit('hook', hook);
  3871. hook.on('error', function(err){
  3872. self.failHook(hook, err);
  3873. });
  3874. hook.run(function(err){
  3875. hook.removeAllListeners('error');
  3876. var testError = hook.error();
  3877. if (testError) self.fail(self.test, testError);
  3878. if (err) {
  3879. self.failHook(hook, err);
  3880. // stop executing hooks, notify callee of hook err
  3881. return fn(err);
  3882. }
  3883. self.emit('hook end', hook);
  3884. delete hook.ctx.currentTest;
  3885. next(++i);
  3886. });
  3887. }
  3888. Runner.immediately(function(){
  3889. next(0);
  3890. });
  3891. };
  3892. /**
  3893. * Run hook `name` for the given array of `suites`
  3894. * in order, and callback `fn(err, errSuite)`.
  3895. *
  3896. * @param {String} name
  3897. * @param {Array} suites
  3898. * @param {Function} fn
  3899. * @api private
  3900. */
  3901. Runner.prototype.hooks = function(name, suites, fn){
  3902. var self = this
  3903. , orig = this.suite;
  3904. function next(suite) {
  3905. self.suite = suite;
  3906. if (!suite) {
  3907. self.suite = orig;
  3908. return fn();
  3909. }
  3910. self.hook(name, function(err){
  3911. if (err) {
  3912. var errSuite = self.suite;
  3913. self.suite = orig;
  3914. return fn(err, errSuite);
  3915. }
  3916. next(suites.pop());
  3917. });
  3918. }
  3919. next(suites.pop());
  3920. };
  3921. /**
  3922. * Run hooks from the top level down.
  3923. *
  3924. * @param {String} name
  3925. * @param {Function} fn
  3926. * @api private
  3927. */
  3928. Runner.prototype.hookUp = function(name, fn){
  3929. var suites = [this.suite].concat(this.parents()).reverse();
  3930. this.hooks(name, suites, fn);
  3931. };
  3932. /**
  3933. * Run hooks from the bottom up.
  3934. *
  3935. * @param {String} name
  3936. * @param {Function} fn
  3937. * @api private
  3938. */
  3939. Runner.prototype.hookDown = function(name, fn){
  3940. var suites = [this.suite].concat(this.parents());
  3941. this.hooks(name, suites, fn);
  3942. };
  3943. /**
  3944. * Return an array of parent Suites from
  3945. * closest to furthest.
  3946. *
  3947. * @return {Array}
  3948. * @api private
  3949. */
  3950. Runner.prototype.parents = function(){
  3951. var suite = this.suite
  3952. , suites = [];
  3953. while (suite = suite.parent) suites.push(suite);
  3954. return suites;
  3955. };
  3956. /**
  3957. * Run the current test and callback `fn(err)`.
  3958. *
  3959. * @param {Function} fn
  3960. * @api private
  3961. */
  3962. Runner.prototype.runTest = function(fn){
  3963. var test = this.test
  3964. , self = this;
  3965. if (this.asyncOnly) test.asyncOnly = true;
  3966. try {
  3967. test.on('error', function(err){
  3968. self.fail(test, err);
  3969. });
  3970. test.run(fn);
  3971. } catch (err) {
  3972. fn(err);
  3973. }
  3974. };
  3975. /**
  3976. * Run tests in the given `suite` and invoke
  3977. * the callback `fn()` when complete.
  3978. *
  3979. * @param {Suite} suite
  3980. * @param {Function} fn
  3981. * @api private
  3982. */
  3983. Runner.prototype.runTests = function(suite, fn){
  3984. var self = this
  3985. , tests = suite.tests.slice()
  3986. , test;
  3987. function hookErr(err, errSuite, after) {
  3988. // before/after Each hook for errSuite failed:
  3989. var orig = self.suite;
  3990. // for failed 'after each' hook start from errSuite parent,
  3991. // otherwise start from errSuite itself
  3992. self.suite = after ? errSuite.parent : errSuite;
  3993. if (self.suite) {
  3994. // call hookUp afterEach
  3995. self.hookUp('afterEach', function(err2, errSuite2) {
  3996. self.suite = orig;
  3997. // some hooks may fail even now
  3998. if (err2) return hookErr(err2, errSuite2, true);
  3999. // report error suite
  4000. fn(errSuite);
  4001. });
  4002. } else {
  4003. // there is no need calling other 'after each' hooks
  4004. self.suite = orig;
  4005. fn(errSuite);
  4006. }
  4007. }
  4008. function next(err, errSuite) {
  4009. // if we bail after first err
  4010. if (self.failures && suite._bail) return fn();
  4011. if (self._abort) return fn();
  4012. if (err) return hookErr(err, errSuite, true);
  4013. // next test
  4014. test = tests.shift();
  4015. // all done
  4016. if (!test) return fn();
  4017. // grep
  4018. var match = self._grep.test(test.fullTitle());
  4019. if (self._invert) match = !match;
  4020. if (!match) return next();
  4021. // pending
  4022. if (test.pending) {
  4023. self.emit('pending', test);
  4024. self.emit('test end', test);
  4025. return next();
  4026. }
  4027. // execute test and hook(s)
  4028. self.emit('test', self.test = test);
  4029. self.hookDown('beforeEach', function(err, errSuite){
  4030. if (err) return hookErr(err, errSuite, false);
  4031. self.currentRunnable = self.test;
  4032. self.runTest(function(err){
  4033. test = self.test;
  4034. if (err) {
  4035. self.fail(test, err);
  4036. self.emit('test end', test);
  4037. return self.hookUp('afterEach', next);
  4038. }
  4039. test.state = 'passed';
  4040. self.emit('pass', test);
  4041. self.emit('test end', test);
  4042. self.hookUp('afterEach', next);
  4043. });
  4044. });
  4045. }
  4046. this.next = next;
  4047. next();
  4048. };
  4049. /**
  4050. * Run the given `suite` and invoke the
  4051. * callback `fn()` when complete.
  4052. *
  4053. * @param {Suite} suite
  4054. * @param {Function} fn
  4055. * @api private
  4056. */
  4057. Runner.prototype.runSuite = function(suite, fn){
  4058. var total = this.grepTotal(suite)
  4059. , self = this
  4060. , i = 0;
  4061. debug('run suite %s', suite.fullTitle());
  4062. if (!total) return fn();
  4063. this.emit('suite', this.suite = suite);
  4064. function next(errSuite) {
  4065. if (errSuite) {
  4066. // current suite failed on a hook from errSuite
  4067. if (errSuite == suite) {
  4068. // if errSuite is current suite
  4069. // continue to the next sibling suite
  4070. return done();
  4071. } else {
  4072. // errSuite is among the parents of current suite
  4073. // stop execution of errSuite and all sub-suites
  4074. return done(errSuite);
  4075. }
  4076. }
  4077. if (self._abort) return done();
  4078. var curr = suite.suites[i++];
  4079. if (!curr) return done();
  4080. self.runSuite(curr, next);
  4081. }
  4082. function done(errSuite) {
  4083. self.suite = suite;
  4084. self.hook('afterAll', function(){
  4085. self.emit('suite end', suite);
  4086. fn(errSuite);
  4087. });
  4088. }
  4089. this.hook('beforeAll', function(err){
  4090. if (err) return done();
  4091. self.runTests(suite, next);
  4092. });
  4093. };
  4094. /**
  4095. * Handle uncaught exceptions.
  4096. *
  4097. * @param {Error} err
  4098. * @api private
  4099. */
  4100. Runner.prototype.uncaught = function(err){
  4101. if (err) {
  4102. debug('uncaught exception %s', err !== function () {
  4103. return this;
  4104. }.call(err) ? err : ( err.message || err ));
  4105. } else {
  4106. debug('uncaught undefined exception');
  4107. err = new Error('Caught undefined error, did you throw without specifying what?');
  4108. }
  4109. err.uncaught = true;
  4110. var runnable = this.currentRunnable;
  4111. if (!runnable) return;
  4112. var wasAlreadyDone = runnable.state;
  4113. this.fail(runnable, err);
  4114. runnable.clearTimeout();
  4115. if (wasAlreadyDone) return;
  4116. // recover from test
  4117. if ('test' == runnable.type) {
  4118. this.emit('test end', runnable);
  4119. this.hookUp('afterEach', this.next);
  4120. return;
  4121. }
  4122. // bail on hooks
  4123. this.emit('end');
  4124. };
  4125. /**
  4126. * Run the root suite and invoke `fn(failures)`
  4127. * on completion.
  4128. *
  4129. * @param {Function} fn
  4130. * @return {Runner} for chaining
  4131. * @api public
  4132. */
  4133. Runner.prototype.run = function(fn){
  4134. var self = this
  4135. , fn = fn || function(){};
  4136. function uncaught(err){
  4137. self.uncaught(err);
  4138. }
  4139. debug('start');
  4140. // callback
  4141. this.on('end', function(){
  4142. debug('end');
  4143. process.removeListener('uncaughtException', uncaught);
  4144. fn(self.failures);
  4145. });
  4146. // run suites
  4147. this.emit('start');
  4148. this.runSuite(this.suite, function(){
  4149. debug('finished running');
  4150. self.emit('end');
  4151. });
  4152. // uncaught exception
  4153. process.on('uncaughtException', uncaught);
  4154. return this;
  4155. };
  4156. /**
  4157. * Cleanly abort execution
  4158. *
  4159. * @return {Runner} for chaining
  4160. * @api public
  4161. */
  4162. Runner.prototype.abort = function(){
  4163. debug('aborting');
  4164. this._abort = true;
  4165. };
  4166. /**
  4167. * Filter leaks with the given globals flagged as `ok`.
  4168. *
  4169. * @param {Array} ok
  4170. * @param {Array} globals
  4171. * @return {Array}
  4172. * @api private
  4173. */
  4174. function filterLeaks(ok, globals) {
  4175. return filter(globals, function(key){
  4176. // Firefox and Chrome exposes iframes as index inside the window object
  4177. if (/^d+/.test(key)) return false;
  4178. // in firefox
  4179. // if runner runs in an iframe, this iframe's window.getInterface method not init at first
  4180. // it is assigned in some seconds
  4181. if (global.navigator && /^getInterface/.test(key)) return false;
  4182. // an iframe could be approached by window[iframeIndex]
  4183. // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
  4184. if (global.navigator && /^\d+/.test(key)) return false;
  4185. // Opera and IE expose global variables for HTML element IDs (issue #243)
  4186. if (/^mocha-/.test(key)) return false;
  4187. var matched = filter(ok, function(ok){
  4188. if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]);
  4189. return key == ok;
  4190. });
  4191. return matched.length == 0 && (!global.navigator || 'onerror' !== key);
  4192. });
  4193. }
  4194. /**
  4195. * Array of globals dependent on the environment.
  4196. *
  4197. * @return {Array}
  4198. * @api private
  4199. */
  4200. function extraGlobals() {
  4201. if (typeof(process) === 'object' &&
  4202. typeof(process.version) === 'string') {
  4203. var nodeVersion = process.version.split('.').reduce(function(a, v) {
  4204. return a << 8 | v;
  4205. });
  4206. // 'errno' was renamed to process._errno in v0.9.11.
  4207. if (nodeVersion < 0x00090B) {
  4208. return ['errno'];
  4209. }
  4210. }
  4211. return [];
  4212. }
  4213. }); // module: runner.js
  4214. require.register("suite.js", function(module, exports, require){
  4215. /**
  4216. * Module dependencies.
  4217. */
  4218. var EventEmitter = require('browser/events').EventEmitter
  4219. , debug = require('browser/debug')('mocha:suite')
  4220. , milliseconds = require('./ms')
  4221. , utils = require('./utils')
  4222. , Hook = require('./hook');
  4223. /**
  4224. * Expose `Suite`.
  4225. */
  4226. exports = module.exports = Suite;
  4227. /**
  4228. * Create a new `Suite` with the given `title`
  4229. * and parent `Suite`. When a suite with the
  4230. * same title is already present, that suite
  4231. * is returned to provide nicer reporter
  4232. * and more flexible meta-testing.
  4233. *
  4234. * @param {Suite} parent
  4235. * @param {String} title
  4236. * @return {Suite}
  4237. * @api public
  4238. */
  4239. exports.create = function(parent, title){
  4240. var suite = new Suite(title, parent.ctx);
  4241. suite.parent = parent;
  4242. if (parent.pending) suite.pending = true;
  4243. title = suite.fullTitle();
  4244. parent.addSuite(suite);
  4245. return suite;
  4246. };
  4247. /**
  4248. * Initialize a new `Suite` with the given
  4249. * `title` and `ctx`.
  4250. *
  4251. * @param {String} title
  4252. * @param {Context} ctx
  4253. * @api private
  4254. */
  4255. function Suite(title, parentContext) {
  4256. this.title = title;
  4257. var context = function() {};
  4258. context.prototype = parentContext;
  4259. this.ctx = new context();
  4260. this.suites = [];
  4261. this.tests = [];
  4262. this.pending = false;
  4263. this._beforeEach = [];
  4264. this._beforeAll = [];
  4265. this._afterEach = [];
  4266. this._afterAll = [];
  4267. this.root = !title;
  4268. this._timeout = 2000;
  4269. this._enableTimeouts = true;
  4270. this._slow = 75;
  4271. this._bail = false;
  4272. }
  4273. /**
  4274. * Inherit from `EventEmitter.prototype`.
  4275. */
  4276. function F(){};
  4277. F.prototype = EventEmitter.prototype;
  4278. Suite.prototype = new F;
  4279. Suite.prototype.constructor = Suite;
  4280. /**
  4281. * Return a clone of this `Suite`.
  4282. *
  4283. * @return {Suite}
  4284. * @api private
  4285. */
  4286. Suite.prototype.clone = function(){
  4287. var suite = new Suite(this.title);
  4288. debug('clone');
  4289. suite.ctx = this.ctx;
  4290. suite.timeout(this.timeout());
  4291. suite.enableTimeouts(this.enableTimeouts());
  4292. suite.slow(this.slow());
  4293. suite.bail(this.bail());
  4294. return suite;
  4295. };
  4296. /**
  4297. * Set timeout `ms` or short-hand such as "2s".
  4298. *
  4299. * @param {Number|String} ms
  4300. * @return {Suite|Number} for chaining
  4301. * @api private
  4302. */
  4303. Suite.prototype.timeout = function(ms){
  4304. if (0 == arguments.length) return this._timeout;
  4305. if (ms === 0) this._enableTimeouts = false;
  4306. if ('string' == typeof ms) ms = milliseconds(ms);
  4307. debug('timeout %d', ms);
  4308. this._timeout = parseInt(ms, 10);
  4309. return this;
  4310. };
  4311. /**
  4312. * Set timeout `enabled`.
  4313. *
  4314. * @param {Boolean} enabled
  4315. * @return {Suite|Boolean} self or enabled
  4316. * @api private
  4317. */
  4318. Suite.prototype.enableTimeouts = function(enabled){
  4319. if (arguments.length === 0) return this._enableTimeouts;
  4320. debug('enableTimeouts %s', enabled);
  4321. this._enableTimeouts = enabled;
  4322. return this;
  4323. };
  4324. /**
  4325. * Set slow `ms` or short-hand such as "2s".
  4326. *
  4327. * @param {Number|String} ms
  4328. * @return {Suite|Number} for chaining
  4329. * @api private
  4330. */
  4331. Suite.prototype.slow = function(ms){
  4332. if (0 === arguments.length) return this._slow;
  4333. if ('string' == typeof ms) ms = milliseconds(ms);
  4334. debug('slow %d', ms);
  4335. this._slow = ms;
  4336. return this;
  4337. };
  4338. /**
  4339. * Sets whether to bail after first error.
  4340. *
  4341. * @parma {Boolean} bail
  4342. * @return {Suite|Number} for chaining
  4343. * @api private
  4344. */
  4345. Suite.prototype.bail = function(bail){
  4346. if (0 == arguments.length) return this._bail;
  4347. debug('bail %s', bail);
  4348. this._bail = bail;
  4349. return this;
  4350. };
  4351. /**
  4352. * Run `fn(test[, done])` before running tests.
  4353. *
  4354. * @param {Function} fn
  4355. * @return {Suite} for chaining
  4356. * @api private
  4357. */
  4358. Suite.prototype.beforeAll = function(title, fn){
  4359. if (this.pending) return this;
  4360. if ('function' === typeof title) {
  4361. fn = title;
  4362. title = fn.name;
  4363. }
  4364. title = '"before all" hook' + (title ? ': ' + title : '');
  4365. var hook = new Hook(title, fn);
  4366. hook.parent = this;
  4367. hook.timeout(this.timeout());
  4368. hook.enableTimeouts(this.enableTimeouts());
  4369. hook.slow(this.slow());
  4370. hook.ctx = this.ctx;
  4371. this._beforeAll.push(hook);
  4372. this.emit('beforeAll', hook);
  4373. return this;
  4374. };
  4375. /**
  4376. * Run `fn(test[, done])` after running tests.
  4377. *
  4378. * @param {Function} fn
  4379. * @return {Suite} for chaining
  4380. * @api private
  4381. */
  4382. Suite.prototype.afterAll = function(title, fn){
  4383. if (this.pending) return this;
  4384. if ('function' === typeof title) {
  4385. fn = title;
  4386. title = fn.name;
  4387. }
  4388. title = '"after all" hook' + (title ? ': ' + title : '');
  4389. var hook = new Hook(title, fn);
  4390. hook.parent = this;
  4391. hook.timeout(this.timeout());
  4392. hook.enableTimeouts(this.enableTimeouts());
  4393. hook.slow(this.slow());
  4394. hook.ctx = this.ctx;
  4395. this._afterAll.push(hook);
  4396. this.emit('afterAll', hook);
  4397. return this;
  4398. };
  4399. /**
  4400. * Run `fn(test[, done])` before each test case.
  4401. *
  4402. * @param {Function} fn
  4403. * @return {Suite} for chaining
  4404. * @api private
  4405. */
  4406. Suite.prototype.beforeEach = function(title, fn){
  4407. if (this.pending) return this;
  4408. if ('function' === typeof title) {
  4409. fn = title;
  4410. title = fn.name;
  4411. }
  4412. title = '"before each" hook' + (title ? ': ' + title : '');
  4413. var hook = new Hook(title, fn);
  4414. hook.parent = this;
  4415. hook.timeout(this.timeout());
  4416. hook.enableTimeouts(this.enableTimeouts());
  4417. hook.slow(this.slow());
  4418. hook.ctx = this.ctx;
  4419. this._beforeEach.push(hook);
  4420. this.emit('beforeEach', hook);
  4421. return this;
  4422. };
  4423. /**
  4424. * Run `fn(test[, done])` after each test case.
  4425. *
  4426. * @param {Function} fn
  4427. * @return {Suite} for chaining
  4428. * @api private
  4429. */
  4430. Suite.prototype.afterEach = function(title, fn){
  4431. if (this.pending) return this;
  4432. if ('function' === typeof title) {
  4433. fn = title;
  4434. title = fn.name;
  4435. }
  4436. title = '"after each" hook' + (title ? ': ' + title : '');
  4437. var hook = new Hook(title, fn);
  4438. hook.parent = this;
  4439. hook.timeout(this.timeout());
  4440. hook.enableTimeouts(this.enableTimeouts());
  4441. hook.slow(this.slow());
  4442. hook.ctx = this.ctx;
  4443. this._afterEach.push(hook);
  4444. this.emit('afterEach', hook);
  4445. return this;
  4446. };
  4447. /**
  4448. * Add a test `suite`.
  4449. *
  4450. * @param {Suite} suite
  4451. * @return {Suite} for chaining
  4452. * @api private
  4453. */
  4454. Suite.prototype.addSuite = function(suite){
  4455. suite.parent = this;
  4456. suite.timeout(this.timeout());
  4457. suite.enableTimeouts(this.enableTimeouts());
  4458. suite.slow(this.slow());
  4459. suite.bail(this.bail());
  4460. this.suites.push(suite);
  4461. this.emit('suite', suite);
  4462. return this;
  4463. };
  4464. /**
  4465. * Add a `test` to this suite.
  4466. *
  4467. * @param {Test} test
  4468. * @return {Suite} for chaining
  4469. * @api private
  4470. */
  4471. Suite.prototype.addTest = function(test){
  4472. test.parent = this;
  4473. test.timeout(this.timeout());
  4474. test.enableTimeouts(this.enableTimeouts());
  4475. test.slow(this.slow());
  4476. test.ctx = this.ctx;
  4477. this.tests.push(test);
  4478. this.emit('test', test);
  4479. return this;
  4480. };
  4481. /**
  4482. * Return the full title generated by recursively
  4483. * concatenating the parent's full title.
  4484. *
  4485. * @return {String}
  4486. * @api public
  4487. */
  4488. Suite.prototype.fullTitle = function(){
  4489. if (this.parent) {
  4490. var full = this.parent.fullTitle();
  4491. if (full) return full + ' ' + this.title;
  4492. }
  4493. return this.title;
  4494. };
  4495. /**
  4496. * Return the total number of tests.
  4497. *
  4498. * @return {Number}
  4499. * @api public
  4500. */
  4501. Suite.prototype.total = function(){
  4502. return utils.reduce(this.suites, function(sum, suite){
  4503. return sum + suite.total();
  4504. }, 0) + this.tests.length;
  4505. };
  4506. /**
  4507. * Iterates through each suite recursively to find
  4508. * all tests. Applies a function in the format
  4509. * `fn(test)`.
  4510. *
  4511. * @param {Function} fn
  4512. * @return {Suite}
  4513. * @api private
  4514. */
  4515. Suite.prototype.eachTest = function(fn){
  4516. utils.forEach(this.tests, fn);
  4517. utils.forEach(this.suites, function(suite){
  4518. suite.eachTest(fn);
  4519. });
  4520. return this;
  4521. };
  4522. }); // module: suite.js
  4523. require.register("test.js", function(module, exports, require){
  4524. /**
  4525. * Module dependencies.
  4526. */
  4527. var Runnable = require('./runnable');
  4528. /**
  4529. * Expose `Test`.
  4530. */
  4531. module.exports = Test;
  4532. /**
  4533. * Initialize a new `Test` with the given `title` and callback `fn`.
  4534. *
  4535. * @param {String} title
  4536. * @param {Function} fn
  4537. * @api private
  4538. */
  4539. function Test(title, fn) {
  4540. Runnable.call(this, title, fn);
  4541. this.pending = !fn;
  4542. this.type = 'test';
  4543. }
  4544. /**
  4545. * Inherit from `Runnable.prototype`.
  4546. */
  4547. function F(){};
  4548. F.prototype = Runnable.prototype;
  4549. Test.prototype = new F;
  4550. Test.prototype.constructor = Test;
  4551. }); // module: test.js
  4552. require.register("utils.js", function(module, exports, require){
  4553. /**
  4554. * Module dependencies.
  4555. */
  4556. var fs = require('browser/fs')
  4557. , path = require('browser/path')
  4558. , basename = path.basename
  4559. , exists = fs.existsSync || path.existsSync
  4560. , glob = require('browser/glob')
  4561. , join = path.join
  4562. , debug = require('browser/debug')('mocha:watch');
  4563. /**
  4564. * Ignored directories.
  4565. */
  4566. var ignore = ['node_modules', '.git'];
  4567. /**
  4568. * Escape special characters in the given string of html.
  4569. *
  4570. * @param {String} html
  4571. * @return {String}
  4572. * @api private
  4573. */
  4574. exports.escape = function(html){
  4575. return String(html)
  4576. .replace(/&/g, '&amp;')
  4577. .replace(/"/g, '&quot;')
  4578. .replace(/</g, '&lt;')
  4579. .replace(/>/g, '&gt;');
  4580. };
  4581. /**
  4582. * Array#forEach (<=IE8)
  4583. *
  4584. * @param {Array} array
  4585. * @param {Function} fn
  4586. * @param {Object} scope
  4587. * @api private
  4588. */
  4589. exports.forEach = function(arr, fn, scope){
  4590. for (var i = 0, l = arr.length; i < l; i++)
  4591. fn.call(scope, arr[i], i);
  4592. };
  4593. /**
  4594. * Array#map (<=IE8)
  4595. *
  4596. * @param {Array} array
  4597. * @param {Function} fn
  4598. * @param {Object} scope
  4599. * @api private
  4600. */
  4601. exports.map = function(arr, fn, scope){
  4602. var result = [];
  4603. for (var i = 0, l = arr.length; i < l; i++)
  4604. result.push(fn.call(scope, arr[i], i));
  4605. return result;
  4606. };
  4607. /**
  4608. * Array#indexOf (<=IE8)
  4609. *
  4610. * @parma {Array} arr
  4611. * @param {Object} obj to find index of
  4612. * @param {Number} start
  4613. * @api private
  4614. */
  4615. exports.indexOf = function(arr, obj, start){
  4616. for (var i = start || 0, l = arr.length; i < l; i++) {
  4617. if (arr[i] === obj)
  4618. return i;
  4619. }
  4620. return -1;
  4621. };
  4622. /**
  4623. * Array#reduce (<=IE8)
  4624. *
  4625. * @param {Array} array
  4626. * @param {Function} fn
  4627. * @param {Object} initial value
  4628. * @api private
  4629. */
  4630. exports.reduce = function(arr, fn, val){
  4631. var rval = val;
  4632. for (var i = 0, l = arr.length; i < l; i++) {
  4633. rval = fn(rval, arr[i], i, arr);
  4634. }
  4635. return rval;
  4636. };
  4637. /**
  4638. * Array#filter (<=IE8)
  4639. *
  4640. * @param {Array} array
  4641. * @param {Function} fn
  4642. * @api private
  4643. */
  4644. exports.filter = function(arr, fn){
  4645. var ret = [];
  4646. for (var i = 0, l = arr.length; i < l; i++) {
  4647. var val = arr[i];
  4648. if (fn(val, i, arr)) ret.push(val);
  4649. }
  4650. return ret;
  4651. };
  4652. /**
  4653. * Object.keys (<=IE8)
  4654. *
  4655. * @param {Object} obj
  4656. * @return {Array} keys
  4657. * @api private
  4658. */
  4659. exports.keys = Object.keys || function(obj) {
  4660. var keys = []
  4661. , has = Object.prototype.hasOwnProperty // for `window` on <=IE8
  4662. for (var key in obj) {
  4663. if (has.call(obj, key)) {
  4664. keys.push(key);
  4665. }
  4666. }
  4667. return keys;
  4668. };
  4669. /**
  4670. * Watch the given `files` for changes
  4671. * and invoke `fn(file)` on modification.
  4672. *
  4673. * @param {Array} files
  4674. * @param {Function} fn
  4675. * @api private
  4676. */
  4677. exports.watch = function(files, fn){
  4678. var options = { interval: 100 };
  4679. files.forEach(function(file){
  4680. debug('file %s', file);
  4681. fs.watchFile(file, options, function(curr, prev){
  4682. if (prev.mtime < curr.mtime) fn(file);
  4683. });
  4684. });
  4685. };
  4686. /**
  4687. * Ignored files.
  4688. */
  4689. function ignored(path){
  4690. return !~ignore.indexOf(path);
  4691. }
  4692. /**
  4693. * Lookup files in the given `dir`.
  4694. *
  4695. * @return {Array}
  4696. * @api private
  4697. */
  4698. exports.files = function(dir, ext, ret){
  4699. ret = ret || [];
  4700. ext = ext || ['js'];
  4701. var re = new RegExp('\\.(' + ext.join('|') + ')$');
  4702. fs.readdirSync(dir)
  4703. .filter(ignored)
  4704. .forEach(function(path){
  4705. path = join(dir, path);
  4706. if (fs.statSync(path).isDirectory()) {
  4707. exports.files(path, ext, ret);
  4708. } else if (path.match(re)) {
  4709. ret.push(path);
  4710. }
  4711. });
  4712. return ret;
  4713. };
  4714. /**
  4715. * Compute a slug from the given `str`.
  4716. *
  4717. * @param {String} str
  4718. * @return {String}
  4719. * @api private
  4720. */
  4721. exports.slug = function(str){
  4722. return str
  4723. .toLowerCase()
  4724. .replace(/ +/g, '-')
  4725. .replace(/[^-\w]/g, '');
  4726. };
  4727. /**
  4728. * Strip the function definition from `str`,
  4729. * and re-indent for pre whitespace.
  4730. */
  4731. exports.clean = function(str) {
  4732. str = str
  4733. .replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
  4734. .replace(/^function *\(.*\) *{|\(.*\) *=> *{?/, '')
  4735. .replace(/\s+\}$/, '');
  4736. var spaces = str.match(/^\n?( *)/)[1].length
  4737. , tabs = str.match(/^\n?(\t*)/)[1].length
  4738. , re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs ? tabs : spaces) + '}', 'gm');
  4739. str = str.replace(re, '');
  4740. return exports.trim(str);
  4741. };
  4742. /**
  4743. * Trim the given `str`.
  4744. *
  4745. * @param {String} str
  4746. * @return {String}
  4747. * @api private
  4748. */
  4749. exports.trim = function(str){
  4750. return str.replace(/^\s+|\s+$/g, '');
  4751. };
  4752. /**
  4753. * Parse the given `qs`.
  4754. *
  4755. * @param {String} qs
  4756. * @return {Object}
  4757. * @api private
  4758. */
  4759. exports.parseQuery = function(qs){
  4760. return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair){
  4761. var i = pair.indexOf('=')
  4762. , key = pair.slice(0, i)
  4763. , val = pair.slice(++i);
  4764. obj[key] = decodeURIComponent(val);
  4765. return obj;
  4766. }, {});
  4767. };
  4768. /**
  4769. * Highlight the given string of `js`.
  4770. *
  4771. * @param {String} js
  4772. * @return {String}
  4773. * @api private
  4774. */
  4775. function highlight(js) {
  4776. return js
  4777. .replace(/</g, '&lt;')
  4778. .replace(/>/g, '&gt;')
  4779. .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
  4780. .replace(/('.*?')/gm, '<span class="string">$1</span>')
  4781. .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
  4782. .replace(/(\d+)/gm, '<span class="number">$1</span>')
  4783. .replace(/\bnew[ \t]+(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
  4784. .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')
  4785. }
  4786. /**
  4787. * Highlight the contents of tag `name`.
  4788. *
  4789. * @param {String} name
  4790. * @api private
  4791. */
  4792. exports.highlightTags = function(name) {
  4793. var code = document.getElementById('mocha').getElementsByTagName(name);
  4794. for (var i = 0, len = code.length; i < len; ++i) {
  4795. code[i].innerHTML = highlight(code[i].innerHTML);
  4796. }
  4797. };
  4798. /**
  4799. * Stringify `obj`.
  4800. *
  4801. * @param {Object} obj
  4802. * @return {String}
  4803. * @api private
  4804. */
  4805. exports.stringify = function(obj) {
  4806. if (obj instanceof RegExp) return obj.toString();
  4807. return JSON.stringify(exports.canonicalize(obj), null, 2).replace(/,(\n|$)/g, '$1');
  4808. };
  4809. /**
  4810. * Return a new object that has the keys in sorted order.
  4811. * @param {Object} obj
  4812. * @param {Array} [stack]
  4813. * @return {Object}
  4814. * @api private
  4815. */
  4816. exports.canonicalize = function(obj, stack) {
  4817. stack = stack || [];
  4818. if (exports.indexOf(stack, obj) !== -1) return '[Circular]';
  4819. var canonicalizedObj;
  4820. if ({}.toString.call(obj) === '[object Array]') {
  4821. stack.push(obj);
  4822. canonicalizedObj = exports.map(obj, function (item) {
  4823. return exports.canonicalize(item, stack);
  4824. });
  4825. stack.pop();
  4826. } else if (typeof obj === 'object' && obj !== null) {
  4827. stack.push(obj);
  4828. canonicalizedObj = {};
  4829. exports.forEach(exports.keys(obj).sort(), function (key) {
  4830. canonicalizedObj[key] = exports.canonicalize(obj[key], stack);
  4831. });
  4832. stack.pop();
  4833. } else {
  4834. canonicalizedObj = obj;
  4835. }
  4836. return canonicalizedObj;
  4837. };
  4838. /**
  4839. * Lookup file names at the given `path`.
  4840. */
  4841. exports.lookupFiles = function lookupFiles(path, extensions, recursive) {
  4842. var files = [];
  4843. var re = new RegExp('\\.(' + extensions.join('|') + ')$');
  4844. if (!exists(path)) {
  4845. if (exists(path + '.js')) {
  4846. path += '.js';
  4847. } else {
  4848. files = glob.sync(path);
  4849. if (!files.length) throw new Error("cannot resolve path (or pattern) '" + path + "'");
  4850. return files;
  4851. }
  4852. }
  4853. try {
  4854. var stat = fs.statSync(path);
  4855. if (stat.isFile()) return path;
  4856. }
  4857. catch (ignored) {
  4858. return;
  4859. }
  4860. fs.readdirSync(path).forEach(function(file){
  4861. file = join(path, file);
  4862. try {
  4863. var stat = fs.statSync(file);
  4864. if (stat.isDirectory()) {
  4865. if (recursive) {
  4866. files = files.concat(lookupFiles(file, extensions, recursive));
  4867. }
  4868. return;
  4869. }
  4870. }
  4871. catch (ignored) {
  4872. return;
  4873. }
  4874. if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') return;
  4875. files.push(file);
  4876. });
  4877. return files;
  4878. };
  4879. }); // module: utils.js
  4880. // The global object is "self" in Web Workers.
  4881. var global = (function() { return this; })();
  4882. /**
  4883. * Save timer references to avoid Sinon interfering (see GH-237).
  4884. */
  4885. var Date = global.Date;
  4886. var setTimeout = global.setTimeout;
  4887. var setInterval = global.setInterval;
  4888. var clearTimeout = global.clearTimeout;
  4889. var clearInterval = global.clearInterval;
  4890. /**
  4891. * Node shims.
  4892. *
  4893. * These are meant only to allow
  4894. * mocha.js to run untouched, not
  4895. * to allow running node code in
  4896. * the browser.
  4897. */
  4898. var process = {};
  4899. process.exit = function(status){};
  4900. process.stdout = {};
  4901. var uncaughtExceptionHandlers = [];
  4902. var originalOnerrorHandler = global.onerror;
  4903. /**
  4904. * Remove uncaughtException listener.
  4905. * Revert to original onerror handler if previously defined.
  4906. */
  4907. process.removeListener = function(e, fn){
  4908. if ('uncaughtException' == e) {
  4909. if (originalOnerrorHandler) {
  4910. global.onerror = originalOnerrorHandler;
  4911. } else {
  4912. global.onerror = function() {};
  4913. }
  4914. var i = Mocha.utils.indexOf(uncaughtExceptionHandlers, fn);
  4915. if (i != -1) { uncaughtExceptionHandlers.splice(i, 1); }
  4916. }
  4917. };
  4918. /**
  4919. * Implements uncaughtException listener.
  4920. */
  4921. process.on = function(e, fn){
  4922. if ('uncaughtException' == e) {
  4923. global.onerror = function(err, url, line){
  4924. fn(new Error(err + ' (' + url + ':' + line + ')'));
  4925. return true;
  4926. };
  4927. uncaughtExceptionHandlers.push(fn);
  4928. }
  4929. };
  4930. /**
  4931. * Expose mocha.
  4932. */
  4933. var Mocha = global.Mocha = require('mocha'),
  4934. mocha = global.mocha = new Mocha({ reporter: 'html' });
  4935. // The BDD UI is registered by default, but no UI will be functional in the
  4936. // browser without an explicit call to the overridden `mocha.ui` (see below).
  4937. // Ensure that this default UI does not expose its methods to the global scope.
  4938. mocha.suite.removeAllListeners('pre-require');
  4939. var immediateQueue = []
  4940. , immediateTimeout;
  4941. function timeslice() {
  4942. var immediateStart = new Date().getTime();
  4943. while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
  4944. immediateQueue.shift()();
  4945. }
  4946. if (immediateQueue.length) {
  4947. immediateTimeout = setTimeout(timeslice, 0);
  4948. } else {
  4949. immediateTimeout = null;
  4950. }
  4951. }
  4952. /**
  4953. * High-performance override of Runner.immediately.
  4954. */
  4955. Mocha.Runner.immediately = function(callback) {
  4956. immediateQueue.push(callback);
  4957. if (!immediateTimeout) {
  4958. immediateTimeout = setTimeout(timeslice, 0);
  4959. }
  4960. };
  4961. /**
  4962. * Function to allow assertion libraries to throw errors directly into mocha.
  4963. * This is useful when running tests in a browser because window.onerror will
  4964. * only receive the 'message' attribute of the Error.
  4965. */
  4966. mocha.throwError = function(err) {
  4967. Mocha.utils.forEach(uncaughtExceptionHandlers, function (fn) {
  4968. fn(err);
  4969. });
  4970. throw err;
  4971. };
  4972. /**
  4973. * Override ui to ensure that the ui functions are initialized.
  4974. * Normally this would happen in Mocha.prototype.loadFiles.
  4975. */
  4976. mocha.ui = function(ui){
  4977. Mocha.prototype.ui.call(this, ui);
  4978. this.suite.emit('pre-require', global, null, this);
  4979. return this;
  4980. };
  4981. /**
  4982. * Setup mocha with the given setting options.
  4983. */
  4984. mocha.setup = function(opts){
  4985. if ('string' == typeof opts) opts = { ui: opts };
  4986. for (var opt in opts) this[opt](opts[opt]);
  4987. return this;
  4988. };
  4989. /**
  4990. * Run mocha, returning the Runner.
  4991. */
  4992. mocha.run = function(fn){
  4993. var options = mocha.options;
  4994. mocha.globals('location');
  4995. var query = Mocha.utils.parseQuery(global.location.search || '');
  4996. if (query.grep) mocha.grep(query.grep);
  4997. if (query.invert) mocha.invert();
  4998. return Mocha.prototype.run.call(mocha, function(err){
  4999. // The DOM Document is not available in Web Workers.
  5000. var document = global.document;
  5001. if (document && document.getElementById('mocha') && options.noHighlighting !== true) {
  5002. Mocha.utils.highlightTags('code');
  5003. }
  5004. if (fn) fn(err);
  5005. });
  5006. };
  5007. /**
  5008. * Expose the process shim.
  5009. */
  5010. Mocha.process = process;
  5011. })();
  5012. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.chai = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  5013. module.exports = require('./lib/chai');
  5014. },{"./lib/chai":2}],2:[function(require,module,exports){
  5015. /*!
  5016. * chai
  5017. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  5018. * MIT Licensed
  5019. */
  5020. var used = []
  5021. , exports = module.exports = {};
  5022. /*!
  5023. * Chai version
  5024. */
  5025. exports.version = '3.5.0';
  5026. /*!
  5027. * Assertion Error
  5028. */
  5029. exports.AssertionError = require('assertion-error');
  5030. /*!
  5031. * Utils for plugins (not exported)
  5032. */
  5033. var util = require('./chai/utils');
  5034. /**
  5035. * # .use(function)
  5036. *
  5037. * Provides a way to extend the internals of Chai
  5038. *
  5039. * @param {Function}
  5040. * @returns {this} for chaining
  5041. * @api public
  5042. */
  5043. exports.use = function (fn) {
  5044. if (!~used.indexOf(fn)) {
  5045. fn(this, util);
  5046. used.push(fn);
  5047. }
  5048. return this;
  5049. };
  5050. /*!
  5051. * Utility Functions
  5052. */
  5053. exports.util = util;
  5054. /*!
  5055. * Configuration
  5056. */
  5057. var config = require('./chai/config');
  5058. exports.config = config;
  5059. /*!
  5060. * Primary `Assertion` prototype
  5061. */
  5062. var assertion = require('./chai/assertion');
  5063. exports.use(assertion);
  5064. /*!
  5065. * Core Assertions
  5066. */
  5067. var core = require('./chai/core/assertions');
  5068. exports.use(core);
  5069. /*!
  5070. * Expect interface
  5071. */
  5072. var expect = require('./chai/interface/expect');
  5073. exports.use(expect);
  5074. /*!
  5075. * Should interface
  5076. */
  5077. var should = require('./chai/interface/should');
  5078. exports.use(should);
  5079. /*!
  5080. * Assert interface
  5081. */
  5082. var assert = require('./chai/interface/assert');
  5083. exports.use(assert);
  5084. },{"./chai/assertion":3,"./chai/config":4,"./chai/core/assertions":5,"./chai/interface/assert":6,"./chai/interface/expect":7,"./chai/interface/should":8,"./chai/utils":22,"assertion-error":30}],3:[function(require,module,exports){
  5085. /*!
  5086. * chai
  5087. * http://chaijs.com
  5088. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  5089. * MIT Licensed
  5090. */
  5091. var config = require('./config');
  5092. module.exports = function (_chai, util) {
  5093. /*!
  5094. * Module dependencies.
  5095. */
  5096. var AssertionError = _chai.AssertionError
  5097. , flag = util.flag;
  5098. /*!
  5099. * Module export.
  5100. */
  5101. _chai.Assertion = Assertion;
  5102. /*!
  5103. * Assertion Constructor
  5104. *
  5105. * Creates object for chaining.
  5106. *
  5107. * @api private
  5108. */
  5109. function Assertion (obj, msg, stack) {
  5110. flag(this, 'ssfi', stack || arguments.callee);
  5111. flag(this, 'object', obj);
  5112. flag(this, 'message', msg);
  5113. }
  5114. Object.defineProperty(Assertion, 'includeStack', {
  5115. get: function() {
  5116. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  5117. return config.includeStack;
  5118. },
  5119. set: function(value) {
  5120. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  5121. config.includeStack = value;
  5122. }
  5123. });
  5124. Object.defineProperty(Assertion, 'showDiff', {
  5125. get: function() {
  5126. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  5127. return config.showDiff;
  5128. },
  5129. set: function(value) {
  5130. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  5131. config.showDiff = value;
  5132. }
  5133. });
  5134. Assertion.addProperty = function (name, fn) {
  5135. util.addProperty(this.prototype, name, fn);
  5136. };
  5137. Assertion.addMethod = function (name, fn) {
  5138. util.addMethod(this.prototype, name, fn);
  5139. };
  5140. Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
  5141. util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
  5142. };
  5143. Assertion.overwriteProperty = function (name, fn) {
  5144. util.overwriteProperty(this.prototype, name, fn);
  5145. };
  5146. Assertion.overwriteMethod = function (name, fn) {
  5147. util.overwriteMethod(this.prototype, name, fn);
  5148. };
  5149. Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
  5150. util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
  5151. };
  5152. /**
  5153. * ### .assert(expression, message, negateMessage, expected, actual, showDiff)
  5154. *
  5155. * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
  5156. *
  5157. * @name assert
  5158. * @param {Philosophical} expression to be tested
  5159. * @param {String|Function} message or function that returns message to display if expression fails
  5160. * @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
  5161. * @param {Mixed} expected value (remember to check for negation)
  5162. * @param {Mixed} actual (optional) will default to `this.obj`
  5163. * @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
  5164. * @api private
  5165. */
  5166. Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
  5167. var ok = util.test(this, arguments);
  5168. if (true !== showDiff) showDiff = false;
  5169. if (true !== config.showDiff) showDiff = false;
  5170. if (!ok) {
  5171. var msg = util.getMessage(this, arguments)
  5172. , actual = util.getActual(this, arguments);
  5173. throw new AssertionError(msg, {
  5174. actual: actual
  5175. , expected: expected
  5176. , showDiff: showDiff
  5177. }, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
  5178. }
  5179. };
  5180. /*!
  5181. * ### ._obj
  5182. *
  5183. * Quick reference to stored `actual` value for plugin developers.
  5184. *
  5185. * @api private
  5186. */
  5187. Object.defineProperty(Assertion.prototype, '_obj',
  5188. { get: function () {
  5189. return flag(this, 'object');
  5190. }
  5191. , set: function (val) {
  5192. flag(this, 'object', val);
  5193. }
  5194. });
  5195. };
  5196. },{"./config":4}],4:[function(require,module,exports){
  5197. module.exports = {
  5198. /**
  5199. * ### config.includeStack
  5200. *
  5201. * User configurable property, influences whether stack trace
  5202. * is included in Assertion error message. Default of false
  5203. * suppresses stack trace in the error message.
  5204. *
  5205. * chai.config.includeStack = true; // enable stack on error
  5206. *
  5207. * @param {Boolean}
  5208. * @api public
  5209. */
  5210. includeStack: false,
  5211. /**
  5212. * ### config.showDiff
  5213. *
  5214. * User configurable property, influences whether or not
  5215. * the `showDiff` flag should be included in the thrown
  5216. * AssertionErrors. `false` will always be `false`; `true`
  5217. * will be true when the assertion has requested a diff
  5218. * be shown.
  5219. *
  5220. * @param {Boolean}
  5221. * @api public
  5222. */
  5223. showDiff: true,
  5224. /**
  5225. * ### config.truncateThreshold
  5226. *
  5227. * User configurable property, sets length threshold for actual and
  5228. * expected values in assertion errors. If this threshold is exceeded, for
  5229. * example for large data structures, the value is replaced with something
  5230. * like `[ Array(3) ]` or `{ Object (prop1, prop2) }`.
  5231. *
  5232. * Set it to zero if you want to disable truncating altogether.
  5233. *
  5234. * This is especially userful when doing assertions on arrays: having this
  5235. * set to a reasonable large value makes the failure messages readily
  5236. * inspectable.
  5237. *
  5238. * chai.config.truncateThreshold = 0; // disable truncating
  5239. *
  5240. * @param {Number}
  5241. * @api public
  5242. */
  5243. truncateThreshold: 40
  5244. };
  5245. },{}],5:[function(require,module,exports){
  5246. /*!
  5247. * chai
  5248. * http://chaijs.com
  5249. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  5250. * MIT Licensed
  5251. */
  5252. module.exports = function (chai, _) {
  5253. var Assertion = chai.Assertion
  5254. , toString = Object.prototype.toString
  5255. , flag = _.flag;
  5256. /**
  5257. * ### Language Chains
  5258. *
  5259. * The following are provided as chainable getters to
  5260. * improve the readability of your assertions. They
  5261. * do not provide testing capabilities unless they
  5262. * have been overwritten by a plugin.
  5263. *
  5264. * **Chains**
  5265. *
  5266. * - to
  5267. * - be
  5268. * - been
  5269. * - is
  5270. * - that
  5271. * - which
  5272. * - and
  5273. * - has
  5274. * - have
  5275. * - with
  5276. * - at
  5277. * - of
  5278. * - same
  5279. *
  5280. * @name language chains
  5281. * @namespace BDD
  5282. * @api public
  5283. */
  5284. [ 'to', 'be', 'been'
  5285. , 'is', 'and', 'has', 'have'
  5286. , 'with', 'that', 'which', 'at'
  5287. , 'of', 'same' ].forEach(function (chain) {
  5288. Assertion.addProperty(chain, function () {
  5289. return this;
  5290. });
  5291. });
  5292. /**
  5293. * ### .not
  5294. *
  5295. * Negates any of assertions following in the chain.
  5296. *
  5297. * expect(foo).to.not.equal('bar');
  5298. * expect(goodFn).to.not.throw(Error);
  5299. * expect({ foo: 'baz' }).to.have.property('foo')
  5300. * .and.not.equal('bar');
  5301. *
  5302. * @name not
  5303. * @namespace BDD
  5304. * @api public
  5305. */
  5306. Assertion.addProperty('not', function () {
  5307. flag(this, 'negate', true);
  5308. });
  5309. /**
  5310. * ### .deep
  5311. *
  5312. * Sets the `deep` flag, later used by the `equal` and
  5313. * `property` assertions.
  5314. *
  5315. * expect(foo).to.deep.equal({ bar: 'baz' });
  5316. * expect({ foo: { bar: { baz: 'quux' } } })
  5317. * .to.have.deep.property('foo.bar.baz', 'quux');
  5318. *
  5319. * `.deep.property` special characters can be escaped
  5320. * by adding two slashes before the `.` or `[]`.
  5321. *
  5322. * var deepCss = { '.link': { '[target]': 42 }};
  5323. * expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);
  5324. *
  5325. * @name deep
  5326. * @namespace BDD
  5327. * @api public
  5328. */
  5329. Assertion.addProperty('deep', function () {
  5330. flag(this, 'deep', true);
  5331. });
  5332. /**
  5333. * ### .any
  5334. *
  5335. * Sets the `any` flag, (opposite of the `all` flag)
  5336. * later used in the `keys` assertion.
  5337. *
  5338. * expect(foo).to.have.any.keys('bar', 'baz');
  5339. *
  5340. * @name any
  5341. * @namespace BDD
  5342. * @api public
  5343. */
  5344. Assertion.addProperty('any', function () {
  5345. flag(this, 'any', true);
  5346. flag(this, 'all', false)
  5347. });
  5348. /**
  5349. * ### .all
  5350. *
  5351. * Sets the `all` flag (opposite of the `any` flag)
  5352. * later used by the `keys` assertion.
  5353. *
  5354. * expect(foo).to.have.all.keys('bar', 'baz');
  5355. *
  5356. * @name all
  5357. * @namespace BDD
  5358. * @api public
  5359. */
  5360. Assertion.addProperty('all', function () {
  5361. flag(this, 'all', true);
  5362. flag(this, 'any', false);
  5363. });
  5364. /**
  5365. * ### .a(type)
  5366. *
  5367. * The `a` and `an` assertions are aliases that can be
  5368. * used either as language chains or to assert a value's
  5369. * type.
  5370. *
  5371. * // typeof
  5372. * expect('test').to.be.a('string');
  5373. * expect({ foo: 'bar' }).to.be.an('object');
  5374. * expect(null).to.be.a('null');
  5375. * expect(undefined).to.be.an('undefined');
  5376. * expect(new Error).to.be.an('error');
  5377. * expect(new Promise).to.be.a('promise');
  5378. * expect(new Float32Array()).to.be.a('float32array');
  5379. * expect(Symbol()).to.be.a('symbol');
  5380. *
  5381. * // es6 overrides
  5382. * expect({[Symbol.toStringTag]:()=>'foo'}).to.be.a('foo');
  5383. *
  5384. * // language chain
  5385. * expect(foo).to.be.an.instanceof(Foo);
  5386. *
  5387. * @name a
  5388. * @alias an
  5389. * @param {String} type
  5390. * @param {String} message _optional_
  5391. * @namespace BDD
  5392. * @api public
  5393. */
  5394. function an (type, msg) {
  5395. if (msg) flag(this, 'message', msg);
  5396. type = type.toLowerCase();
  5397. var obj = flag(this, 'object')
  5398. , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
  5399. this.assert(
  5400. type === _.type(obj)
  5401. , 'expected #{this} to be ' + article + type
  5402. , 'expected #{this} not to be ' + article + type
  5403. );
  5404. }
  5405. Assertion.addChainableMethod('an', an);
  5406. Assertion.addChainableMethod('a', an);
  5407. /**
  5408. * ### .include(value)
  5409. *
  5410. * The `include` and `contain` assertions can be used as either property
  5411. * based language chains or as methods to assert the inclusion of an object
  5412. * in an array or a substring in a string. When used as language chains,
  5413. * they toggle the `contains` flag for the `keys` assertion.
  5414. *
  5415. * expect([1,2,3]).to.include(2);
  5416. * expect('foobar').to.contain('foo');
  5417. * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
  5418. *
  5419. * @name include
  5420. * @alias contain
  5421. * @alias includes
  5422. * @alias contains
  5423. * @param {Object|String|Number} obj
  5424. * @param {String} message _optional_
  5425. * @namespace BDD
  5426. * @api public
  5427. */
  5428. function includeChainingBehavior () {
  5429. flag(this, 'contains', true);
  5430. }
  5431. function include (val, msg) {
  5432. _.expectTypes(this, ['array', 'object', 'string']);
  5433. if (msg) flag(this, 'message', msg);
  5434. var obj = flag(this, 'object');
  5435. var expected = false;
  5436. if (_.type(obj) === 'array' && _.type(val) === 'object') {
  5437. for (var i in obj) {
  5438. if (_.eql(obj[i], val)) {
  5439. expected = true;
  5440. break;
  5441. }
  5442. }
  5443. } else if (_.type(val) === 'object') {
  5444. if (!flag(this, 'negate')) {
  5445. for (var k in val) new Assertion(obj).property(k, val[k]);
  5446. return;
  5447. }
  5448. var subset = {};
  5449. for (var k in val) subset[k] = obj[k];
  5450. expected = _.eql(subset, val);
  5451. } else {
  5452. expected = (obj != undefined) && ~obj.indexOf(val);
  5453. }
  5454. this.assert(
  5455. expected
  5456. , 'expected #{this} to include ' + _.inspect(val)
  5457. , 'expected #{this} to not include ' + _.inspect(val));
  5458. }
  5459. Assertion.addChainableMethod('include', include, includeChainingBehavior);
  5460. Assertion.addChainableMethod('contain', include, includeChainingBehavior);
  5461. Assertion.addChainableMethod('contains', include, includeChainingBehavior);
  5462. Assertion.addChainableMethod('includes', include, includeChainingBehavior);
  5463. /**
  5464. * ### .ok
  5465. *
  5466. * Asserts that the target is truthy.
  5467. *
  5468. * expect('everything').to.be.ok;
  5469. * expect(1).to.be.ok;
  5470. * expect(false).to.not.be.ok;
  5471. * expect(undefined).to.not.be.ok;
  5472. * expect(null).to.not.be.ok;
  5473. *
  5474. * @name ok
  5475. * @namespace BDD
  5476. * @api public
  5477. */
  5478. Assertion.addProperty('ok', function () {
  5479. this.assert(
  5480. flag(this, 'object')
  5481. , 'expected #{this} to be truthy'
  5482. , 'expected #{this} to be falsy');
  5483. });
  5484. /**
  5485. * ### .true
  5486. *
  5487. * Asserts that the target is `true`.
  5488. *
  5489. * expect(true).to.be.true;
  5490. * expect(1).to.not.be.true;
  5491. *
  5492. * @name true
  5493. * @namespace BDD
  5494. * @api public
  5495. */
  5496. Assertion.addProperty('true', function () {
  5497. this.assert(
  5498. true === flag(this, 'object')
  5499. , 'expected #{this} to be true'
  5500. , 'expected #{this} to be false'
  5501. , this.negate ? false : true
  5502. );
  5503. });
  5504. /**
  5505. * ### .false
  5506. *
  5507. * Asserts that the target is `false`.
  5508. *
  5509. * expect(false).to.be.false;
  5510. * expect(0).to.not.be.false;
  5511. *
  5512. * @name false
  5513. * @namespace BDD
  5514. * @api public
  5515. */
  5516. Assertion.addProperty('false', function () {
  5517. this.assert(
  5518. false === flag(this, 'object')
  5519. , 'expected #{this} to be false'
  5520. , 'expected #{this} to be true'
  5521. , this.negate ? true : false
  5522. );
  5523. });
  5524. /**
  5525. * ### .null
  5526. *
  5527. * Asserts that the target is `null`.
  5528. *
  5529. * expect(null).to.be.null;
  5530. * expect(undefined).to.not.be.null;
  5531. *
  5532. * @name null
  5533. * @namespace BDD
  5534. * @api public
  5535. */
  5536. Assertion.addProperty('null', function () {
  5537. this.assert(
  5538. null === flag(this, 'object')
  5539. , 'expected #{this} to be null'
  5540. , 'expected #{this} not to be null'
  5541. );
  5542. });
  5543. /**
  5544. * ### .undefined
  5545. *
  5546. * Asserts that the target is `undefined`.
  5547. *
  5548. * expect(undefined).to.be.undefined;
  5549. * expect(null).to.not.be.undefined;
  5550. *
  5551. * @name undefined
  5552. * @namespace BDD
  5553. * @api public
  5554. */
  5555. Assertion.addProperty('undefined', function () {
  5556. this.assert(
  5557. undefined === flag(this, 'object')
  5558. , 'expected #{this} to be undefined'
  5559. , 'expected #{this} not to be undefined'
  5560. );
  5561. });
  5562. /**
  5563. * ### .NaN
  5564. * Asserts that the target is `NaN`.
  5565. *
  5566. * expect('foo').to.be.NaN;
  5567. * expect(4).not.to.be.NaN;
  5568. *
  5569. * @name NaN
  5570. * @namespace BDD
  5571. * @api public
  5572. */
  5573. Assertion.addProperty('NaN', function () {
  5574. this.assert(
  5575. isNaN(flag(this, 'object'))
  5576. , 'expected #{this} to be NaN'
  5577. , 'expected #{this} not to be NaN'
  5578. );
  5579. });
  5580. /**
  5581. * ### .exist
  5582. *
  5583. * Asserts that the target is neither `null` nor `undefined`.
  5584. *
  5585. * var foo = 'hi'
  5586. * , bar = null
  5587. * , baz;
  5588. *
  5589. * expect(foo).to.exist;
  5590. * expect(bar).to.not.exist;
  5591. * expect(baz).to.not.exist;
  5592. *
  5593. * @name exist
  5594. * @namespace BDD
  5595. * @api public
  5596. */
  5597. Assertion.addProperty('exist', function () {
  5598. this.assert(
  5599. null != flag(this, 'object')
  5600. , 'expected #{this} to exist'
  5601. , 'expected #{this} to not exist'
  5602. );
  5603. });
  5604. /**
  5605. * ### .empty
  5606. *
  5607. * Asserts that the target's length is `0`. For arrays and strings, it checks
  5608. * the `length` property. For objects, it gets the count of
  5609. * enumerable keys.
  5610. *
  5611. * expect([]).to.be.empty;
  5612. * expect('').to.be.empty;
  5613. * expect({}).to.be.empty;
  5614. *
  5615. * @name empty
  5616. * @namespace BDD
  5617. * @api public
  5618. */
  5619. Assertion.addProperty('empty', function () {
  5620. var obj = flag(this, 'object')
  5621. , expected = obj;
  5622. if (Array.isArray(obj) || 'string' === typeof object) {
  5623. expected = obj.length;
  5624. } else if (typeof obj === 'object') {
  5625. expected = Object.keys(obj).length;
  5626. }
  5627. this.assert(
  5628. !expected
  5629. , 'expected #{this} to be empty'
  5630. , 'expected #{this} not to be empty'
  5631. );
  5632. });
  5633. /**
  5634. * ### .arguments
  5635. *
  5636. * Asserts that the target is an arguments object.
  5637. *
  5638. * function test () {
  5639. * expect(arguments).to.be.arguments;
  5640. * }
  5641. *
  5642. * @name arguments
  5643. * @alias Arguments
  5644. * @namespace BDD
  5645. * @api public
  5646. */
  5647. function checkArguments () {
  5648. var obj = flag(this, 'object')
  5649. , type = Object.prototype.toString.call(obj);
  5650. this.assert(
  5651. '[object Arguments]' === type
  5652. , 'expected #{this} to be arguments but got ' + type
  5653. , 'expected #{this} to not be arguments'
  5654. );
  5655. }
  5656. Assertion.addProperty('arguments', checkArguments);
  5657. Assertion.addProperty('Arguments', checkArguments);
  5658. /**
  5659. * ### .equal(value)
  5660. *
  5661. * Asserts that the target is strictly equal (`===`) to `value`.
  5662. * Alternately, if the `deep` flag is set, asserts that
  5663. * the target is deeply equal to `value`.
  5664. *
  5665. * expect('hello').to.equal('hello');
  5666. * expect(42).to.equal(42);
  5667. * expect(1).to.not.equal(true);
  5668. * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
  5669. * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
  5670. *
  5671. * @name equal
  5672. * @alias equals
  5673. * @alias eq
  5674. * @alias deep.equal
  5675. * @param {Mixed} value
  5676. * @param {String} message _optional_
  5677. * @namespace BDD
  5678. * @api public
  5679. */
  5680. function assertEqual (val, msg) {
  5681. if (msg) flag(this, 'message', msg);
  5682. var obj = flag(this, 'object');
  5683. if (flag(this, 'deep')) {
  5684. return this.eql(val);
  5685. } else {
  5686. this.assert(
  5687. val === obj
  5688. , 'expected #{this} to equal #{exp}'
  5689. , 'expected #{this} to not equal #{exp}'
  5690. , val
  5691. , this._obj
  5692. , true
  5693. );
  5694. }
  5695. }
  5696. Assertion.addMethod('equal', assertEqual);
  5697. Assertion.addMethod('equals', assertEqual);
  5698. Assertion.addMethod('eq', assertEqual);
  5699. /**
  5700. * ### .eql(value)
  5701. *
  5702. * Asserts that the target is deeply equal to `value`.
  5703. *
  5704. * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
  5705. * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
  5706. *
  5707. * @name eql
  5708. * @alias eqls
  5709. * @param {Mixed} value
  5710. * @param {String} message _optional_
  5711. * @namespace BDD
  5712. * @api public
  5713. */
  5714. function assertEql(obj, msg) {
  5715. if (msg) flag(this, 'message', msg);
  5716. this.assert(
  5717. _.eql(obj, flag(this, 'object'))
  5718. , 'expected #{this} to deeply equal #{exp}'
  5719. , 'expected #{this} to not deeply equal #{exp}'
  5720. , obj
  5721. , this._obj
  5722. , true
  5723. );
  5724. }
  5725. Assertion.addMethod('eql', assertEql);
  5726. Assertion.addMethod('eqls', assertEql);
  5727. /**
  5728. * ### .above(value)
  5729. *
  5730. * Asserts that the target is greater than `value`.
  5731. *
  5732. * expect(10).to.be.above(5);
  5733. *
  5734. * Can also be used in conjunction with `length` to
  5735. * assert a minimum length. The benefit being a
  5736. * more informative error message than if the length
  5737. * was supplied directly.
  5738. *
  5739. * expect('foo').to.have.length.above(2);
  5740. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  5741. *
  5742. * @name above
  5743. * @alias gt
  5744. * @alias greaterThan
  5745. * @param {Number} value
  5746. * @param {String} message _optional_
  5747. * @namespace BDD
  5748. * @api public
  5749. */
  5750. function assertAbove (n, msg) {
  5751. if (msg) flag(this, 'message', msg);
  5752. var obj = flag(this, 'object');
  5753. if (flag(this, 'doLength')) {
  5754. new Assertion(obj, msg).to.have.property('length');
  5755. var len = obj.length;
  5756. this.assert(
  5757. len > n
  5758. , 'expected #{this} to have a length above #{exp} but got #{act}'
  5759. , 'expected #{this} to not have a length above #{exp}'
  5760. , n
  5761. , len
  5762. );
  5763. } else {
  5764. this.assert(
  5765. obj > n
  5766. , 'expected #{this} to be above ' + n
  5767. , 'expected #{this} to be at most ' + n
  5768. );
  5769. }
  5770. }
  5771. Assertion.addMethod('above', assertAbove);
  5772. Assertion.addMethod('gt', assertAbove);
  5773. Assertion.addMethod('greaterThan', assertAbove);
  5774. /**
  5775. * ### .least(value)
  5776. *
  5777. * Asserts that the target is greater than or equal to `value`.
  5778. *
  5779. * expect(10).to.be.at.least(10);
  5780. *
  5781. * Can also be used in conjunction with `length` to
  5782. * assert a minimum length. The benefit being a
  5783. * more informative error message than if the length
  5784. * was supplied directly.
  5785. *
  5786. * expect('foo').to.have.length.of.at.least(2);
  5787. * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
  5788. *
  5789. * @name least
  5790. * @alias gte
  5791. * @param {Number} value
  5792. * @param {String} message _optional_
  5793. * @namespace BDD
  5794. * @api public
  5795. */
  5796. function assertLeast (n, msg) {
  5797. if (msg) flag(this, 'message', msg);
  5798. var obj = flag(this, 'object');
  5799. if (flag(this, 'doLength')) {
  5800. new Assertion(obj, msg).to.have.property('length');
  5801. var len = obj.length;
  5802. this.assert(
  5803. len >= n
  5804. , 'expected #{this} to have a length at least #{exp} but got #{act}'
  5805. , 'expected #{this} to have a length below #{exp}'
  5806. , n
  5807. , len
  5808. );
  5809. } else {
  5810. this.assert(
  5811. obj >= n
  5812. , 'expected #{this} to be at least ' + n
  5813. , 'expected #{this} to be below ' + n
  5814. );
  5815. }
  5816. }
  5817. Assertion.addMethod('least', assertLeast);
  5818. Assertion.addMethod('gte', assertLeast);
  5819. /**
  5820. * ### .below(value)
  5821. *
  5822. * Asserts that the target is less than `value`.
  5823. *
  5824. * expect(5).to.be.below(10);
  5825. *
  5826. * Can also be used in conjunction with `length` to
  5827. * assert a maximum length. The benefit being a
  5828. * more informative error message than if the length
  5829. * was supplied directly.
  5830. *
  5831. * expect('foo').to.have.length.below(4);
  5832. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  5833. *
  5834. * @name below
  5835. * @alias lt
  5836. * @alias lessThan
  5837. * @param {Number} value
  5838. * @param {String} message _optional_
  5839. * @namespace BDD
  5840. * @api public
  5841. */
  5842. function assertBelow (n, msg) {
  5843. if (msg) flag(this, 'message', msg);
  5844. var obj = flag(this, 'object');
  5845. if (flag(this, 'doLength')) {
  5846. new Assertion(obj, msg).to.have.property('length');
  5847. var len = obj.length;
  5848. this.assert(
  5849. len < n
  5850. , 'expected #{this} to have a length below #{exp} but got #{act}'
  5851. , 'expected #{this} to not have a length below #{exp}'
  5852. , n
  5853. , len
  5854. );
  5855. } else {
  5856. this.assert(
  5857. obj < n
  5858. , 'expected #{this} to be below ' + n
  5859. , 'expected #{this} to be at least ' + n
  5860. );
  5861. }
  5862. }
  5863. Assertion.addMethod('below', assertBelow);
  5864. Assertion.addMethod('lt', assertBelow);
  5865. Assertion.addMethod('lessThan', assertBelow);
  5866. /**
  5867. * ### .most(value)
  5868. *
  5869. * Asserts that the target is less than or equal to `value`.
  5870. *
  5871. * expect(5).to.be.at.most(5);
  5872. *
  5873. * Can also be used in conjunction with `length` to
  5874. * assert a maximum length. The benefit being a
  5875. * more informative error message than if the length
  5876. * was supplied directly.
  5877. *
  5878. * expect('foo').to.have.length.of.at.most(4);
  5879. * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
  5880. *
  5881. * @name most
  5882. * @alias lte
  5883. * @param {Number} value
  5884. * @param {String} message _optional_
  5885. * @namespace BDD
  5886. * @api public
  5887. */
  5888. function assertMost (n, msg) {
  5889. if (msg) flag(this, 'message', msg);
  5890. var obj = flag(this, 'object');
  5891. if (flag(this, 'doLength')) {
  5892. new Assertion(obj, msg).to.have.property('length');
  5893. var len = obj.length;
  5894. this.assert(
  5895. len <= n
  5896. , 'expected #{this} to have a length at most #{exp} but got #{act}'
  5897. , 'expected #{this} to have a length above #{exp}'
  5898. , n
  5899. , len
  5900. );
  5901. } else {
  5902. this.assert(
  5903. obj <= n
  5904. , 'expected #{this} to be at most ' + n
  5905. , 'expected #{this} to be above ' + n
  5906. );
  5907. }
  5908. }
  5909. Assertion.addMethod('most', assertMost);
  5910. Assertion.addMethod('lte', assertMost);
  5911. /**
  5912. * ### .within(start, finish)
  5913. *
  5914. * Asserts that the target is within a range.
  5915. *
  5916. * expect(7).to.be.within(5,10);
  5917. *
  5918. * Can also be used in conjunction with `length` to
  5919. * assert a length range. The benefit being a
  5920. * more informative error message than if the length
  5921. * was supplied directly.
  5922. *
  5923. * expect('foo').to.have.length.within(2,4);
  5924. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  5925. *
  5926. * @name within
  5927. * @param {Number} start lowerbound inclusive
  5928. * @param {Number} finish upperbound inclusive
  5929. * @param {String} message _optional_
  5930. * @namespace BDD
  5931. * @api public
  5932. */
  5933. Assertion.addMethod('within', function (start, finish, msg) {
  5934. if (msg) flag(this, 'message', msg);
  5935. var obj = flag(this, 'object')
  5936. , range = start + '..' + finish;
  5937. if (flag(this, 'doLength')) {
  5938. new Assertion(obj, msg).to.have.property('length');
  5939. var len = obj.length;
  5940. this.assert(
  5941. len >= start && len <= finish
  5942. , 'expected #{this} to have a length within ' + range
  5943. , 'expected #{this} to not have a length within ' + range
  5944. );
  5945. } else {
  5946. this.assert(
  5947. obj >= start && obj <= finish
  5948. , 'expected #{this} to be within ' + range
  5949. , 'expected #{this} to not be within ' + range
  5950. );
  5951. }
  5952. });
  5953. /**
  5954. * ### .instanceof(constructor)
  5955. *
  5956. * Asserts that the target is an instance of `constructor`.
  5957. *
  5958. * var Tea = function (name) { this.name = name; }
  5959. * , Chai = new Tea('chai');
  5960. *
  5961. * expect(Chai).to.be.an.instanceof(Tea);
  5962. * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
  5963. *
  5964. * @name instanceof
  5965. * @param {Constructor} constructor
  5966. * @param {String} message _optional_
  5967. * @alias instanceOf
  5968. * @namespace BDD
  5969. * @api public
  5970. */
  5971. function assertInstanceOf (constructor, msg) {
  5972. if (msg) flag(this, 'message', msg);
  5973. var name = _.getName(constructor);
  5974. this.assert(
  5975. flag(this, 'object') instanceof constructor
  5976. , 'expected #{this} to be an instance of ' + name
  5977. , 'expected #{this} to not be an instance of ' + name
  5978. );
  5979. };
  5980. Assertion.addMethod('instanceof', assertInstanceOf);
  5981. Assertion.addMethod('instanceOf', assertInstanceOf);
  5982. /**
  5983. * ### .property(name, [value])
  5984. *
  5985. * Asserts that the target has a property `name`, optionally asserting that
  5986. * the value of that property is strictly equal to `value`.
  5987. * If the `deep` flag is set, you can use dot- and bracket-notation for deep
  5988. * references into objects and arrays.
  5989. *
  5990. * // simple referencing
  5991. * var obj = { foo: 'bar' };
  5992. * expect(obj).to.have.property('foo');
  5993. * expect(obj).to.have.property('foo', 'bar');
  5994. *
  5995. * // deep referencing
  5996. * var deepObj = {
  5997. * green: { tea: 'matcha' }
  5998. * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
  5999. * };
  6000. *
  6001. * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
  6002. * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
  6003. * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
  6004. *
  6005. * You can also use an array as the starting point of a `deep.property`
  6006. * assertion, or traverse nested arrays.
  6007. *
  6008. * var arr = [
  6009. * [ 'chai', 'matcha', 'konacha' ]
  6010. * , [ { tea: 'chai' }
  6011. * , { tea: 'matcha' }
  6012. * , { tea: 'konacha' } ]
  6013. * ];
  6014. *
  6015. * expect(arr).to.have.deep.property('[0][1]', 'matcha');
  6016. * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
  6017. *
  6018. * Furthermore, `property` changes the subject of the assertion
  6019. * to be the value of that property from the original object. This
  6020. * permits for further chainable assertions on that property.
  6021. *
  6022. * expect(obj).to.have.property('foo')
  6023. * .that.is.a('string');
  6024. * expect(deepObj).to.have.property('green')
  6025. * .that.is.an('object')
  6026. * .that.deep.equals({ tea: 'matcha' });
  6027. * expect(deepObj).to.have.property('teas')
  6028. * .that.is.an('array')
  6029. * .with.deep.property('[2]')
  6030. * .that.deep.equals({ tea: 'konacha' });
  6031. *
  6032. * Note that dots and bracket in `name` must be backslash-escaped when
  6033. * the `deep` flag is set, while they must NOT be escaped when the `deep`
  6034. * flag is not set.
  6035. *
  6036. * // simple referencing
  6037. * var css = { '.link[target]': 42 };
  6038. * expect(css).to.have.property('.link[target]', 42);
  6039. *
  6040. * // deep referencing
  6041. * var deepCss = { '.link': { '[target]': 42 }};
  6042. * expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);
  6043. *
  6044. * @name property
  6045. * @alias deep.property
  6046. * @param {String} name
  6047. * @param {Mixed} value (optional)
  6048. * @param {String} message _optional_
  6049. * @returns value of property for chaining
  6050. * @namespace BDD
  6051. * @api public
  6052. */
  6053. Assertion.addMethod('property', function (name, val, msg) {
  6054. if (msg) flag(this, 'message', msg);
  6055. var isDeep = !!flag(this, 'deep')
  6056. , descriptor = isDeep ? 'deep property ' : 'property '
  6057. , negate = flag(this, 'negate')
  6058. , obj = flag(this, 'object')
  6059. , pathInfo = isDeep ? _.getPathInfo(name, obj) : null
  6060. , hasProperty = isDeep
  6061. ? pathInfo.exists
  6062. : _.hasProperty(name, obj)
  6063. , value = isDeep
  6064. ? pathInfo.value
  6065. : obj[name];
  6066. if (negate && arguments.length > 1) {
  6067. if (undefined === value) {
  6068. msg = (msg != null) ? msg + ': ' : '';
  6069. throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
  6070. }
  6071. } else {
  6072. this.assert(
  6073. hasProperty
  6074. , 'expected #{this} to have a ' + descriptor + _.inspect(name)
  6075. , 'expected #{this} to not have ' + descriptor + _.inspect(name));
  6076. }
  6077. if (arguments.length > 1) {
  6078. this.assert(
  6079. val === value
  6080. , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
  6081. , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'
  6082. , val
  6083. , value
  6084. );
  6085. }
  6086. flag(this, 'object', value);
  6087. });
  6088. /**
  6089. * ### .ownProperty(name)
  6090. *
  6091. * Asserts that the target has an own property `name`.
  6092. *
  6093. * expect('test').to.have.ownProperty('length');
  6094. *
  6095. * @name ownProperty
  6096. * @alias haveOwnProperty
  6097. * @param {String} name
  6098. * @param {String} message _optional_
  6099. * @namespace BDD
  6100. * @api public
  6101. */
  6102. function assertOwnProperty (name, msg) {
  6103. if (msg) flag(this, 'message', msg);
  6104. var obj = flag(this, 'object');
  6105. this.assert(
  6106. obj.hasOwnProperty(name)
  6107. , 'expected #{this} to have own property ' + _.inspect(name)
  6108. , 'expected #{this} to not have own property ' + _.inspect(name)
  6109. );
  6110. }
  6111. Assertion.addMethod('ownProperty', assertOwnProperty);
  6112. Assertion.addMethod('haveOwnProperty', assertOwnProperty);
  6113. /**
  6114. * ### .ownPropertyDescriptor(name[, descriptor[, message]])
  6115. *
  6116. * Asserts that the target has an own property descriptor `name`, that optionally matches `descriptor`.
  6117. *
  6118. * expect('test').to.have.ownPropertyDescriptor('length');
  6119. * expect('test').to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 4 });
  6120. * expect('test').not.to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 3 });
  6121. * expect('test').ownPropertyDescriptor('length').to.have.property('enumerable', false);
  6122. * expect('test').ownPropertyDescriptor('length').to.have.keys('value');
  6123. *
  6124. * @name ownPropertyDescriptor
  6125. * @alias haveOwnPropertyDescriptor
  6126. * @param {String} name
  6127. * @param {Object} descriptor _optional_
  6128. * @param {String} message _optional_
  6129. * @namespace BDD
  6130. * @api public
  6131. */
  6132. function assertOwnPropertyDescriptor (name, descriptor, msg) {
  6133. if (typeof descriptor === 'string') {
  6134. msg = descriptor;
  6135. descriptor = null;
  6136. }
  6137. if (msg) flag(this, 'message', msg);
  6138. var obj = flag(this, 'object');
  6139. var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
  6140. if (actualDescriptor && descriptor) {
  6141. this.assert(
  6142. _.eql(descriptor, actualDescriptor)
  6143. , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)
  6144. , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)
  6145. , descriptor
  6146. , actualDescriptor
  6147. , true
  6148. );
  6149. } else {
  6150. this.assert(
  6151. actualDescriptor
  6152. , 'expected #{this} to have an own property descriptor for ' + _.inspect(name)
  6153. , 'expected #{this} to not have an own property descriptor for ' + _.inspect(name)
  6154. );
  6155. }
  6156. flag(this, 'object', actualDescriptor);
  6157. }
  6158. Assertion.addMethod('ownPropertyDescriptor', assertOwnPropertyDescriptor);
  6159. Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
  6160. /**
  6161. * ### .length
  6162. *
  6163. * Sets the `doLength` flag later used as a chain precursor to a value
  6164. * comparison for the `length` property.
  6165. *
  6166. * expect('foo').to.have.length.above(2);
  6167. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  6168. * expect('foo').to.have.length.below(4);
  6169. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  6170. * expect('foo').to.have.length.within(2,4);
  6171. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  6172. *
  6173. * *Deprecation notice:* Using `length` as an assertion will be deprecated
  6174. * in version 2.4.0 and removed in 3.0.0. Code using the old style of
  6175. * asserting for `length` property value using `length(value)` should be
  6176. * switched to use `lengthOf(value)` instead.
  6177. *
  6178. * @name length
  6179. * @namespace BDD
  6180. * @api public
  6181. */
  6182. /**
  6183. * ### .lengthOf(value[, message])
  6184. *
  6185. * Asserts that the target's `length` property has
  6186. * the expected value.
  6187. *
  6188. * expect([ 1, 2, 3]).to.have.lengthOf(3);
  6189. * expect('foobar').to.have.lengthOf(6);
  6190. *
  6191. * @name lengthOf
  6192. * @param {Number} length
  6193. * @param {String} message _optional_
  6194. * @namespace BDD
  6195. * @api public
  6196. */
  6197. function assertLengthChain () {
  6198. flag(this, 'doLength', true);
  6199. }
  6200. function assertLength (n, msg) {
  6201. if (msg) flag(this, 'message', msg);
  6202. var obj = flag(this, 'object');
  6203. new Assertion(obj, msg).to.have.property('length');
  6204. var len = obj.length;
  6205. this.assert(
  6206. len == n
  6207. , 'expected #{this} to have a length of #{exp} but got #{act}'
  6208. , 'expected #{this} to not have a length of #{act}'
  6209. , n
  6210. , len
  6211. );
  6212. }
  6213. Assertion.addChainableMethod('length', assertLength, assertLengthChain);
  6214. Assertion.addMethod('lengthOf', assertLength);
  6215. /**
  6216. * ### .match(regexp)
  6217. *
  6218. * Asserts that the target matches a regular expression.
  6219. *
  6220. * expect('foobar').to.match(/^foo/);
  6221. *
  6222. * @name match
  6223. * @alias matches
  6224. * @param {RegExp} RegularExpression
  6225. * @param {String} message _optional_
  6226. * @namespace BDD
  6227. * @api public
  6228. */
  6229. function assertMatch(re, msg) {
  6230. if (msg) flag(this, 'message', msg);
  6231. var obj = flag(this, 'object');
  6232. this.assert(
  6233. re.exec(obj)
  6234. , 'expected #{this} to match ' + re
  6235. , 'expected #{this} not to match ' + re
  6236. );
  6237. }
  6238. Assertion.addMethod('match', assertMatch);
  6239. Assertion.addMethod('matches', assertMatch);
  6240. /**
  6241. * ### .string(string)
  6242. *
  6243. * Asserts that the string target contains another string.
  6244. *
  6245. * expect('foobar').to.have.string('bar');
  6246. *
  6247. * @name string
  6248. * @param {String} string
  6249. * @param {String} message _optional_
  6250. * @namespace BDD
  6251. * @api public
  6252. */
  6253. Assertion.addMethod('string', function (str, msg) {
  6254. if (msg) flag(this, 'message', msg);
  6255. var obj = flag(this, 'object');
  6256. new Assertion(obj, msg).is.a('string');
  6257. this.assert(
  6258. ~obj.indexOf(str)
  6259. , 'expected #{this} to contain ' + _.inspect(str)
  6260. , 'expected #{this} to not contain ' + _.inspect(str)
  6261. );
  6262. });
  6263. /**
  6264. * ### .keys(key1, [key2], [...])
  6265. *
  6266. * Asserts that the target contains any or all of the passed-in keys.
  6267. * Use in combination with `any`, `all`, `contains`, or `have` will affect
  6268. * what will pass.
  6269. *
  6270. * When used in conjunction with `any`, at least one key that is passed
  6271. * in must exist in the target object. This is regardless whether or not
  6272. * the `have` or `contain` qualifiers are used. Note, either `any` or `all`
  6273. * should be used in the assertion. If neither are used, the assertion is
  6274. * defaulted to `all`.
  6275. *
  6276. * When both `all` and `contain` are used, the target object must have at
  6277. * least all of the passed-in keys but may have more keys not listed.
  6278. *
  6279. * When both `all` and `have` are used, the target object must both contain
  6280. * all of the passed-in keys AND the number of keys in the target object must
  6281. * match the number of keys passed in (in other words, a target object must
  6282. * have all and only all of the passed-in keys).
  6283. *
  6284. * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz');
  6285. * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo');
  6286. * expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz');
  6287. * expect({ foo: 1, bar: 2 }).to.contain.any.keys(['foo']);
  6288. * expect({ foo: 1, bar: 2 }).to.contain.any.keys({'foo': 6});
  6289. * expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']);
  6290. * expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo': 7});
  6291. * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']);
  6292. * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys({'bar': 6});
  6293. *
  6294. *
  6295. * @name keys
  6296. * @alias key
  6297. * @param {...String|Array|Object} keys
  6298. * @namespace BDD
  6299. * @api public
  6300. */
  6301. function assertKeys (keys) {
  6302. var obj = flag(this, 'object')
  6303. , str
  6304. , ok = true
  6305. , mixedArgsMsg = 'keys must be given single argument of Array|Object|String, or multiple String arguments';
  6306. switch (_.type(keys)) {
  6307. case "array":
  6308. if (arguments.length > 1) throw (new Error(mixedArgsMsg));
  6309. break;
  6310. case "object":
  6311. if (arguments.length > 1) throw (new Error(mixedArgsMsg));
  6312. keys = Object.keys(keys);
  6313. break;
  6314. default:
  6315. keys = Array.prototype.slice.call(arguments);
  6316. }
  6317. if (!keys.length) throw new Error('keys required');
  6318. var actual = Object.keys(obj)
  6319. , expected = keys
  6320. , len = keys.length
  6321. , any = flag(this, 'any')
  6322. , all = flag(this, 'all');
  6323. if (!any && !all) {
  6324. all = true;
  6325. }
  6326. // Has any
  6327. if (any) {
  6328. var intersection = expected.filter(function(key) {
  6329. return ~actual.indexOf(key);
  6330. });
  6331. ok = intersection.length > 0;
  6332. }
  6333. // Has all
  6334. if (all) {
  6335. ok = keys.every(function(key){
  6336. return ~actual.indexOf(key);
  6337. });
  6338. if (!flag(this, 'negate') && !flag(this, 'contains')) {
  6339. ok = ok && keys.length == actual.length;
  6340. }
  6341. }
  6342. // Key string
  6343. if (len > 1) {
  6344. keys = keys.map(function(key){
  6345. return _.inspect(key);
  6346. });
  6347. var last = keys.pop();
  6348. if (all) {
  6349. str = keys.join(', ') + ', and ' + last;
  6350. }
  6351. if (any) {
  6352. str = keys.join(', ') + ', or ' + last;
  6353. }
  6354. } else {
  6355. str = _.inspect(keys[0]);
  6356. }
  6357. // Form
  6358. str = (len > 1 ? 'keys ' : 'key ') + str;
  6359. // Have / include
  6360. str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
  6361. // Assertion
  6362. this.assert(
  6363. ok
  6364. , 'expected #{this} to ' + str
  6365. , 'expected #{this} to not ' + str
  6366. , expected.slice(0).sort()
  6367. , actual.sort()
  6368. , true
  6369. );
  6370. }
  6371. Assertion.addMethod('keys', assertKeys);
  6372. Assertion.addMethod('key', assertKeys);
  6373. /**
  6374. * ### .throw(constructor)
  6375. *
  6376. * Asserts that the function target will throw a specific error, or specific type of error
  6377. * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
  6378. * for the error's message.
  6379. *
  6380. * var err = new ReferenceError('This is a bad function.');
  6381. * var fn = function () { throw err; }
  6382. * expect(fn).to.throw(ReferenceError);
  6383. * expect(fn).to.throw(Error);
  6384. * expect(fn).to.throw(/bad function/);
  6385. * expect(fn).to.not.throw('good function');
  6386. * expect(fn).to.throw(ReferenceError, /bad function/);
  6387. * expect(fn).to.throw(err);
  6388. *
  6389. * Please note that when a throw expectation is negated, it will check each
  6390. * parameter independently, starting with error constructor type. The appropriate way
  6391. * to check for the existence of a type of error but for a message that does not match
  6392. * is to use `and`.
  6393. *
  6394. * expect(fn).to.throw(ReferenceError)
  6395. * .and.not.throw(/good function/);
  6396. *
  6397. * @name throw
  6398. * @alias throws
  6399. * @alias Throw
  6400. * @param {ErrorConstructor} constructor
  6401. * @param {String|RegExp} expected error message
  6402. * @param {String} message _optional_
  6403. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  6404. * @returns error for chaining (null if no error)
  6405. * @namespace BDD
  6406. * @api public
  6407. */
  6408. function assertThrows (constructor, errMsg, msg) {
  6409. if (msg) flag(this, 'message', msg);
  6410. var obj = flag(this, 'object');
  6411. new Assertion(obj, msg).is.a('function');
  6412. var thrown = false
  6413. , desiredError = null
  6414. , name = null
  6415. , thrownError = null;
  6416. if (arguments.length === 0) {
  6417. errMsg = null;
  6418. constructor = null;
  6419. } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
  6420. errMsg = constructor;
  6421. constructor = null;
  6422. } else if (constructor && constructor instanceof Error) {
  6423. desiredError = constructor;
  6424. constructor = null;
  6425. errMsg = null;
  6426. } else if (typeof constructor === 'function') {
  6427. name = constructor.prototype.name;
  6428. if (!name || (name === 'Error' && constructor !== Error)) {
  6429. name = constructor.name || (new constructor()).name;
  6430. }
  6431. } else {
  6432. constructor = null;
  6433. }
  6434. try {
  6435. obj();
  6436. } catch (err) {
  6437. // first, check desired error
  6438. if (desiredError) {
  6439. this.assert(
  6440. err === desiredError
  6441. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  6442. , 'expected #{this} to not throw #{exp}'
  6443. , (desiredError instanceof Error ? desiredError.toString() : desiredError)
  6444. , (err instanceof Error ? err.toString() : err)
  6445. );
  6446. flag(this, 'object', err);
  6447. return this;
  6448. }
  6449. // next, check constructor
  6450. if (constructor) {
  6451. this.assert(
  6452. err instanceof constructor
  6453. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  6454. , 'expected #{this} to not throw #{exp} but #{act} was thrown'
  6455. , name
  6456. , (err instanceof Error ? err.toString() : err)
  6457. );
  6458. if (!errMsg) {
  6459. flag(this, 'object', err);
  6460. return this;
  6461. }
  6462. }
  6463. // next, check message
  6464. var message = 'error' === _.type(err) && "message" in err
  6465. ? err.message
  6466. : '' + err;
  6467. if ((message != null) && errMsg && errMsg instanceof RegExp) {
  6468. this.assert(
  6469. errMsg.exec(message)
  6470. , 'expected #{this} to throw error matching #{exp} but got #{act}'
  6471. , 'expected #{this} to throw error not matching #{exp}'
  6472. , errMsg
  6473. , message
  6474. );
  6475. flag(this, 'object', err);
  6476. return this;
  6477. } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
  6478. this.assert(
  6479. ~message.indexOf(errMsg)
  6480. , 'expected #{this} to throw error including #{exp} but got #{act}'
  6481. , 'expected #{this} to throw error not including #{act}'
  6482. , errMsg
  6483. , message
  6484. );
  6485. flag(this, 'object', err);
  6486. return this;
  6487. } else {
  6488. thrown = true;
  6489. thrownError = err;
  6490. }
  6491. }
  6492. var actuallyGot = ''
  6493. , expectedThrown = name !== null
  6494. ? name
  6495. : desiredError
  6496. ? '#{exp}' //_.inspect(desiredError)
  6497. : 'an error';
  6498. if (thrown) {
  6499. actuallyGot = ' but #{act} was thrown'
  6500. }
  6501. this.assert(
  6502. thrown === true
  6503. , 'expected #{this} to throw ' + expectedThrown + actuallyGot
  6504. , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
  6505. , (desiredError instanceof Error ? desiredError.toString() : desiredError)
  6506. , (thrownError instanceof Error ? thrownError.toString() : thrownError)
  6507. );
  6508. flag(this, 'object', thrownError);
  6509. };
  6510. Assertion.addMethod('throw', assertThrows);
  6511. Assertion.addMethod('throws', assertThrows);
  6512. Assertion.addMethod('Throw', assertThrows);
  6513. /**
  6514. * ### .respondTo(method)
  6515. *
  6516. * Asserts that the object or class target will respond to a method.
  6517. *
  6518. * Klass.prototype.bar = function(){};
  6519. * expect(Klass).to.respondTo('bar');
  6520. * expect(obj).to.respondTo('bar');
  6521. *
  6522. * To check if a constructor will respond to a static function,
  6523. * set the `itself` flag.
  6524. *
  6525. * Klass.baz = function(){};
  6526. * expect(Klass).itself.to.respondTo('baz');
  6527. *
  6528. * @name respondTo
  6529. * @alias respondsTo
  6530. * @param {String} method
  6531. * @param {String} message _optional_
  6532. * @namespace BDD
  6533. * @api public
  6534. */
  6535. function respondTo (method, msg) {
  6536. if (msg) flag(this, 'message', msg);
  6537. var obj = flag(this, 'object')
  6538. , itself = flag(this, 'itself')
  6539. , context = ('function' === _.type(obj) && !itself)
  6540. ? obj.prototype[method]
  6541. : obj[method];
  6542. this.assert(
  6543. 'function' === typeof context
  6544. , 'expected #{this} to respond to ' + _.inspect(method)
  6545. , 'expected #{this} to not respond to ' + _.inspect(method)
  6546. );
  6547. }
  6548. Assertion.addMethod('respondTo', respondTo);
  6549. Assertion.addMethod('respondsTo', respondTo);
  6550. /**
  6551. * ### .itself
  6552. *
  6553. * Sets the `itself` flag, later used by the `respondTo` assertion.
  6554. *
  6555. * function Foo() {}
  6556. * Foo.bar = function() {}
  6557. * Foo.prototype.baz = function() {}
  6558. *
  6559. * expect(Foo).itself.to.respondTo('bar');
  6560. * expect(Foo).itself.not.to.respondTo('baz');
  6561. *
  6562. * @name itself
  6563. * @namespace BDD
  6564. * @api public
  6565. */
  6566. Assertion.addProperty('itself', function () {
  6567. flag(this, 'itself', true);
  6568. });
  6569. /**
  6570. * ### .satisfy(method)
  6571. *
  6572. * Asserts that the target passes a given truth test.
  6573. *
  6574. * expect(1).to.satisfy(function(num) { return num > 0; });
  6575. *
  6576. * @name satisfy
  6577. * @alias satisfies
  6578. * @param {Function} matcher
  6579. * @param {String} message _optional_
  6580. * @namespace BDD
  6581. * @api public
  6582. */
  6583. function satisfy (matcher, msg) {
  6584. if (msg) flag(this, 'message', msg);
  6585. var obj = flag(this, 'object');
  6586. var result = matcher(obj);
  6587. this.assert(
  6588. result
  6589. , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
  6590. , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
  6591. , this.negate ? false : true
  6592. , result
  6593. );
  6594. }
  6595. Assertion.addMethod('satisfy', satisfy);
  6596. Assertion.addMethod('satisfies', satisfy);
  6597. /**
  6598. * ### .closeTo(expected, delta)
  6599. *
  6600. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  6601. *
  6602. * expect(1.5).to.be.closeTo(1, 0.5);
  6603. *
  6604. * @name closeTo
  6605. * @alias approximately
  6606. * @param {Number} expected
  6607. * @param {Number} delta
  6608. * @param {String} message _optional_
  6609. * @namespace BDD
  6610. * @api public
  6611. */
  6612. function closeTo(expected, delta, msg) {
  6613. if (msg) flag(this, 'message', msg);
  6614. var obj = flag(this, 'object');
  6615. new Assertion(obj, msg).is.a('number');
  6616. if (_.type(expected) !== 'number' || _.type(delta) !== 'number') {
  6617. throw new Error('the arguments to closeTo or approximately must be numbers');
  6618. }
  6619. this.assert(
  6620. Math.abs(obj - expected) <= delta
  6621. , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
  6622. , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
  6623. );
  6624. }
  6625. Assertion.addMethod('closeTo', closeTo);
  6626. Assertion.addMethod('approximately', closeTo);
  6627. function isSubsetOf(subset, superset, cmp) {
  6628. return subset.every(function(elem) {
  6629. if (!cmp) return superset.indexOf(elem) !== -1;
  6630. return superset.some(function(elem2) {
  6631. return cmp(elem, elem2);
  6632. });
  6633. })
  6634. }
  6635. /**
  6636. * ### .members(set)
  6637. *
  6638. * Asserts that the target is a superset of `set`,
  6639. * or that the target and `set` have the same strictly-equal (===) members.
  6640. * Alternately, if the `deep` flag is set, set members are compared for deep
  6641. * equality.
  6642. *
  6643. * expect([1, 2, 3]).to.include.members([3, 2]);
  6644. * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
  6645. *
  6646. * expect([4, 2]).to.have.members([2, 4]);
  6647. * expect([5, 2]).to.not.have.members([5, 2, 1]);
  6648. *
  6649. * expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
  6650. *
  6651. * @name members
  6652. * @param {Array} set
  6653. * @param {String} message _optional_
  6654. * @namespace BDD
  6655. * @api public
  6656. */
  6657. Assertion.addMethod('members', function (subset, msg) {
  6658. if (msg) flag(this, 'message', msg);
  6659. var obj = flag(this, 'object');
  6660. new Assertion(obj).to.be.an('array');
  6661. new Assertion(subset).to.be.an('array');
  6662. var cmp = flag(this, 'deep') ? _.eql : undefined;
  6663. if (flag(this, 'contains')) {
  6664. return this.assert(
  6665. isSubsetOf(subset, obj, cmp)
  6666. , 'expected #{this} to be a superset of #{act}'
  6667. , 'expected #{this} to not be a superset of #{act}'
  6668. , obj
  6669. , subset
  6670. );
  6671. }
  6672. this.assert(
  6673. isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
  6674. , 'expected #{this} to have the same members as #{act}'
  6675. , 'expected #{this} to not have the same members as #{act}'
  6676. , obj
  6677. , subset
  6678. );
  6679. });
  6680. /**
  6681. * ### .oneOf(list)
  6682. *
  6683. * Assert that a value appears somewhere in the top level of array `list`.
  6684. *
  6685. * expect('a').to.be.oneOf(['a', 'b', 'c']);
  6686. * expect(9).to.not.be.oneOf(['z']);
  6687. * expect([3]).to.not.be.oneOf([1, 2, [3]]);
  6688. *
  6689. * var three = [3];
  6690. * // for object-types, contents are not compared
  6691. * expect(three).to.not.be.oneOf([1, 2, [3]]);
  6692. * // comparing references works
  6693. * expect(three).to.be.oneOf([1, 2, three]);
  6694. *
  6695. * @name oneOf
  6696. * @param {Array<*>} list
  6697. * @param {String} message _optional_
  6698. * @namespace BDD
  6699. * @api public
  6700. */
  6701. function oneOf (list, msg) {
  6702. if (msg) flag(this, 'message', msg);
  6703. var expected = flag(this, 'object');
  6704. new Assertion(list).to.be.an('array');
  6705. this.assert(
  6706. list.indexOf(expected) > -1
  6707. , 'expected #{this} to be one of #{exp}'
  6708. , 'expected #{this} to not be one of #{exp}'
  6709. , list
  6710. , expected
  6711. );
  6712. }
  6713. Assertion.addMethod('oneOf', oneOf);
  6714. /**
  6715. * ### .change(function)
  6716. *
  6717. * Asserts that a function changes an object property
  6718. *
  6719. * var obj = { val: 10 };
  6720. * var fn = function() { obj.val += 3 };
  6721. * var noChangeFn = function() { return 'foo' + 'bar'; }
  6722. * expect(fn).to.change(obj, 'val');
  6723. * expect(noChangeFn).to.not.change(obj, 'val')
  6724. *
  6725. * @name change
  6726. * @alias changes
  6727. * @alias Change
  6728. * @param {String} object
  6729. * @param {String} property name
  6730. * @param {String} message _optional_
  6731. * @namespace BDD
  6732. * @api public
  6733. */
  6734. function assertChanges (object, prop, msg) {
  6735. if (msg) flag(this, 'message', msg);
  6736. var fn = flag(this, 'object');
  6737. new Assertion(object, msg).to.have.property(prop);
  6738. new Assertion(fn).is.a('function');
  6739. var initial = object[prop];
  6740. fn();
  6741. this.assert(
  6742. initial !== object[prop]
  6743. , 'expected .' + prop + ' to change'
  6744. , 'expected .' + prop + ' to not change'
  6745. );
  6746. }
  6747. Assertion.addChainableMethod('change', assertChanges);
  6748. Assertion.addChainableMethod('changes', assertChanges);
  6749. /**
  6750. * ### .increase(function)
  6751. *
  6752. * Asserts that a function increases an object property
  6753. *
  6754. * var obj = { val: 10 };
  6755. * var fn = function() { obj.val = 15 };
  6756. * expect(fn).to.increase(obj, 'val');
  6757. *
  6758. * @name increase
  6759. * @alias increases
  6760. * @alias Increase
  6761. * @param {String} object
  6762. * @param {String} property name
  6763. * @param {String} message _optional_
  6764. * @namespace BDD
  6765. * @api public
  6766. */
  6767. function assertIncreases (object, prop, msg) {
  6768. if (msg) flag(this, 'message', msg);
  6769. var fn = flag(this, 'object');
  6770. new Assertion(object, msg).to.have.property(prop);
  6771. new Assertion(fn).is.a('function');
  6772. var initial = object[prop];
  6773. fn();
  6774. this.assert(
  6775. object[prop] - initial > 0
  6776. , 'expected .' + prop + ' to increase'
  6777. , 'expected .' + prop + ' to not increase'
  6778. );
  6779. }
  6780. Assertion.addChainableMethod('increase', assertIncreases);
  6781. Assertion.addChainableMethod('increases', assertIncreases);
  6782. /**
  6783. * ### .decrease(function)
  6784. *
  6785. * Asserts that a function decreases an object property
  6786. *
  6787. * var obj = { val: 10 };
  6788. * var fn = function() { obj.val = 5 };
  6789. * expect(fn).to.decrease(obj, 'val');
  6790. *
  6791. * @name decrease
  6792. * @alias decreases
  6793. * @alias Decrease
  6794. * @param {String} object
  6795. * @param {String} property name
  6796. * @param {String} message _optional_
  6797. * @namespace BDD
  6798. * @api public
  6799. */
  6800. function assertDecreases (object, prop, msg) {
  6801. if (msg) flag(this, 'message', msg);
  6802. var fn = flag(this, 'object');
  6803. new Assertion(object, msg).to.have.property(prop);
  6804. new Assertion(fn).is.a('function');
  6805. var initial = object[prop];
  6806. fn();
  6807. this.assert(
  6808. object[prop] - initial < 0
  6809. , 'expected .' + prop + ' to decrease'
  6810. , 'expected .' + prop + ' to not decrease'
  6811. );
  6812. }
  6813. Assertion.addChainableMethod('decrease', assertDecreases);
  6814. Assertion.addChainableMethod('decreases', assertDecreases);
  6815. /**
  6816. * ### .extensible
  6817. *
  6818. * Asserts that the target is extensible (can have new properties added to
  6819. * it).
  6820. *
  6821. * var nonExtensibleObject = Object.preventExtensions({});
  6822. * var sealedObject = Object.seal({});
  6823. * var frozenObject = Object.freeze({});
  6824. *
  6825. * expect({}).to.be.extensible;
  6826. * expect(nonExtensibleObject).to.not.be.extensible;
  6827. * expect(sealedObject).to.not.be.extensible;
  6828. * expect(frozenObject).to.not.be.extensible;
  6829. *
  6830. * @name extensible
  6831. * @namespace BDD
  6832. * @api public
  6833. */
  6834. Assertion.addProperty('extensible', function() {
  6835. var obj = flag(this, 'object');
  6836. // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
  6837. // In ES6, a non-object argument will be treated as if it was a non-extensible ordinary object, simply return false.
  6838. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
  6839. // The following provides ES6 behavior when a TypeError is thrown under ES5.
  6840. var isExtensible;
  6841. try {
  6842. isExtensible = Object.isExtensible(obj);
  6843. } catch (err) {
  6844. if (err instanceof TypeError) isExtensible = false;
  6845. else throw err;
  6846. }
  6847. this.assert(
  6848. isExtensible
  6849. , 'expected #{this} to be extensible'
  6850. , 'expected #{this} to not be extensible'
  6851. );
  6852. });
  6853. /**
  6854. * ### .sealed
  6855. *
  6856. * Asserts that the target is sealed (cannot have new properties added to it
  6857. * and its existing properties cannot be removed).
  6858. *
  6859. * var sealedObject = Object.seal({});
  6860. * var frozenObject = Object.freeze({});
  6861. *
  6862. * expect(sealedObject).to.be.sealed;
  6863. * expect(frozenObject).to.be.sealed;
  6864. * expect({}).to.not.be.sealed;
  6865. *
  6866. * @name sealed
  6867. * @namespace BDD
  6868. * @api public
  6869. */
  6870. Assertion.addProperty('sealed', function() {
  6871. var obj = flag(this, 'object');
  6872. // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
  6873. // In ES6, a non-object argument will be treated as if it was a sealed ordinary object, simply return true.
  6874. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
  6875. // The following provides ES6 behavior when a TypeError is thrown under ES5.
  6876. var isSealed;
  6877. try {
  6878. isSealed = Object.isSealed(obj);
  6879. } catch (err) {
  6880. if (err instanceof TypeError) isSealed = true;
  6881. else throw err;
  6882. }
  6883. this.assert(
  6884. isSealed
  6885. , 'expected #{this} to be sealed'
  6886. , 'expected #{this} to not be sealed'
  6887. );
  6888. });
  6889. /**
  6890. * ### .frozen
  6891. *
  6892. * Asserts that the target is frozen (cannot have new properties added to it
  6893. * and its existing properties cannot be modified).
  6894. *
  6895. * var frozenObject = Object.freeze({});
  6896. *
  6897. * expect(frozenObject).to.be.frozen;
  6898. * expect({}).to.not.be.frozen;
  6899. *
  6900. * @name frozen
  6901. * @namespace BDD
  6902. * @api public
  6903. */
  6904. Assertion.addProperty('frozen', function() {
  6905. var obj = flag(this, 'object');
  6906. // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
  6907. // In ES6, a non-object argument will be treated as if it was a frozen ordinary object, simply return true.
  6908. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
  6909. // The following provides ES6 behavior when a TypeError is thrown under ES5.
  6910. var isFrozen;
  6911. try {
  6912. isFrozen = Object.isFrozen(obj);
  6913. } catch (err) {
  6914. if (err instanceof TypeError) isFrozen = true;
  6915. else throw err;
  6916. }
  6917. this.assert(
  6918. isFrozen
  6919. , 'expected #{this} to be frozen'
  6920. , 'expected #{this} to not be frozen'
  6921. );
  6922. });
  6923. };
  6924. },{}],6:[function(require,module,exports){
  6925. /*!
  6926. * chai
  6927. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  6928. * MIT Licensed
  6929. */
  6930. module.exports = function (chai, util) {
  6931. /*!
  6932. * Chai dependencies.
  6933. */
  6934. var Assertion = chai.Assertion
  6935. , flag = util.flag;
  6936. /*!
  6937. * Module export.
  6938. */
  6939. /**
  6940. * ### assert(expression, message)
  6941. *
  6942. * Write your own test expressions.
  6943. *
  6944. * assert('foo' !== 'bar', 'foo is not bar');
  6945. * assert(Array.isArray([]), 'empty arrays are arrays');
  6946. *
  6947. * @param {Mixed} expression to test for truthiness
  6948. * @param {String} message to display on error
  6949. * @name assert
  6950. * @namespace Assert
  6951. * @api public
  6952. */
  6953. var assert = chai.assert = function (express, errmsg) {
  6954. var test = new Assertion(null, null, chai.assert);
  6955. test.assert(
  6956. express
  6957. , errmsg
  6958. , '[ negation message unavailable ]'
  6959. );
  6960. };
  6961. /**
  6962. * ### .fail(actual, expected, [message], [operator])
  6963. *
  6964. * Throw a failure. Node.js `assert` module-compatible.
  6965. *
  6966. * @name fail
  6967. * @param {Mixed} actual
  6968. * @param {Mixed} expected
  6969. * @param {String} message
  6970. * @param {String} operator
  6971. * @namespace Assert
  6972. * @api public
  6973. */
  6974. assert.fail = function (actual, expected, message, operator) {
  6975. message = message || 'assert.fail()';
  6976. throw new chai.AssertionError(message, {
  6977. actual: actual
  6978. , expected: expected
  6979. , operator: operator
  6980. }, assert.fail);
  6981. };
  6982. /**
  6983. * ### .isOk(object, [message])
  6984. *
  6985. * Asserts that `object` is truthy.
  6986. *
  6987. * assert.isOk('everything', 'everything is ok');
  6988. * assert.isOk(false, 'this will fail');
  6989. *
  6990. * @name isOk
  6991. * @alias ok
  6992. * @param {Mixed} object to test
  6993. * @param {String} message
  6994. * @namespace Assert
  6995. * @api public
  6996. */
  6997. assert.isOk = function (val, msg) {
  6998. new Assertion(val, msg).is.ok;
  6999. };
  7000. /**
  7001. * ### .isNotOk(object, [message])
  7002. *
  7003. * Asserts that `object` is falsy.
  7004. *
  7005. * assert.isNotOk('everything', 'this will fail');
  7006. * assert.isNotOk(false, 'this will pass');
  7007. *
  7008. * @name isNotOk
  7009. * @alias notOk
  7010. * @param {Mixed} object to test
  7011. * @param {String} message
  7012. * @namespace Assert
  7013. * @api public
  7014. */
  7015. assert.isNotOk = function (val, msg) {
  7016. new Assertion(val, msg).is.not.ok;
  7017. };
  7018. /**
  7019. * ### .equal(actual, expected, [message])
  7020. *
  7021. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  7022. *
  7023. * assert.equal(3, '3', '== coerces values to strings');
  7024. *
  7025. * @name equal
  7026. * @param {Mixed} actual
  7027. * @param {Mixed} expected
  7028. * @param {String} message
  7029. * @namespace Assert
  7030. * @api public
  7031. */
  7032. assert.equal = function (act, exp, msg) {
  7033. var test = new Assertion(act, msg, assert.equal);
  7034. test.assert(
  7035. exp == flag(test, 'object')
  7036. , 'expected #{this} to equal #{exp}'
  7037. , 'expected #{this} to not equal #{act}'
  7038. , exp
  7039. , act
  7040. );
  7041. };
  7042. /**
  7043. * ### .notEqual(actual, expected, [message])
  7044. *
  7045. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  7046. *
  7047. * assert.notEqual(3, 4, 'these numbers are not equal');
  7048. *
  7049. * @name notEqual
  7050. * @param {Mixed} actual
  7051. * @param {Mixed} expected
  7052. * @param {String} message
  7053. * @namespace Assert
  7054. * @api public
  7055. */
  7056. assert.notEqual = function (act, exp, msg) {
  7057. var test = new Assertion(act, msg, assert.notEqual);
  7058. test.assert(
  7059. exp != flag(test, 'object')
  7060. , 'expected #{this} to not equal #{exp}'
  7061. , 'expected #{this} to equal #{act}'
  7062. , exp
  7063. , act
  7064. );
  7065. };
  7066. /**
  7067. * ### .strictEqual(actual, expected, [message])
  7068. *
  7069. * Asserts strict equality (`===`) of `actual` and `expected`.
  7070. *
  7071. * assert.strictEqual(true, true, 'these booleans are strictly equal');
  7072. *
  7073. * @name strictEqual
  7074. * @param {Mixed} actual
  7075. * @param {Mixed} expected
  7076. * @param {String} message
  7077. * @namespace Assert
  7078. * @api public
  7079. */
  7080. assert.strictEqual = function (act, exp, msg) {
  7081. new Assertion(act, msg).to.equal(exp);
  7082. };
  7083. /**
  7084. * ### .notStrictEqual(actual, expected, [message])
  7085. *
  7086. * Asserts strict inequality (`!==`) of `actual` and `expected`.
  7087. *
  7088. * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
  7089. *
  7090. * @name notStrictEqual
  7091. * @param {Mixed} actual
  7092. * @param {Mixed} expected
  7093. * @param {String} message
  7094. * @namespace Assert
  7095. * @api public
  7096. */
  7097. assert.notStrictEqual = function (act, exp, msg) {
  7098. new Assertion(act, msg).to.not.equal(exp);
  7099. };
  7100. /**
  7101. * ### .deepEqual(actual, expected, [message])
  7102. *
  7103. * Asserts that `actual` is deeply equal to `expected`.
  7104. *
  7105. * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
  7106. *
  7107. * @name deepEqual
  7108. * @param {Mixed} actual
  7109. * @param {Mixed} expected
  7110. * @param {String} message
  7111. * @namespace Assert
  7112. * @api public
  7113. */
  7114. assert.deepEqual = function (act, exp, msg) {
  7115. new Assertion(act, msg).to.eql(exp);
  7116. };
  7117. /**
  7118. * ### .notDeepEqual(actual, expected, [message])
  7119. *
  7120. * Assert that `actual` is not deeply equal to `expected`.
  7121. *
  7122. * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
  7123. *
  7124. * @name notDeepEqual
  7125. * @param {Mixed} actual
  7126. * @param {Mixed} expected
  7127. * @param {String} message
  7128. * @namespace Assert
  7129. * @api public
  7130. */
  7131. assert.notDeepEqual = function (act, exp, msg) {
  7132. new Assertion(act, msg).to.not.eql(exp);
  7133. };
  7134. /**
  7135. * ### .isAbove(valueToCheck, valueToBeAbove, [message])
  7136. *
  7137. * Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`
  7138. *
  7139. * assert.isAbove(5, 2, '5 is strictly greater than 2');
  7140. *
  7141. * @name isAbove
  7142. * @param {Mixed} valueToCheck
  7143. * @param {Mixed} valueToBeAbove
  7144. * @param {String} message
  7145. * @namespace Assert
  7146. * @api public
  7147. */
  7148. assert.isAbove = function (val, abv, msg) {
  7149. new Assertion(val, msg).to.be.above(abv);
  7150. };
  7151. /**
  7152. * ### .isAtLeast(valueToCheck, valueToBeAtLeast, [message])
  7153. *
  7154. * Asserts `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`
  7155. *
  7156. * assert.isAtLeast(5, 2, '5 is greater or equal to 2');
  7157. * assert.isAtLeast(3, 3, '3 is greater or equal to 3');
  7158. *
  7159. * @name isAtLeast
  7160. * @param {Mixed} valueToCheck
  7161. * @param {Mixed} valueToBeAtLeast
  7162. * @param {String} message
  7163. * @namespace Assert
  7164. * @api public
  7165. */
  7166. assert.isAtLeast = function (val, atlst, msg) {
  7167. new Assertion(val, msg).to.be.least(atlst);
  7168. };
  7169. /**
  7170. * ### .isBelow(valueToCheck, valueToBeBelow, [message])
  7171. *
  7172. * Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`
  7173. *
  7174. * assert.isBelow(3, 6, '3 is strictly less than 6');
  7175. *
  7176. * @name isBelow
  7177. * @param {Mixed} valueToCheck
  7178. * @param {Mixed} valueToBeBelow
  7179. * @param {String} message
  7180. * @namespace Assert
  7181. * @api public
  7182. */
  7183. assert.isBelow = function (val, blw, msg) {
  7184. new Assertion(val, msg).to.be.below(blw);
  7185. };
  7186. /**
  7187. * ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
  7188. *
  7189. * Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`
  7190. *
  7191. * assert.isAtMost(3, 6, '3 is less than or equal to 6');
  7192. * assert.isAtMost(4, 4, '4 is less than or equal to 4');
  7193. *
  7194. * @name isAtMost
  7195. * @param {Mixed} valueToCheck
  7196. * @param {Mixed} valueToBeAtMost
  7197. * @param {String} message
  7198. * @namespace Assert
  7199. * @api public
  7200. */
  7201. assert.isAtMost = function (val, atmst, msg) {
  7202. new Assertion(val, msg).to.be.most(atmst);
  7203. };
  7204. /**
  7205. * ### .isTrue(value, [message])
  7206. *
  7207. * Asserts that `value` is true.
  7208. *
  7209. * var teaServed = true;
  7210. * assert.isTrue(teaServed, 'the tea has been served');
  7211. *
  7212. * @name isTrue
  7213. * @param {Mixed} value
  7214. * @param {String} message
  7215. * @namespace Assert
  7216. * @api public
  7217. */
  7218. assert.isTrue = function (val, msg) {
  7219. new Assertion(val, msg).is['true'];
  7220. };
  7221. /**
  7222. * ### .isNotTrue(value, [message])
  7223. *
  7224. * Asserts that `value` is not true.
  7225. *
  7226. * var tea = 'tasty chai';
  7227. * assert.isNotTrue(tea, 'great, time for tea!');
  7228. *
  7229. * @name isNotTrue
  7230. * @param {Mixed} value
  7231. * @param {String} message
  7232. * @namespace Assert
  7233. * @api public
  7234. */
  7235. assert.isNotTrue = function (val, msg) {
  7236. new Assertion(val, msg).to.not.equal(true);
  7237. };
  7238. /**
  7239. * ### .isFalse(value, [message])
  7240. *
  7241. * Asserts that `value` is false.
  7242. *
  7243. * var teaServed = false;
  7244. * assert.isFalse(teaServed, 'no tea yet? hmm...');
  7245. *
  7246. * @name isFalse
  7247. * @param {Mixed} value
  7248. * @param {String} message
  7249. * @namespace Assert
  7250. * @api public
  7251. */
  7252. assert.isFalse = function (val, msg) {
  7253. new Assertion(val, msg).is['false'];
  7254. };
  7255. /**
  7256. * ### .isNotFalse(value, [message])
  7257. *
  7258. * Asserts that `value` is not false.
  7259. *
  7260. * var tea = 'tasty chai';
  7261. * assert.isNotFalse(tea, 'great, time for tea!');
  7262. *
  7263. * @name isNotFalse
  7264. * @param {Mixed} value
  7265. * @param {String} message
  7266. * @namespace Assert
  7267. * @api public
  7268. */
  7269. assert.isNotFalse = function (val, msg) {
  7270. new Assertion(val, msg).to.not.equal(false);
  7271. };
  7272. /**
  7273. * ### .isNull(value, [message])
  7274. *
  7275. * Asserts that `value` is null.
  7276. *
  7277. * assert.isNull(err, 'there was no error');
  7278. *
  7279. * @name isNull
  7280. * @param {Mixed} value
  7281. * @param {String} message
  7282. * @namespace Assert
  7283. * @api public
  7284. */
  7285. assert.isNull = function (val, msg) {
  7286. new Assertion(val, msg).to.equal(null);
  7287. };
  7288. /**
  7289. * ### .isNotNull(value, [message])
  7290. *
  7291. * Asserts that `value` is not null.
  7292. *
  7293. * var tea = 'tasty chai';
  7294. * assert.isNotNull(tea, 'great, time for tea!');
  7295. *
  7296. * @name isNotNull
  7297. * @param {Mixed} value
  7298. * @param {String} message
  7299. * @namespace Assert
  7300. * @api public
  7301. */
  7302. assert.isNotNull = function (val, msg) {
  7303. new Assertion(val, msg).to.not.equal(null);
  7304. };
  7305. /**
  7306. * ### .isNaN
  7307. * Asserts that value is NaN
  7308. *
  7309. * assert.isNaN('foo', 'foo is NaN');
  7310. *
  7311. * @name isNaN
  7312. * @param {Mixed} value
  7313. * @param {String} message
  7314. * @namespace Assert
  7315. * @api public
  7316. */
  7317. assert.isNaN = function (val, msg) {
  7318. new Assertion(val, msg).to.be.NaN;
  7319. };
  7320. /**
  7321. * ### .isNotNaN
  7322. * Asserts that value is not NaN
  7323. *
  7324. * assert.isNotNaN(4, '4 is not NaN');
  7325. *
  7326. * @name isNotNaN
  7327. * @param {Mixed} value
  7328. * @param {String} message
  7329. * @namespace Assert
  7330. * @api public
  7331. */
  7332. assert.isNotNaN = function (val, msg) {
  7333. new Assertion(val, msg).not.to.be.NaN;
  7334. };
  7335. /**
  7336. * ### .isUndefined(value, [message])
  7337. *
  7338. * Asserts that `value` is `undefined`.
  7339. *
  7340. * var tea;
  7341. * assert.isUndefined(tea, 'no tea defined');
  7342. *
  7343. * @name isUndefined
  7344. * @param {Mixed} value
  7345. * @param {String} message
  7346. * @namespace Assert
  7347. * @api public
  7348. */
  7349. assert.isUndefined = function (val, msg) {
  7350. new Assertion(val, msg).to.equal(undefined);
  7351. };
  7352. /**
  7353. * ### .isDefined(value, [message])
  7354. *
  7355. * Asserts that `value` is not `undefined`.
  7356. *
  7357. * var tea = 'cup of chai';
  7358. * assert.isDefined(tea, 'tea has been defined');
  7359. *
  7360. * @name isDefined
  7361. * @param {Mixed} value
  7362. * @param {String} message
  7363. * @namespace Assert
  7364. * @api public
  7365. */
  7366. assert.isDefined = function (val, msg) {
  7367. new Assertion(val, msg).to.not.equal(undefined);
  7368. };
  7369. /**
  7370. * ### .isFunction(value, [message])
  7371. *
  7372. * Asserts that `value` is a function.
  7373. *
  7374. * function serveTea() { return 'cup of tea'; };
  7375. * assert.isFunction(serveTea, 'great, we can have tea now');
  7376. *
  7377. * @name isFunction
  7378. * @param {Mixed} value
  7379. * @param {String} message
  7380. * @namespace Assert
  7381. * @api public
  7382. */
  7383. assert.isFunction = function (val, msg) {
  7384. new Assertion(val, msg).to.be.a('function');
  7385. };
  7386. /**
  7387. * ### .isNotFunction(value, [message])
  7388. *
  7389. * Asserts that `value` is _not_ a function.
  7390. *
  7391. * var serveTea = [ 'heat', 'pour', 'sip' ];
  7392. * assert.isNotFunction(serveTea, 'great, we have listed the steps');
  7393. *
  7394. * @name isNotFunction
  7395. * @param {Mixed} value
  7396. * @param {String} message
  7397. * @namespace Assert
  7398. * @api public
  7399. */
  7400. assert.isNotFunction = function (val, msg) {
  7401. new Assertion(val, msg).to.not.be.a('function');
  7402. };
  7403. /**
  7404. * ### .isObject(value, [message])
  7405. *
  7406. * Asserts that `value` is an object of type 'Object' (as revealed by `Object.prototype.toString`).
  7407. * _The assertion does not match subclassed objects._
  7408. *
  7409. * var selection = { name: 'Chai', serve: 'with spices' };
  7410. * assert.isObject(selection, 'tea selection is an object');
  7411. *
  7412. * @name isObject
  7413. * @param {Mixed} value
  7414. * @param {String} message
  7415. * @namespace Assert
  7416. * @api public
  7417. */
  7418. assert.isObject = function (val, msg) {
  7419. new Assertion(val, msg).to.be.a('object');
  7420. };
  7421. /**
  7422. * ### .isNotObject(value, [message])
  7423. *
  7424. * Asserts that `value` is _not_ an object of type 'Object' (as revealed by `Object.prototype.toString`).
  7425. *
  7426. * var selection = 'chai'
  7427. * assert.isNotObject(selection, 'tea selection is not an object');
  7428. * assert.isNotObject(null, 'null is not an object');
  7429. *
  7430. * @name isNotObject
  7431. * @param {Mixed} value
  7432. * @param {String} message
  7433. * @namespace Assert
  7434. * @api public
  7435. */
  7436. assert.isNotObject = function (val, msg) {
  7437. new Assertion(val, msg).to.not.be.a('object');
  7438. };
  7439. /**
  7440. * ### .isArray(value, [message])
  7441. *
  7442. * Asserts that `value` is an array.
  7443. *
  7444. * var menu = [ 'green', 'chai', 'oolong' ];
  7445. * assert.isArray(menu, 'what kind of tea do we want?');
  7446. *
  7447. * @name isArray
  7448. * @param {Mixed} value
  7449. * @param {String} message
  7450. * @namespace Assert
  7451. * @api public
  7452. */
  7453. assert.isArray = function (val, msg) {
  7454. new Assertion(val, msg).to.be.an('array');
  7455. };
  7456. /**
  7457. * ### .isNotArray(value, [message])
  7458. *
  7459. * Asserts that `value` is _not_ an array.
  7460. *
  7461. * var menu = 'green|chai|oolong';
  7462. * assert.isNotArray(menu, 'what kind of tea do we want?');
  7463. *
  7464. * @name isNotArray
  7465. * @param {Mixed} value
  7466. * @param {String} message
  7467. * @namespace Assert
  7468. * @api public
  7469. */
  7470. assert.isNotArray = function (val, msg) {
  7471. new Assertion(val, msg).to.not.be.an('array');
  7472. };
  7473. /**
  7474. * ### .isString(value, [message])
  7475. *
  7476. * Asserts that `value` is a string.
  7477. *
  7478. * var teaOrder = 'chai';
  7479. * assert.isString(teaOrder, 'order placed');
  7480. *
  7481. * @name isString
  7482. * @param {Mixed} value
  7483. * @param {String} message
  7484. * @namespace Assert
  7485. * @api public
  7486. */
  7487. assert.isString = function (val, msg) {
  7488. new Assertion(val, msg).to.be.a('string');
  7489. };
  7490. /**
  7491. * ### .isNotString(value, [message])
  7492. *
  7493. * Asserts that `value` is _not_ a string.
  7494. *
  7495. * var teaOrder = 4;
  7496. * assert.isNotString(teaOrder, 'order placed');
  7497. *
  7498. * @name isNotString
  7499. * @param {Mixed} value
  7500. * @param {String} message
  7501. * @namespace Assert
  7502. * @api public
  7503. */
  7504. assert.isNotString = function (val, msg) {
  7505. new Assertion(val, msg).to.not.be.a('string');
  7506. };
  7507. /**
  7508. * ### .isNumber(value, [message])
  7509. *
  7510. * Asserts that `value` is a number.
  7511. *
  7512. * var cups = 2;
  7513. * assert.isNumber(cups, 'how many cups');
  7514. *
  7515. * @name isNumber
  7516. * @param {Number} value
  7517. * @param {String} message
  7518. * @namespace Assert
  7519. * @api public
  7520. */
  7521. assert.isNumber = function (val, msg) {
  7522. new Assertion(val, msg).to.be.a('number');
  7523. };
  7524. /**
  7525. * ### .isNotNumber(value, [message])
  7526. *
  7527. * Asserts that `value` is _not_ a number.
  7528. *
  7529. * var cups = '2 cups please';
  7530. * assert.isNotNumber(cups, 'how many cups');
  7531. *
  7532. * @name isNotNumber
  7533. * @param {Mixed} value
  7534. * @param {String} message
  7535. * @namespace Assert
  7536. * @api public
  7537. */
  7538. assert.isNotNumber = function (val, msg) {
  7539. new Assertion(val, msg).to.not.be.a('number');
  7540. };
  7541. /**
  7542. * ### .isBoolean(value, [message])
  7543. *
  7544. * Asserts that `value` is a boolean.
  7545. *
  7546. * var teaReady = true
  7547. * , teaServed = false;
  7548. *
  7549. * assert.isBoolean(teaReady, 'is the tea ready');
  7550. * assert.isBoolean(teaServed, 'has tea been served');
  7551. *
  7552. * @name isBoolean
  7553. * @param {Mixed} value
  7554. * @param {String} message
  7555. * @namespace Assert
  7556. * @api public
  7557. */
  7558. assert.isBoolean = function (val, msg) {
  7559. new Assertion(val, msg).to.be.a('boolean');
  7560. };
  7561. /**
  7562. * ### .isNotBoolean(value, [message])
  7563. *
  7564. * Asserts that `value` is _not_ a boolean.
  7565. *
  7566. * var teaReady = 'yep'
  7567. * , teaServed = 'nope';
  7568. *
  7569. * assert.isNotBoolean(teaReady, 'is the tea ready');
  7570. * assert.isNotBoolean(teaServed, 'has tea been served');
  7571. *
  7572. * @name isNotBoolean
  7573. * @param {Mixed} value
  7574. * @param {String} message
  7575. * @namespace Assert
  7576. * @api public
  7577. */
  7578. assert.isNotBoolean = function (val, msg) {
  7579. new Assertion(val, msg).to.not.be.a('boolean');
  7580. };
  7581. /**
  7582. * ### .typeOf(value, name, [message])
  7583. *
  7584. * Asserts that `value`'s type is `name`, as determined by
  7585. * `Object.prototype.toString`.
  7586. *
  7587. * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
  7588. * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
  7589. * assert.typeOf('tea', 'string', 'we have a string');
  7590. * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
  7591. * assert.typeOf(null, 'null', 'we have a null');
  7592. * assert.typeOf(undefined, 'undefined', 'we have an undefined');
  7593. *
  7594. * @name typeOf
  7595. * @param {Mixed} value
  7596. * @param {String} name
  7597. * @param {String} message
  7598. * @namespace Assert
  7599. * @api public
  7600. */
  7601. assert.typeOf = function (val, type, msg) {
  7602. new Assertion(val, msg).to.be.a(type);
  7603. };
  7604. /**
  7605. * ### .notTypeOf(value, name, [message])
  7606. *
  7607. * Asserts that `value`'s type is _not_ `name`, as determined by
  7608. * `Object.prototype.toString`.
  7609. *
  7610. * assert.notTypeOf('tea', 'number', 'strings are not numbers');
  7611. *
  7612. * @name notTypeOf
  7613. * @param {Mixed} value
  7614. * @param {String} typeof name
  7615. * @param {String} message
  7616. * @namespace Assert
  7617. * @api public
  7618. */
  7619. assert.notTypeOf = function (val, type, msg) {
  7620. new Assertion(val, msg).to.not.be.a(type);
  7621. };
  7622. /**
  7623. * ### .instanceOf(object, constructor, [message])
  7624. *
  7625. * Asserts that `value` is an instance of `constructor`.
  7626. *
  7627. * var Tea = function (name) { this.name = name; }
  7628. * , chai = new Tea('chai');
  7629. *
  7630. * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
  7631. *
  7632. * @name instanceOf
  7633. * @param {Object} object
  7634. * @param {Constructor} constructor
  7635. * @param {String} message
  7636. * @namespace Assert
  7637. * @api public
  7638. */
  7639. assert.instanceOf = function (val, type, msg) {
  7640. new Assertion(val, msg).to.be.instanceOf(type);
  7641. };
  7642. /**
  7643. * ### .notInstanceOf(object, constructor, [message])
  7644. *
  7645. * Asserts `value` is not an instance of `constructor`.
  7646. *
  7647. * var Tea = function (name) { this.name = name; }
  7648. * , chai = new String('chai');
  7649. *
  7650. * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
  7651. *
  7652. * @name notInstanceOf
  7653. * @param {Object} object
  7654. * @param {Constructor} constructor
  7655. * @param {String} message
  7656. * @namespace Assert
  7657. * @api public
  7658. */
  7659. assert.notInstanceOf = function (val, type, msg) {
  7660. new Assertion(val, msg).to.not.be.instanceOf(type);
  7661. };
  7662. /**
  7663. * ### .include(haystack, needle, [message])
  7664. *
  7665. * Asserts that `haystack` includes `needle`. Works
  7666. * for strings and arrays.
  7667. *
  7668. * assert.include('foobar', 'bar', 'foobar contains string "bar"');
  7669. * assert.include([ 1, 2, 3 ], 3, 'array contains value');
  7670. *
  7671. * @name include
  7672. * @param {Array|String} haystack
  7673. * @param {Mixed} needle
  7674. * @param {String} message
  7675. * @namespace Assert
  7676. * @api public
  7677. */
  7678. assert.include = function (exp, inc, msg) {
  7679. new Assertion(exp, msg, assert.include).include(inc);
  7680. };
  7681. /**
  7682. * ### .notInclude(haystack, needle, [message])
  7683. *
  7684. * Asserts that `haystack` does not include `needle`. Works
  7685. * for strings and arrays.
  7686. *
  7687. * assert.notInclude('foobar', 'baz', 'string not include substring');
  7688. * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
  7689. *
  7690. * @name notInclude
  7691. * @param {Array|String} haystack
  7692. * @param {Mixed} needle
  7693. * @param {String} message
  7694. * @namespace Assert
  7695. * @api public
  7696. */
  7697. assert.notInclude = function (exp, inc, msg) {
  7698. new Assertion(exp, msg, assert.notInclude).not.include(inc);
  7699. };
  7700. /**
  7701. * ### .match(value, regexp, [message])
  7702. *
  7703. * Asserts that `value` matches the regular expression `regexp`.
  7704. *
  7705. * assert.match('foobar', /^foo/, 'regexp matches');
  7706. *
  7707. * @name match
  7708. * @param {Mixed} value
  7709. * @param {RegExp} regexp
  7710. * @param {String} message
  7711. * @namespace Assert
  7712. * @api public
  7713. */
  7714. assert.match = function (exp, re, msg) {
  7715. new Assertion(exp, msg).to.match(re);
  7716. };
  7717. /**
  7718. * ### .notMatch(value, regexp, [message])
  7719. *
  7720. * Asserts that `value` does not match the regular expression `regexp`.
  7721. *
  7722. * assert.notMatch('foobar', /^foo/, 'regexp does not match');
  7723. *
  7724. * @name notMatch
  7725. * @param {Mixed} value
  7726. * @param {RegExp} regexp
  7727. * @param {String} message
  7728. * @namespace Assert
  7729. * @api public
  7730. */
  7731. assert.notMatch = function (exp, re, msg) {
  7732. new Assertion(exp, msg).to.not.match(re);
  7733. };
  7734. /**
  7735. * ### .property(object, property, [message])
  7736. *
  7737. * Asserts that `object` has a property named by `property`.
  7738. *
  7739. * assert.property({ tea: { green: 'matcha' }}, 'tea');
  7740. *
  7741. * @name property
  7742. * @param {Object} object
  7743. * @param {String} property
  7744. * @param {String} message
  7745. * @namespace Assert
  7746. * @api public
  7747. */
  7748. assert.property = function (obj, prop, msg) {
  7749. new Assertion(obj, msg).to.have.property(prop);
  7750. };
  7751. /**
  7752. * ### .notProperty(object, property, [message])
  7753. *
  7754. * Asserts that `object` does _not_ have a property named by `property`.
  7755. *
  7756. * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
  7757. *
  7758. * @name notProperty
  7759. * @param {Object} object
  7760. * @param {String} property
  7761. * @param {String} message
  7762. * @namespace Assert
  7763. * @api public
  7764. */
  7765. assert.notProperty = function (obj, prop, msg) {
  7766. new Assertion(obj, msg).to.not.have.property(prop);
  7767. };
  7768. /**
  7769. * ### .deepProperty(object, property, [message])
  7770. *
  7771. * Asserts that `object` has a property named by `property`, which can be a
  7772. * string using dot- and bracket-notation for deep reference.
  7773. *
  7774. * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
  7775. *
  7776. * @name deepProperty
  7777. * @param {Object} object
  7778. * @param {String} property
  7779. * @param {String} message
  7780. * @namespace Assert
  7781. * @api public
  7782. */
  7783. assert.deepProperty = function (obj, prop, msg) {
  7784. new Assertion(obj, msg).to.have.deep.property(prop);
  7785. };
  7786. /**
  7787. * ### .notDeepProperty(object, property, [message])
  7788. *
  7789. * Asserts that `object` does _not_ have a property named by `property`, which
  7790. * can be a string using dot- and bracket-notation for deep reference.
  7791. *
  7792. * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
  7793. *
  7794. * @name notDeepProperty
  7795. * @param {Object} object
  7796. * @param {String} property
  7797. * @param {String} message
  7798. * @namespace Assert
  7799. * @api public
  7800. */
  7801. assert.notDeepProperty = function (obj, prop, msg) {
  7802. new Assertion(obj, msg).to.not.have.deep.property(prop);
  7803. };
  7804. /**
  7805. * ### .propertyVal(object, property, value, [message])
  7806. *
  7807. * Asserts that `object` has a property named by `property` with value given
  7808. * by `value`.
  7809. *
  7810. * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
  7811. *
  7812. * @name propertyVal
  7813. * @param {Object} object
  7814. * @param {String} property
  7815. * @param {Mixed} value
  7816. * @param {String} message
  7817. * @namespace Assert
  7818. * @api public
  7819. */
  7820. assert.propertyVal = function (obj, prop, val, msg) {
  7821. new Assertion(obj, msg).to.have.property(prop, val);
  7822. };
  7823. /**
  7824. * ### .propertyNotVal(object, property, value, [message])
  7825. *
  7826. * Asserts that `object` has a property named by `property`, but with a value
  7827. * different from that given by `value`.
  7828. *
  7829. * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
  7830. *
  7831. * @name propertyNotVal
  7832. * @param {Object} object
  7833. * @param {String} property
  7834. * @param {Mixed} value
  7835. * @param {String} message
  7836. * @namespace Assert
  7837. * @api public
  7838. */
  7839. assert.propertyNotVal = function (obj, prop, val, msg) {
  7840. new Assertion(obj, msg).to.not.have.property(prop, val);
  7841. };
  7842. /**
  7843. * ### .deepPropertyVal(object, property, value, [message])
  7844. *
  7845. * Asserts that `object` has a property named by `property` with value given
  7846. * by `value`. `property` can use dot- and bracket-notation for deep
  7847. * reference.
  7848. *
  7849. * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
  7850. *
  7851. * @name deepPropertyVal
  7852. * @param {Object} object
  7853. * @param {String} property
  7854. * @param {Mixed} value
  7855. * @param {String} message
  7856. * @namespace Assert
  7857. * @api public
  7858. */
  7859. assert.deepPropertyVal = function (obj, prop, val, msg) {
  7860. new Assertion(obj, msg).to.have.deep.property(prop, val);
  7861. };
  7862. /**
  7863. * ### .deepPropertyNotVal(object, property, value, [message])
  7864. *
  7865. * Asserts that `object` has a property named by `property`, but with a value
  7866. * different from that given by `value`. `property` can use dot- and
  7867. * bracket-notation for deep reference.
  7868. *
  7869. * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
  7870. *
  7871. * @name deepPropertyNotVal
  7872. * @param {Object} object
  7873. * @param {String} property
  7874. * @param {Mixed} value
  7875. * @param {String} message
  7876. * @namespace Assert
  7877. * @api public
  7878. */
  7879. assert.deepPropertyNotVal = function (obj, prop, val, msg) {
  7880. new Assertion(obj, msg).to.not.have.deep.property(prop, val);
  7881. };
  7882. /**
  7883. * ### .lengthOf(object, length, [message])
  7884. *
  7885. * Asserts that `object` has a `length` property with the expected value.
  7886. *
  7887. * assert.lengthOf([1,2,3], 3, 'array has length of 3');
  7888. * assert.lengthOf('foobar', 6, 'string has length of 6');
  7889. *
  7890. * @name lengthOf
  7891. * @param {Mixed} object
  7892. * @param {Number} length
  7893. * @param {String} message
  7894. * @namespace Assert
  7895. * @api public
  7896. */
  7897. assert.lengthOf = function (exp, len, msg) {
  7898. new Assertion(exp, msg).to.have.length(len);
  7899. };
  7900. /**
  7901. * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
  7902. *
  7903. * Asserts that `function` will throw an error that is an instance of
  7904. * `constructor`, or alternately that it will throw an error with message
  7905. * matching `regexp`.
  7906. *
  7907. * assert.throws(fn, 'function throws a reference error');
  7908. * assert.throws(fn, /function throws a reference error/);
  7909. * assert.throws(fn, ReferenceError);
  7910. * assert.throws(fn, ReferenceError, 'function throws a reference error');
  7911. * assert.throws(fn, ReferenceError, /function throws a reference error/);
  7912. *
  7913. * @name throws
  7914. * @alias throw
  7915. * @alias Throw
  7916. * @param {Function} function
  7917. * @param {ErrorConstructor} constructor
  7918. * @param {RegExp} regexp
  7919. * @param {String} message
  7920. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  7921. * @namespace Assert
  7922. * @api public
  7923. */
  7924. assert.throws = function (fn, errt, errs, msg) {
  7925. if ('string' === typeof errt || errt instanceof RegExp) {
  7926. errs = errt;
  7927. errt = null;
  7928. }
  7929. var assertErr = new Assertion(fn, msg).to.throw(errt, errs);
  7930. return flag(assertErr, 'object');
  7931. };
  7932. /**
  7933. * ### .doesNotThrow(function, [constructor/regexp], [message])
  7934. *
  7935. * Asserts that `function` will _not_ throw an error that is an instance of
  7936. * `constructor`, or alternately that it will not throw an error with message
  7937. * matching `regexp`.
  7938. *
  7939. * assert.doesNotThrow(fn, Error, 'function does not throw');
  7940. *
  7941. * @name doesNotThrow
  7942. * @param {Function} function
  7943. * @param {ErrorConstructor} constructor
  7944. * @param {RegExp} regexp
  7945. * @param {String} message
  7946. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  7947. * @namespace Assert
  7948. * @api public
  7949. */
  7950. assert.doesNotThrow = function (fn, type, msg) {
  7951. if ('string' === typeof type) {
  7952. msg = type;
  7953. type = null;
  7954. }
  7955. new Assertion(fn, msg).to.not.Throw(type);
  7956. };
  7957. /**
  7958. * ### .operator(val1, operator, val2, [message])
  7959. *
  7960. * Compares two values using `operator`.
  7961. *
  7962. * assert.operator(1, '<', 2, 'everything is ok');
  7963. * assert.operator(1, '>', 2, 'this will fail');
  7964. *
  7965. * @name operator
  7966. * @param {Mixed} val1
  7967. * @param {String} operator
  7968. * @param {Mixed} val2
  7969. * @param {String} message
  7970. * @namespace Assert
  7971. * @api public
  7972. */
  7973. assert.operator = function (val, operator, val2, msg) {
  7974. var ok;
  7975. switch(operator) {
  7976. case '==':
  7977. ok = val == val2;
  7978. break;
  7979. case '===':
  7980. ok = val === val2;
  7981. break;
  7982. case '>':
  7983. ok = val > val2;
  7984. break;
  7985. case '>=':
  7986. ok = val >= val2;
  7987. break;
  7988. case '<':
  7989. ok = val < val2;
  7990. break;
  7991. case '<=':
  7992. ok = val <= val2;
  7993. break;
  7994. case '!=':
  7995. ok = val != val2;
  7996. break;
  7997. case '!==':
  7998. ok = val !== val2;
  7999. break;
  8000. default:
  8001. throw new Error('Invalid operator "' + operator + '"');
  8002. }
  8003. var test = new Assertion(ok, msg);
  8004. test.assert(
  8005. true === flag(test, 'object')
  8006. , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
  8007. , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
  8008. };
  8009. /**
  8010. * ### .closeTo(actual, expected, delta, [message])
  8011. *
  8012. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  8013. *
  8014. * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
  8015. *
  8016. * @name closeTo
  8017. * @param {Number} actual
  8018. * @param {Number} expected
  8019. * @param {Number} delta
  8020. * @param {String} message
  8021. * @namespace Assert
  8022. * @api public
  8023. */
  8024. assert.closeTo = function (act, exp, delta, msg) {
  8025. new Assertion(act, msg).to.be.closeTo(exp, delta);
  8026. };
  8027. /**
  8028. * ### .approximately(actual, expected, delta, [message])
  8029. *
  8030. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  8031. *
  8032. * assert.approximately(1.5, 1, 0.5, 'numbers are close');
  8033. *
  8034. * @name approximately
  8035. * @param {Number} actual
  8036. * @param {Number} expected
  8037. * @param {Number} delta
  8038. * @param {String} message
  8039. * @namespace Assert
  8040. * @api public
  8041. */
  8042. assert.approximately = function (act, exp, delta, msg) {
  8043. new Assertion(act, msg).to.be.approximately(exp, delta);
  8044. };
  8045. /**
  8046. * ### .sameMembers(set1, set2, [message])
  8047. *
  8048. * Asserts that `set1` and `set2` have the same members.
  8049. * Order is not taken into account.
  8050. *
  8051. * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
  8052. *
  8053. * @name sameMembers
  8054. * @param {Array} set1
  8055. * @param {Array} set2
  8056. * @param {String} message
  8057. * @namespace Assert
  8058. * @api public
  8059. */
  8060. assert.sameMembers = function (set1, set2, msg) {
  8061. new Assertion(set1, msg).to.have.same.members(set2);
  8062. }
  8063. /**
  8064. * ### .sameDeepMembers(set1, set2, [message])
  8065. *
  8066. * Asserts that `set1` and `set2` have the same members - using a deep equality checking.
  8067. * Order is not taken into account.
  8068. *
  8069. * assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members');
  8070. *
  8071. * @name sameDeepMembers
  8072. * @param {Array} set1
  8073. * @param {Array} set2
  8074. * @param {String} message
  8075. * @namespace Assert
  8076. * @api public
  8077. */
  8078. assert.sameDeepMembers = function (set1, set2, msg) {
  8079. new Assertion(set1, msg).to.have.same.deep.members(set2);
  8080. }
  8081. /**
  8082. * ### .includeMembers(superset, subset, [message])
  8083. *
  8084. * Asserts that `subset` is included in `superset`.
  8085. * Order is not taken into account.
  8086. *
  8087. * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
  8088. *
  8089. * @name includeMembers
  8090. * @param {Array} superset
  8091. * @param {Array} subset
  8092. * @param {String} message
  8093. * @namespace Assert
  8094. * @api public
  8095. */
  8096. assert.includeMembers = function (superset, subset, msg) {
  8097. new Assertion(superset, msg).to.include.members(subset);
  8098. }
  8099. /**
  8100. * ### .includeDeepMembers(superset, subset, [message])
  8101. *
  8102. * Asserts that `subset` is included in `superset` - using deep equality checking.
  8103. * Order is not taken into account.
  8104. * Duplicates are ignored.
  8105. *
  8106. * assert.includeDeepMembers([ {a: 1}, {b: 2}, {c: 3} ], [ {b: 2}, {a: 1}, {b: 2} ], 'include deep members');
  8107. *
  8108. * @name includeDeepMembers
  8109. * @param {Array} superset
  8110. * @param {Array} subset
  8111. * @param {String} message
  8112. * @namespace Assert
  8113. * @api public
  8114. */
  8115. assert.includeDeepMembers = function (superset, subset, msg) {
  8116. new Assertion(superset, msg).to.include.deep.members(subset);
  8117. }
  8118. /**
  8119. * ### .oneOf(inList, list, [message])
  8120. *
  8121. * Asserts that non-object, non-array value `inList` appears in the flat array `list`.
  8122. *
  8123. * assert.oneOf(1, [ 2, 1 ], 'Not found in list');
  8124. *
  8125. * @name oneOf
  8126. * @param {*} inList
  8127. * @param {Array<*>} list
  8128. * @param {String} message
  8129. * @namespace Assert
  8130. * @api public
  8131. */
  8132. assert.oneOf = function (inList, list, msg) {
  8133. new Assertion(inList, msg).to.be.oneOf(list);
  8134. }
  8135. /**
  8136. * ### .changes(function, object, property)
  8137. *
  8138. * Asserts that a function changes the value of a property
  8139. *
  8140. * var obj = { val: 10 };
  8141. * var fn = function() { obj.val = 22 };
  8142. * assert.changes(fn, obj, 'val');
  8143. *
  8144. * @name changes
  8145. * @param {Function} modifier function
  8146. * @param {Object} object
  8147. * @param {String} property name
  8148. * @param {String} message _optional_
  8149. * @namespace Assert
  8150. * @api public
  8151. */
  8152. assert.changes = function (fn, obj, prop) {
  8153. new Assertion(fn).to.change(obj, prop);
  8154. }
  8155. /**
  8156. * ### .doesNotChange(function, object, property)
  8157. *
  8158. * Asserts that a function does not changes the value of a property
  8159. *
  8160. * var obj = { val: 10 };
  8161. * var fn = function() { console.log('foo'); };
  8162. * assert.doesNotChange(fn, obj, 'val');
  8163. *
  8164. * @name doesNotChange
  8165. * @param {Function} modifier function
  8166. * @param {Object} object
  8167. * @param {String} property name
  8168. * @param {String} message _optional_
  8169. * @namespace Assert
  8170. * @api public
  8171. */
  8172. assert.doesNotChange = function (fn, obj, prop) {
  8173. new Assertion(fn).to.not.change(obj, prop);
  8174. }
  8175. /**
  8176. * ### .increases(function, object, property)
  8177. *
  8178. * Asserts that a function increases an object property
  8179. *
  8180. * var obj = { val: 10 };
  8181. * var fn = function() { obj.val = 13 };
  8182. * assert.increases(fn, obj, 'val');
  8183. *
  8184. * @name increases
  8185. * @param {Function} modifier function
  8186. * @param {Object} object
  8187. * @param {String} property name
  8188. * @param {String} message _optional_
  8189. * @namespace Assert
  8190. * @api public
  8191. */
  8192. assert.increases = function (fn, obj, prop) {
  8193. new Assertion(fn).to.increase(obj, prop);
  8194. }
  8195. /**
  8196. * ### .doesNotIncrease(function, object, property)
  8197. *
  8198. * Asserts that a function does not increase object property
  8199. *
  8200. * var obj = { val: 10 };
  8201. * var fn = function() { obj.val = 8 };
  8202. * assert.doesNotIncrease(fn, obj, 'val');
  8203. *
  8204. * @name doesNotIncrease
  8205. * @param {Function} modifier function
  8206. * @param {Object} object
  8207. * @param {String} property name
  8208. * @param {String} message _optional_
  8209. * @namespace Assert
  8210. * @api public
  8211. */
  8212. assert.doesNotIncrease = function (fn, obj, prop) {
  8213. new Assertion(fn).to.not.increase(obj, prop);
  8214. }
  8215. /**
  8216. * ### .decreases(function, object, property)
  8217. *
  8218. * Asserts that a function decreases an object property
  8219. *
  8220. * var obj = { val: 10 };
  8221. * var fn = function() { obj.val = 5 };
  8222. * assert.decreases(fn, obj, 'val');
  8223. *
  8224. * @name decreases
  8225. * @param {Function} modifier function
  8226. * @param {Object} object
  8227. * @param {String} property name
  8228. * @param {String} message _optional_
  8229. * @namespace Assert
  8230. * @api public
  8231. */
  8232. assert.decreases = function (fn, obj, prop) {
  8233. new Assertion(fn).to.decrease(obj, prop);
  8234. }
  8235. /**
  8236. * ### .doesNotDecrease(function, object, property)
  8237. *
  8238. * Asserts that a function does not decreases an object property
  8239. *
  8240. * var obj = { val: 10 };
  8241. * var fn = function() { obj.val = 15 };
  8242. * assert.doesNotDecrease(fn, obj, 'val');
  8243. *
  8244. * @name doesNotDecrease
  8245. * @param {Function} modifier function
  8246. * @param {Object} object
  8247. * @param {String} property name
  8248. * @param {String} message _optional_
  8249. * @namespace Assert
  8250. * @api public
  8251. */
  8252. assert.doesNotDecrease = function (fn, obj, prop) {
  8253. new Assertion(fn).to.not.decrease(obj, prop);
  8254. }
  8255. /*!
  8256. * ### .ifError(object)
  8257. *
  8258. * Asserts if value is not a false value, and throws if it is a true value.
  8259. * This is added to allow for chai to be a drop-in replacement for Node's
  8260. * assert class.
  8261. *
  8262. * var err = new Error('I am a custom error');
  8263. * assert.ifError(err); // Rethrows err!
  8264. *
  8265. * @name ifError
  8266. * @param {Object} object
  8267. * @namespace Assert
  8268. * @api public
  8269. */
  8270. assert.ifError = function (val) {
  8271. if (val) {
  8272. throw(val);
  8273. }
  8274. };
  8275. /**
  8276. * ### .isExtensible(object)
  8277. *
  8278. * Asserts that `object` is extensible (can have new properties added to it).
  8279. *
  8280. * assert.isExtensible({});
  8281. *
  8282. * @name isExtensible
  8283. * @alias extensible
  8284. * @param {Object} object
  8285. * @param {String} message _optional_
  8286. * @namespace Assert
  8287. * @api public
  8288. */
  8289. assert.isExtensible = function (obj, msg) {
  8290. new Assertion(obj, msg).to.be.extensible;
  8291. };
  8292. /**
  8293. * ### .isNotExtensible(object)
  8294. *
  8295. * Asserts that `object` is _not_ extensible.
  8296. *
  8297. * var nonExtensibleObject = Object.preventExtensions({});
  8298. * var sealedObject = Object.seal({});
  8299. * var frozenObject = Object.freese({});
  8300. *
  8301. * assert.isNotExtensible(nonExtensibleObject);
  8302. * assert.isNotExtensible(sealedObject);
  8303. * assert.isNotExtensible(frozenObject);
  8304. *
  8305. * @name isNotExtensible
  8306. * @alias notExtensible
  8307. * @param {Object} object
  8308. * @param {String} message _optional_
  8309. * @namespace Assert
  8310. * @api public
  8311. */
  8312. assert.isNotExtensible = function (obj, msg) {
  8313. new Assertion(obj, msg).to.not.be.extensible;
  8314. };
  8315. /**
  8316. * ### .isSealed(object)
  8317. *
  8318. * Asserts that `object` is sealed (cannot have new properties added to it
  8319. * and its existing properties cannot be removed).
  8320. *
  8321. * var sealedObject = Object.seal({});
  8322. * var frozenObject = Object.seal({});
  8323. *
  8324. * assert.isSealed(sealedObject);
  8325. * assert.isSealed(frozenObject);
  8326. *
  8327. * @name isSealed
  8328. * @alias sealed
  8329. * @param {Object} object
  8330. * @param {String} message _optional_
  8331. * @namespace Assert
  8332. * @api public
  8333. */
  8334. assert.isSealed = function (obj, msg) {
  8335. new Assertion(obj, msg).to.be.sealed;
  8336. };
  8337. /**
  8338. * ### .isNotSealed(object)
  8339. *
  8340. * Asserts that `object` is _not_ sealed.
  8341. *
  8342. * assert.isNotSealed({});
  8343. *
  8344. * @name isNotSealed
  8345. * @alias notSealed
  8346. * @param {Object} object
  8347. * @param {String} message _optional_
  8348. * @namespace Assert
  8349. * @api public
  8350. */
  8351. assert.isNotSealed = function (obj, msg) {
  8352. new Assertion(obj, msg).to.not.be.sealed;
  8353. };
  8354. /**
  8355. * ### .isFrozen(object)
  8356. *
  8357. * Asserts that `object` is frozen (cannot have new properties added to it
  8358. * and its existing properties cannot be modified).
  8359. *
  8360. * var frozenObject = Object.freeze({});
  8361. * assert.frozen(frozenObject);
  8362. *
  8363. * @name isFrozen
  8364. * @alias frozen
  8365. * @param {Object} object
  8366. * @param {String} message _optional_
  8367. * @namespace Assert
  8368. * @api public
  8369. */
  8370. assert.isFrozen = function (obj, msg) {
  8371. new Assertion(obj, msg).to.be.frozen;
  8372. };
  8373. /**
  8374. * ### .isNotFrozen(object)
  8375. *
  8376. * Asserts that `object` is _not_ frozen.
  8377. *
  8378. * assert.isNotFrozen({});
  8379. *
  8380. * @name isNotFrozen
  8381. * @alias notFrozen
  8382. * @param {Object} object
  8383. * @param {String} message _optional_
  8384. * @namespace Assert
  8385. * @api public
  8386. */
  8387. assert.isNotFrozen = function (obj, msg) {
  8388. new Assertion(obj, msg).to.not.be.frozen;
  8389. };
  8390. /*!
  8391. * Aliases.
  8392. */
  8393. (function alias(name, as){
  8394. assert[as] = assert[name];
  8395. return alias;
  8396. })
  8397. ('isOk', 'ok')
  8398. ('isNotOk', 'notOk')
  8399. ('throws', 'throw')
  8400. ('throws', 'Throw')
  8401. ('isExtensible', 'extensible')
  8402. ('isNotExtensible', 'notExtensible')
  8403. ('isSealed', 'sealed')
  8404. ('isNotSealed', 'notSealed')
  8405. ('isFrozen', 'frozen')
  8406. ('isNotFrozen', 'notFrozen');
  8407. };
  8408. },{}],7:[function(require,module,exports){
  8409. /*!
  8410. * chai
  8411. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  8412. * MIT Licensed
  8413. */
  8414. module.exports = function (chai, util) {
  8415. chai.expect = function (val, message) {
  8416. return new chai.Assertion(val, message);
  8417. };
  8418. /**
  8419. * ### .fail(actual, expected, [message], [operator])
  8420. *
  8421. * Throw a failure.
  8422. *
  8423. * @name fail
  8424. * @param {Mixed} actual
  8425. * @param {Mixed} expected
  8426. * @param {String} message
  8427. * @param {String} operator
  8428. * @namespace Expect
  8429. * @api public
  8430. */
  8431. chai.expect.fail = function (actual, expected, message, operator) {
  8432. message = message || 'expect.fail()';
  8433. throw new chai.AssertionError(message, {
  8434. actual: actual
  8435. , expected: expected
  8436. , operator: operator
  8437. }, chai.expect.fail);
  8438. };
  8439. };
  8440. },{}],8:[function(require,module,exports){
  8441. /*!
  8442. * chai
  8443. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  8444. * MIT Licensed
  8445. */
  8446. module.exports = function (chai, util) {
  8447. var Assertion = chai.Assertion;
  8448. function loadShould () {
  8449. // explicitly define this method as function as to have it's name to include as `ssfi`
  8450. function shouldGetter() {
  8451. if (this instanceof String || this instanceof Number || this instanceof Boolean ) {
  8452. return new Assertion(this.valueOf(), null, shouldGetter);
  8453. }
  8454. return new Assertion(this, null, shouldGetter);
  8455. }
  8456. function shouldSetter(value) {
  8457. // See https://github.com/chaijs/chai/issues/86: this makes
  8458. // `whatever.should = someValue` actually set `someValue`, which is
  8459. // especially useful for `global.should = require('chai').should()`.
  8460. //
  8461. // Note that we have to use [[DefineProperty]] instead of [[Put]]
  8462. // since otherwise we would trigger this very setter!
  8463. Object.defineProperty(this, 'should', {
  8464. value: value,
  8465. enumerable: true,
  8466. configurable: true,
  8467. writable: true
  8468. });
  8469. }
  8470. // modify Object.prototype to have `should`
  8471. Object.defineProperty(Object.prototype, 'should', {
  8472. set: shouldSetter
  8473. , get: shouldGetter
  8474. , configurable: true
  8475. });
  8476. var should = {};
  8477. /**
  8478. * ### .fail(actual, expected, [message], [operator])
  8479. *
  8480. * Throw a failure.
  8481. *
  8482. * @name fail
  8483. * @param {Mixed} actual
  8484. * @param {Mixed} expected
  8485. * @param {String} message
  8486. * @param {String} operator
  8487. * @namespace Should
  8488. * @api public
  8489. */
  8490. should.fail = function (actual, expected, message, operator) {
  8491. message = message || 'should.fail()';
  8492. throw new chai.AssertionError(message, {
  8493. actual: actual
  8494. , expected: expected
  8495. , operator: operator
  8496. }, should.fail);
  8497. };
  8498. /**
  8499. * ### .equal(actual, expected, [message])
  8500. *
  8501. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  8502. *
  8503. * should.equal(3, '3', '== coerces values to strings');
  8504. *
  8505. * @name equal
  8506. * @param {Mixed} actual
  8507. * @param {Mixed} expected
  8508. * @param {String} message
  8509. * @namespace Should
  8510. * @api public
  8511. */
  8512. should.equal = function (val1, val2, msg) {
  8513. new Assertion(val1, msg).to.equal(val2);
  8514. };
  8515. /**
  8516. * ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
  8517. *
  8518. * Asserts that `function` will throw an error that is an instance of
  8519. * `constructor`, or alternately that it will throw an error with message
  8520. * matching `regexp`.
  8521. *
  8522. * should.throw(fn, 'function throws a reference error');
  8523. * should.throw(fn, /function throws a reference error/);
  8524. * should.throw(fn, ReferenceError);
  8525. * should.throw(fn, ReferenceError, 'function throws a reference error');
  8526. * should.throw(fn, ReferenceError, /function throws a reference error/);
  8527. *
  8528. * @name throw
  8529. * @alias Throw
  8530. * @param {Function} function
  8531. * @param {ErrorConstructor} constructor
  8532. * @param {RegExp} regexp
  8533. * @param {String} message
  8534. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  8535. * @namespace Should
  8536. * @api public
  8537. */
  8538. should.Throw = function (fn, errt, errs, msg) {
  8539. new Assertion(fn, msg).to.Throw(errt, errs);
  8540. };
  8541. /**
  8542. * ### .exist
  8543. *
  8544. * Asserts that the target is neither `null` nor `undefined`.
  8545. *
  8546. * var foo = 'hi';
  8547. *
  8548. * should.exist(foo, 'foo exists');
  8549. *
  8550. * @name exist
  8551. * @namespace Should
  8552. * @api public
  8553. */
  8554. should.exist = function (val, msg) {
  8555. new Assertion(val, msg).to.exist;
  8556. }
  8557. // negation
  8558. should.not = {}
  8559. /**
  8560. * ### .not.equal(actual, expected, [message])
  8561. *
  8562. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  8563. *
  8564. * should.not.equal(3, 4, 'these numbers are not equal');
  8565. *
  8566. * @name not.equal
  8567. * @param {Mixed} actual
  8568. * @param {Mixed} expected
  8569. * @param {String} message
  8570. * @namespace Should
  8571. * @api public
  8572. */
  8573. should.not.equal = function (val1, val2, msg) {
  8574. new Assertion(val1, msg).to.not.equal(val2);
  8575. };
  8576. /**
  8577. * ### .throw(function, [constructor/regexp], [message])
  8578. *
  8579. * Asserts that `function` will _not_ throw an error that is an instance of
  8580. * `constructor`, or alternately that it will not throw an error with message
  8581. * matching `regexp`.
  8582. *
  8583. * should.not.throw(fn, Error, 'function does not throw');
  8584. *
  8585. * @name not.throw
  8586. * @alias not.Throw
  8587. * @param {Function} function
  8588. * @param {ErrorConstructor} constructor
  8589. * @param {RegExp} regexp
  8590. * @param {String} message
  8591. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  8592. * @namespace Should
  8593. * @api public
  8594. */
  8595. should.not.Throw = function (fn, errt, errs, msg) {
  8596. new Assertion(fn, msg).to.not.Throw(errt, errs);
  8597. };
  8598. /**
  8599. * ### .not.exist
  8600. *
  8601. * Asserts that the target is neither `null` nor `undefined`.
  8602. *
  8603. * var bar = null;
  8604. *
  8605. * should.not.exist(bar, 'bar does not exist');
  8606. *
  8607. * @name not.exist
  8608. * @namespace Should
  8609. * @api public
  8610. */
  8611. should.not.exist = function (val, msg) {
  8612. new Assertion(val, msg).to.not.exist;
  8613. }
  8614. should['throw'] = should['Throw'];
  8615. should.not['throw'] = should.not['Throw'];
  8616. return should;
  8617. };
  8618. chai.should = loadShould;
  8619. chai.Should = loadShould;
  8620. };
  8621. },{}],9:[function(require,module,exports){
  8622. /*!
  8623. * Chai - addChainingMethod utility
  8624. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8625. * MIT Licensed
  8626. */
  8627. /*!
  8628. * Module dependencies
  8629. */
  8630. var transferFlags = require('./transferFlags');
  8631. var flag = require('./flag');
  8632. var config = require('../config');
  8633. /*!
  8634. * Module variables
  8635. */
  8636. // Check whether `__proto__` is supported
  8637. var hasProtoSupport = '__proto__' in Object;
  8638. // Without `__proto__` support, this module will need to add properties to a function.
  8639. // However, some Function.prototype methods cannot be overwritten,
  8640. // and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
  8641. var excludeNames = /^(?:length|name|arguments|caller)$/;
  8642. // Cache `Function` properties
  8643. var call = Function.prototype.call,
  8644. apply = Function.prototype.apply;
  8645. /**
  8646. * ### addChainableMethod (ctx, name, method, chainingBehavior)
  8647. *
  8648. * Adds a method to an object, such that the method can also be chained.
  8649. *
  8650. * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
  8651. * var obj = utils.flag(this, 'object');
  8652. * new chai.Assertion(obj).to.be.equal(str);
  8653. * });
  8654. *
  8655. * Can also be accessed directly from `chai.Assertion`.
  8656. *
  8657. * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
  8658. *
  8659. * The result can then be used as both a method assertion, executing both `method` and
  8660. * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
  8661. *
  8662. * expect(fooStr).to.be.foo('bar');
  8663. * expect(fooStr).to.be.foo.equal('foo');
  8664. *
  8665. * @param {Object} ctx object to which the method is added
  8666. * @param {String} name of method to add
  8667. * @param {Function} method function to be used for `name`, when called
  8668. * @param {Function} chainingBehavior function to be called every time the property is accessed
  8669. * @namespace Utils
  8670. * @name addChainableMethod
  8671. * @api public
  8672. */
  8673. module.exports = function (ctx, name, method, chainingBehavior) {
  8674. if (typeof chainingBehavior !== 'function') {
  8675. chainingBehavior = function () { };
  8676. }
  8677. var chainableBehavior = {
  8678. method: method
  8679. , chainingBehavior: chainingBehavior
  8680. };
  8681. // save the methods so we can overwrite them later, if we need to.
  8682. if (!ctx.__methods) {
  8683. ctx.__methods = {};
  8684. }
  8685. ctx.__methods[name] = chainableBehavior;
  8686. Object.defineProperty(ctx, name,
  8687. { get: function () {
  8688. chainableBehavior.chainingBehavior.call(this);
  8689. var assert = function assert() {
  8690. var old_ssfi = flag(this, 'ssfi');
  8691. if (old_ssfi && config.includeStack === false)
  8692. flag(this, 'ssfi', assert);
  8693. var result = chainableBehavior.method.apply(this, arguments);
  8694. return result === undefined ? this : result;
  8695. };
  8696. // Use `__proto__` if available
  8697. if (hasProtoSupport) {
  8698. // Inherit all properties from the object by replacing the `Function` prototype
  8699. var prototype = assert.__proto__ = Object.create(this);
  8700. // Restore the `call` and `apply` methods from `Function`
  8701. prototype.call = call;
  8702. prototype.apply = apply;
  8703. }
  8704. // Otherwise, redefine all properties (slow!)
  8705. else {
  8706. var asserterNames = Object.getOwnPropertyNames(ctx);
  8707. asserterNames.forEach(function (asserterName) {
  8708. if (!excludeNames.test(asserterName)) {
  8709. var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
  8710. Object.defineProperty(assert, asserterName, pd);
  8711. }
  8712. });
  8713. }
  8714. transferFlags(this, assert);
  8715. return assert;
  8716. }
  8717. , configurable: true
  8718. });
  8719. };
  8720. },{"../config":4,"./flag":13,"./transferFlags":29}],10:[function(require,module,exports){
  8721. /*!
  8722. * Chai - addMethod utility
  8723. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8724. * MIT Licensed
  8725. */
  8726. var config = require('../config');
  8727. /**
  8728. * ### .addMethod (ctx, name, method)
  8729. *
  8730. * Adds a method to the prototype of an object.
  8731. *
  8732. * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
  8733. * var obj = utils.flag(this, 'object');
  8734. * new chai.Assertion(obj).to.be.equal(str);
  8735. * });
  8736. *
  8737. * Can also be accessed directly from `chai.Assertion`.
  8738. *
  8739. * chai.Assertion.addMethod('foo', fn);
  8740. *
  8741. * Then can be used as any other assertion.
  8742. *
  8743. * expect(fooStr).to.be.foo('bar');
  8744. *
  8745. * @param {Object} ctx object to which the method is added
  8746. * @param {String} name of method to add
  8747. * @param {Function} method function to be used for name
  8748. * @namespace Utils
  8749. * @name addMethod
  8750. * @api public
  8751. */
  8752. var flag = require('./flag');
  8753. module.exports = function (ctx, name, method) {
  8754. ctx[name] = function () {
  8755. var old_ssfi = flag(this, 'ssfi');
  8756. if (old_ssfi && config.includeStack === false)
  8757. flag(this, 'ssfi', ctx[name]);
  8758. var result = method.apply(this, arguments);
  8759. return result === undefined ? this : result;
  8760. };
  8761. };
  8762. },{"../config":4,"./flag":13}],11:[function(require,module,exports){
  8763. /*!
  8764. * Chai - addProperty utility
  8765. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8766. * MIT Licensed
  8767. */
  8768. var config = require('../config');
  8769. var flag = require('./flag');
  8770. /**
  8771. * ### addProperty (ctx, name, getter)
  8772. *
  8773. * Adds a property to the prototype of an object.
  8774. *
  8775. * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
  8776. * var obj = utils.flag(this, 'object');
  8777. * new chai.Assertion(obj).to.be.instanceof(Foo);
  8778. * });
  8779. *
  8780. * Can also be accessed directly from `chai.Assertion`.
  8781. *
  8782. * chai.Assertion.addProperty('foo', fn);
  8783. *
  8784. * Then can be used as any other assertion.
  8785. *
  8786. * expect(myFoo).to.be.foo;
  8787. *
  8788. * @param {Object} ctx object to which the property is added
  8789. * @param {String} name of property to add
  8790. * @param {Function} getter function to be used for name
  8791. * @namespace Utils
  8792. * @name addProperty
  8793. * @api public
  8794. */
  8795. module.exports = function (ctx, name, getter) {
  8796. Object.defineProperty(ctx, name,
  8797. { get: function addProperty() {
  8798. var old_ssfi = flag(this, 'ssfi');
  8799. if (old_ssfi && config.includeStack === false)
  8800. flag(this, 'ssfi', addProperty);
  8801. var result = getter.call(this);
  8802. return result === undefined ? this : result;
  8803. }
  8804. , configurable: true
  8805. });
  8806. };
  8807. },{"../config":4,"./flag":13}],12:[function(require,module,exports){
  8808. /*!
  8809. * Chai - expectTypes utility
  8810. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8811. * MIT Licensed
  8812. */
  8813. /**
  8814. * ### expectTypes(obj, types)
  8815. *
  8816. * Ensures that the object being tested against is of a valid type.
  8817. *
  8818. * utils.expectTypes(this, ['array', 'object', 'string']);
  8819. *
  8820. * @param {Mixed} obj constructed Assertion
  8821. * @param {Array} type A list of allowed types for this assertion
  8822. * @namespace Utils
  8823. * @name expectTypes
  8824. * @api public
  8825. */
  8826. var AssertionError = require('assertion-error');
  8827. var flag = require('./flag');
  8828. var type = require('type-detect');
  8829. module.exports = function (obj, types) {
  8830. var obj = flag(obj, 'object');
  8831. types = types.map(function (t) { return t.toLowerCase(); });
  8832. types.sort();
  8833. // Transforms ['lorem', 'ipsum'] into 'a lirum, or an ipsum'
  8834. var str = types.map(function (t, index) {
  8835. var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a';
  8836. var or = types.length > 1 && index === types.length - 1 ? 'or ' : '';
  8837. return or + art + ' ' + t;
  8838. }).join(', ');
  8839. if (!types.some(function (expected) { return type(obj) === expected; })) {
  8840. throw new AssertionError(
  8841. 'object tested must be ' + str + ', but ' + type(obj) + ' given'
  8842. );
  8843. }
  8844. };
  8845. },{"./flag":13,"assertion-error":30,"type-detect":35}],13:[function(require,module,exports){
  8846. /*!
  8847. * Chai - flag utility
  8848. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8849. * MIT Licensed
  8850. */
  8851. /**
  8852. * ### flag(object, key, [value])
  8853. *
  8854. * Get or set a flag value on an object. If a
  8855. * value is provided it will be set, else it will
  8856. * return the currently set value or `undefined` if
  8857. * the value is not set.
  8858. *
  8859. * utils.flag(this, 'foo', 'bar'); // setter
  8860. * utils.flag(this, 'foo'); // getter, returns `bar`
  8861. *
  8862. * @param {Object} object constructed Assertion
  8863. * @param {String} key
  8864. * @param {Mixed} value (optional)
  8865. * @namespace Utils
  8866. * @name flag
  8867. * @api private
  8868. */
  8869. module.exports = function (obj, key, value) {
  8870. var flags = obj.__flags || (obj.__flags = Object.create(null));
  8871. if (arguments.length === 3) {
  8872. flags[key] = value;
  8873. } else {
  8874. return flags[key];
  8875. }
  8876. };
  8877. },{}],14:[function(require,module,exports){
  8878. /*!
  8879. * Chai - getActual utility
  8880. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8881. * MIT Licensed
  8882. */
  8883. /**
  8884. * # getActual(object, [actual])
  8885. *
  8886. * Returns the `actual` value for an Assertion
  8887. *
  8888. * @param {Object} object (constructed Assertion)
  8889. * @param {Arguments} chai.Assertion.prototype.assert arguments
  8890. * @namespace Utils
  8891. * @name getActual
  8892. */
  8893. module.exports = function (obj, args) {
  8894. return args.length > 4 ? args[4] : obj._obj;
  8895. };
  8896. },{}],15:[function(require,module,exports){
  8897. /*!
  8898. * Chai - getEnumerableProperties utility
  8899. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8900. * MIT Licensed
  8901. */
  8902. /**
  8903. * ### .getEnumerableProperties(object)
  8904. *
  8905. * This allows the retrieval of enumerable property names of an object,
  8906. * inherited or not.
  8907. *
  8908. * @param {Object} object
  8909. * @returns {Array}
  8910. * @namespace Utils
  8911. * @name getEnumerableProperties
  8912. * @api public
  8913. */
  8914. module.exports = function getEnumerableProperties(object) {
  8915. var result = [];
  8916. for (var name in object) {
  8917. result.push(name);
  8918. }
  8919. return result;
  8920. };
  8921. },{}],16:[function(require,module,exports){
  8922. /*!
  8923. * Chai - message composition utility
  8924. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8925. * MIT Licensed
  8926. */
  8927. /*!
  8928. * Module dependancies
  8929. */
  8930. var flag = require('./flag')
  8931. , getActual = require('./getActual')
  8932. , inspect = require('./inspect')
  8933. , objDisplay = require('./objDisplay');
  8934. /**
  8935. * ### .getMessage(object, message, negateMessage)
  8936. *
  8937. * Construct the error message based on flags
  8938. * and template tags. Template tags will return
  8939. * a stringified inspection of the object referenced.
  8940. *
  8941. * Message template tags:
  8942. * - `#{this}` current asserted object
  8943. * - `#{act}` actual value
  8944. * - `#{exp}` expected value
  8945. *
  8946. * @param {Object} object (constructed Assertion)
  8947. * @param {Arguments} chai.Assertion.prototype.assert arguments
  8948. * @namespace Utils
  8949. * @name getMessage
  8950. * @api public
  8951. */
  8952. module.exports = function (obj, args) {
  8953. var negate = flag(obj, 'negate')
  8954. , val = flag(obj, 'object')
  8955. , expected = args[3]
  8956. , actual = getActual(obj, args)
  8957. , msg = negate ? args[2] : args[1]
  8958. , flagMsg = flag(obj, 'message');
  8959. if(typeof msg === "function") msg = msg();
  8960. msg = msg || '';
  8961. msg = msg
  8962. .replace(/#\{this\}/g, function () { return objDisplay(val); })
  8963. .replace(/#\{act\}/g, function () { return objDisplay(actual); })
  8964. .replace(/#\{exp\}/g, function () { return objDisplay(expected); });
  8965. return flagMsg ? flagMsg + ': ' + msg : msg;
  8966. };
  8967. },{"./flag":13,"./getActual":14,"./inspect":23,"./objDisplay":24}],17:[function(require,module,exports){
  8968. /*!
  8969. * Chai - getName utility
  8970. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8971. * MIT Licensed
  8972. */
  8973. /**
  8974. * # getName(func)
  8975. *
  8976. * Gets the name of a function, in a cross-browser way.
  8977. *
  8978. * @param {Function} a function (usually a constructor)
  8979. * @namespace Utils
  8980. * @name getName
  8981. */
  8982. module.exports = function (func) {
  8983. if (func.name) return func.name;
  8984. var match = /^\s?function ([^(]*)\(/.exec(func);
  8985. return match && match[1] ? match[1] : "";
  8986. };
  8987. },{}],18:[function(require,module,exports){
  8988. /*!
  8989. * Chai - getPathInfo utility
  8990. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8991. * MIT Licensed
  8992. */
  8993. var hasProperty = require('./hasProperty');
  8994. /**
  8995. * ### .getPathInfo(path, object)
  8996. *
  8997. * This allows the retrieval of property info in an
  8998. * object given a string path.
  8999. *
  9000. * The path info consists of an object with the
  9001. * following properties:
  9002. *
  9003. * * parent - The parent object of the property referenced by `path`
  9004. * * name - The name of the final property, a number if it was an array indexer
  9005. * * value - The value of the property, if it exists, otherwise `undefined`
  9006. * * exists - Whether the property exists or not
  9007. *
  9008. * @param {String} path
  9009. * @param {Object} object
  9010. * @returns {Object} info
  9011. * @namespace Utils
  9012. * @name getPathInfo
  9013. * @api public
  9014. */
  9015. module.exports = function getPathInfo(path, obj) {
  9016. var parsed = parsePath(path),
  9017. last = parsed[parsed.length - 1];
  9018. var info = {
  9019. parent: parsed.length > 1 ? _getPathValue(parsed, obj, parsed.length - 1) : obj,
  9020. name: last.p || last.i,
  9021. value: _getPathValue(parsed, obj)
  9022. };
  9023. info.exists = hasProperty(info.name, info.parent);
  9024. return info;
  9025. };
  9026. /*!
  9027. * ## parsePath(path)
  9028. *
  9029. * Helper function used to parse string object
  9030. * paths. Use in conjunction with `_getPathValue`.
  9031. *
  9032. * var parsed = parsePath('myobject.property.subprop');
  9033. *
  9034. * ### Paths:
  9035. *
  9036. * * Can be as near infinitely deep and nested
  9037. * * Arrays are also valid using the formal `myobject.document[3].property`.
  9038. * * Literal dots and brackets (not delimiter) must be backslash-escaped.
  9039. *
  9040. * @param {String} path
  9041. * @returns {Object} parsed
  9042. * @api private
  9043. */
  9044. function parsePath (path) {
  9045. var str = path.replace(/([^\\])\[/g, '$1.[')
  9046. , parts = str.match(/(\\\.|[^.]+?)+/g);
  9047. return parts.map(function (value) {
  9048. var re = /^\[(\d+)\]$/
  9049. , mArr = re.exec(value);
  9050. if (mArr) return { i: parseFloat(mArr[1]) };
  9051. else return { p: value.replace(/\\([.\[\]])/g, '$1') };
  9052. });
  9053. }
  9054. /*!
  9055. * ## _getPathValue(parsed, obj)
  9056. *
  9057. * Helper companion function for `.parsePath` that returns
  9058. * the value located at the parsed address.
  9059. *
  9060. * var value = getPathValue(parsed, obj);
  9061. *
  9062. * @param {Object} parsed definition from `parsePath`.
  9063. * @param {Object} object to search against
  9064. * @param {Number} object to search against
  9065. * @returns {Object|Undefined} value
  9066. * @api private
  9067. */
  9068. function _getPathValue (parsed, obj, index) {
  9069. var tmp = obj
  9070. , res;
  9071. index = (index === undefined ? parsed.length : index);
  9072. for (var i = 0, l = index; i < l; i++) {
  9073. var part = parsed[i];
  9074. if (tmp) {
  9075. if ('undefined' !== typeof part.p)
  9076. tmp = tmp[part.p];
  9077. else if ('undefined' !== typeof part.i)
  9078. tmp = tmp[part.i];
  9079. if (i == (l - 1)) res = tmp;
  9080. } else {
  9081. res = undefined;
  9082. }
  9083. }
  9084. return res;
  9085. }
  9086. },{"./hasProperty":21}],19:[function(require,module,exports){
  9087. /*!
  9088. * Chai - getPathValue utility
  9089. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9090. * @see https://github.com/logicalparadox/filtr
  9091. * MIT Licensed
  9092. */
  9093. var getPathInfo = require('./getPathInfo');
  9094. /**
  9095. * ### .getPathValue(path, object)
  9096. *
  9097. * This allows the retrieval of values in an
  9098. * object given a string path.
  9099. *
  9100. * var obj = {
  9101. * prop1: {
  9102. * arr: ['a', 'b', 'c']
  9103. * , str: 'Hello'
  9104. * }
  9105. * , prop2: {
  9106. * arr: [ { nested: 'Universe' } ]
  9107. * , str: 'Hello again!'
  9108. * }
  9109. * }
  9110. *
  9111. * The following would be the results.
  9112. *
  9113. * getPathValue('prop1.str', obj); // Hello
  9114. * getPathValue('prop1.att[2]', obj); // b
  9115. * getPathValue('prop2.arr[0].nested', obj); // Universe
  9116. *
  9117. * @param {String} path
  9118. * @param {Object} object
  9119. * @returns {Object} value or `undefined`
  9120. * @namespace Utils
  9121. * @name getPathValue
  9122. * @api public
  9123. */
  9124. module.exports = function(path, obj) {
  9125. var info = getPathInfo(path, obj);
  9126. return info.value;
  9127. };
  9128. },{"./getPathInfo":18}],20:[function(require,module,exports){
  9129. /*!
  9130. * Chai - getProperties utility
  9131. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9132. * MIT Licensed
  9133. */
  9134. /**
  9135. * ### .getProperties(object)
  9136. *
  9137. * This allows the retrieval of property names of an object, enumerable or not,
  9138. * inherited or not.
  9139. *
  9140. * @param {Object} object
  9141. * @returns {Array}
  9142. * @namespace Utils
  9143. * @name getProperties
  9144. * @api public
  9145. */
  9146. module.exports = function getProperties(object) {
  9147. var result = Object.getOwnPropertyNames(object);
  9148. function addProperty(property) {
  9149. if (result.indexOf(property) === -1) {
  9150. result.push(property);
  9151. }
  9152. }
  9153. var proto = Object.getPrototypeOf(object);
  9154. while (proto !== null) {
  9155. Object.getOwnPropertyNames(proto).forEach(addProperty);
  9156. proto = Object.getPrototypeOf(proto);
  9157. }
  9158. return result;
  9159. };
  9160. },{}],21:[function(require,module,exports){
  9161. /*!
  9162. * Chai - hasProperty utility
  9163. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9164. * MIT Licensed
  9165. */
  9166. var type = require('type-detect');
  9167. /**
  9168. * ### .hasProperty(object, name)
  9169. *
  9170. * This allows checking whether an object has
  9171. * named property or numeric array index.
  9172. *
  9173. * Basically does the same thing as the `in`
  9174. * operator but works properly with natives
  9175. * and null/undefined values.
  9176. *
  9177. * var obj = {
  9178. * arr: ['a', 'b', 'c']
  9179. * , str: 'Hello'
  9180. * }
  9181. *
  9182. * The following would be the results.
  9183. *
  9184. * hasProperty('str', obj); // true
  9185. * hasProperty('constructor', obj); // true
  9186. * hasProperty('bar', obj); // false
  9187. *
  9188. * hasProperty('length', obj.str); // true
  9189. * hasProperty(1, obj.str); // true
  9190. * hasProperty(5, obj.str); // false
  9191. *
  9192. * hasProperty('length', obj.arr); // true
  9193. * hasProperty(2, obj.arr); // true
  9194. * hasProperty(3, obj.arr); // false
  9195. *
  9196. * @param {Objuect} object
  9197. * @param {String|Number} name
  9198. * @returns {Boolean} whether it exists
  9199. * @namespace Utils
  9200. * @name getPathInfo
  9201. * @api public
  9202. */
  9203. var literals = {
  9204. 'number': Number
  9205. , 'string': String
  9206. };
  9207. module.exports = function hasProperty(name, obj) {
  9208. var ot = type(obj);
  9209. // Bad Object, obviously no props at all
  9210. if(ot === 'null' || ot === 'undefined')
  9211. return false;
  9212. // The `in` operator does not work with certain literals
  9213. // box these before the check
  9214. if(literals[ot] && typeof obj !== 'object')
  9215. obj = new literals[ot](obj);
  9216. return name in obj;
  9217. };
  9218. },{"type-detect":35}],22:[function(require,module,exports){
  9219. /*!
  9220. * chai
  9221. * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
  9222. * MIT Licensed
  9223. */
  9224. /*!
  9225. * Main exports
  9226. */
  9227. var exports = module.exports = {};
  9228. /*!
  9229. * test utility
  9230. */
  9231. exports.test = require('./test');
  9232. /*!
  9233. * type utility
  9234. */
  9235. exports.type = require('type-detect');
  9236. /*!
  9237. * expectTypes utility
  9238. */
  9239. exports.expectTypes = require('./expectTypes');
  9240. /*!
  9241. * message utility
  9242. */
  9243. exports.getMessage = require('./getMessage');
  9244. /*!
  9245. * actual utility
  9246. */
  9247. exports.getActual = require('./getActual');
  9248. /*!
  9249. * Inspect util
  9250. */
  9251. exports.inspect = require('./inspect');
  9252. /*!
  9253. * Object Display util
  9254. */
  9255. exports.objDisplay = require('./objDisplay');
  9256. /*!
  9257. * Flag utility
  9258. */
  9259. exports.flag = require('./flag');
  9260. /*!
  9261. * Flag transferring utility
  9262. */
  9263. exports.transferFlags = require('./transferFlags');
  9264. /*!
  9265. * Deep equal utility
  9266. */
  9267. exports.eql = require('deep-eql');
  9268. /*!
  9269. * Deep path value
  9270. */
  9271. exports.getPathValue = require('./getPathValue');
  9272. /*!
  9273. * Deep path info
  9274. */
  9275. exports.getPathInfo = require('./getPathInfo');
  9276. /*!
  9277. * Check if a property exists
  9278. */
  9279. exports.hasProperty = require('./hasProperty');
  9280. /*!
  9281. * Function name
  9282. */
  9283. exports.getName = require('./getName');
  9284. /*!
  9285. * add Property
  9286. */
  9287. exports.addProperty = require('./addProperty');
  9288. /*!
  9289. * add Method
  9290. */
  9291. exports.addMethod = require('./addMethod');
  9292. /*!
  9293. * overwrite Property
  9294. */
  9295. exports.overwriteProperty = require('./overwriteProperty');
  9296. /*!
  9297. * overwrite Method
  9298. */
  9299. exports.overwriteMethod = require('./overwriteMethod');
  9300. /*!
  9301. * Add a chainable method
  9302. */
  9303. exports.addChainableMethod = require('./addChainableMethod');
  9304. /*!
  9305. * Overwrite chainable method
  9306. */
  9307. exports.overwriteChainableMethod = require('./overwriteChainableMethod');
  9308. },{"./addChainableMethod":9,"./addMethod":10,"./addProperty":11,"./expectTypes":12,"./flag":13,"./getActual":14,"./getMessage":16,"./getName":17,"./getPathInfo":18,"./getPathValue":19,"./hasProperty":21,"./inspect":23,"./objDisplay":24,"./overwriteChainableMethod":25,"./overwriteMethod":26,"./overwriteProperty":27,"./test":28,"./transferFlags":29,"deep-eql":31,"type-detect":35}],23:[function(require,module,exports){
  9309. // This is (almost) directly from Node.js utils
  9310. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
  9311. var getName = require('./getName');
  9312. var getProperties = require('./getProperties');
  9313. var getEnumerableProperties = require('./getEnumerableProperties');
  9314. module.exports = inspect;
  9315. /**
  9316. * Echos the value of a value. Trys to print the value out
  9317. * in the best way possible given the different types.
  9318. *
  9319. * @param {Object} obj The object to print out.
  9320. * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
  9321. * properties of objects.
  9322. * @param {Number} depth Depth in which to descend in object. Default is 2.
  9323. * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
  9324. * output. Default is false (no coloring).
  9325. * @namespace Utils
  9326. * @name inspect
  9327. */
  9328. function inspect(obj, showHidden, depth, colors) {
  9329. var ctx = {
  9330. showHidden: showHidden,
  9331. seen: [],
  9332. stylize: function (str) { return str; }
  9333. };
  9334. return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
  9335. }
  9336. // Returns true if object is a DOM element.
  9337. var isDOMElement = function (object) {
  9338. if (typeof HTMLElement === 'object') {
  9339. return object instanceof HTMLElement;
  9340. } else {
  9341. return object &&
  9342. typeof object === 'object' &&
  9343. object.nodeType === 1 &&
  9344. typeof object.nodeName === 'string';
  9345. }
  9346. };
  9347. function formatValue(ctx, value, recurseTimes) {
  9348. // Provide a hook for user-specified inspect functions.
  9349. // Check that value is an object with an inspect function on it
  9350. if (value && typeof value.inspect === 'function' &&
  9351. // Filter out the util module, it's inspect function is special
  9352. value.inspect !== exports.inspect &&
  9353. // Also filter out any prototype objects using the circular check.
  9354. !(value.constructor && value.constructor.prototype === value)) {
  9355. var ret = value.inspect(recurseTimes);
  9356. if (typeof ret !== 'string') {
  9357. ret = formatValue(ctx, ret, recurseTimes);
  9358. }
  9359. return ret;
  9360. }
  9361. // Primitive types cannot have properties
  9362. var primitive = formatPrimitive(ctx, value);
  9363. if (primitive) {
  9364. return primitive;
  9365. }
  9366. // If this is a DOM element, try to get the outer HTML.
  9367. if (isDOMElement(value)) {
  9368. if ('outerHTML' in value) {
  9369. return value.outerHTML;
  9370. // This value does not have an outerHTML attribute,
  9371. // it could still be an XML element
  9372. } else {
  9373. // Attempt to serialize it
  9374. try {
  9375. if (document.xmlVersion) {
  9376. var xmlSerializer = new XMLSerializer();
  9377. return xmlSerializer.serializeToString(value);
  9378. } else {
  9379. // Firefox 11- do not support outerHTML
  9380. // It does, however, support innerHTML
  9381. // Use the following to render the element
  9382. var ns = "http://www.w3.org/1999/xhtml";
  9383. var container = document.createElementNS(ns, '_');
  9384. container.appendChild(value.cloneNode(false));
  9385. html = container.innerHTML
  9386. .replace('><', '>' + value.innerHTML + '<');
  9387. container.innerHTML = '';
  9388. return html;
  9389. }
  9390. } catch (err) {
  9391. // This could be a non-native DOM implementation,
  9392. // continue with the normal flow:
  9393. // printing the element as if it is an object.
  9394. }
  9395. }
  9396. }
  9397. // Look up the keys of the object.
  9398. var visibleKeys = getEnumerableProperties(value);
  9399. var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
  9400. // Some type of object without properties can be shortcutted.
  9401. // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
  9402. // a `stack` plus `description` property; ignore those for consistency.
  9403. if (keys.length === 0 || (isError(value) && (
  9404. (keys.length === 1 && keys[0] === 'stack') ||
  9405. (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
  9406. ))) {
  9407. if (typeof value === 'function') {
  9408. var name = getName(value);
  9409. var nameSuffix = name ? ': ' + name : '';
  9410. return ctx.stylize('[Function' + nameSuffix + ']', 'special');
  9411. }
  9412. if (isRegExp(value)) {
  9413. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  9414. }
  9415. if (isDate(value)) {
  9416. return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
  9417. }
  9418. if (isError(value)) {
  9419. return formatError(value);
  9420. }
  9421. }
  9422. var base = '', array = false, braces = ['{', '}'];
  9423. // Make Array say that they are Array
  9424. if (isArray(value)) {
  9425. array = true;
  9426. braces = ['[', ']'];
  9427. }
  9428. // Make functions say that they are functions
  9429. if (typeof value === 'function') {
  9430. var name = getName(value);
  9431. var nameSuffix = name ? ': ' + name : '';
  9432. base = ' [Function' + nameSuffix + ']';
  9433. }
  9434. // Make RegExps say that they are RegExps
  9435. if (isRegExp(value)) {
  9436. base = ' ' + RegExp.prototype.toString.call(value);
  9437. }
  9438. // Make dates with properties first say the date
  9439. if (isDate(value)) {
  9440. base = ' ' + Date.prototype.toUTCString.call(value);
  9441. }
  9442. // Make error with message first say the error
  9443. if (isError(value)) {
  9444. return formatError(value);
  9445. }
  9446. if (keys.length === 0 && (!array || value.length == 0)) {
  9447. return braces[0] + base + braces[1];
  9448. }
  9449. if (recurseTimes < 0) {
  9450. if (isRegExp(value)) {
  9451. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  9452. } else {
  9453. return ctx.stylize('[Object]', 'special');
  9454. }
  9455. }
  9456. ctx.seen.push(value);
  9457. var output;
  9458. if (array) {
  9459. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  9460. } else {
  9461. output = keys.map(function(key) {
  9462. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  9463. });
  9464. }
  9465. ctx.seen.pop();
  9466. return reduceToSingleString(output, base, braces);
  9467. }
  9468. function formatPrimitive(ctx, value) {
  9469. switch (typeof value) {
  9470. case 'undefined':
  9471. return ctx.stylize('undefined', 'undefined');
  9472. case 'string':
  9473. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  9474. .replace(/'/g, "\\'")
  9475. .replace(/\\"/g, '"') + '\'';
  9476. return ctx.stylize(simple, 'string');
  9477. case 'number':
  9478. if (value === 0 && (1/value) === -Infinity) {
  9479. return ctx.stylize('-0', 'number');
  9480. }
  9481. return ctx.stylize('' + value, 'number');
  9482. case 'boolean':
  9483. return ctx.stylize('' + value, 'boolean');
  9484. }
  9485. // For some reason typeof null is "object", so special case here.
  9486. if (value === null) {
  9487. return ctx.stylize('null', 'null');
  9488. }
  9489. }
  9490. function formatError(value) {
  9491. return '[' + Error.prototype.toString.call(value) + ']';
  9492. }
  9493. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  9494. var output = [];
  9495. for (var i = 0, l = value.length; i < l; ++i) {
  9496. if (Object.prototype.hasOwnProperty.call(value, String(i))) {
  9497. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  9498. String(i), true));
  9499. } else {
  9500. output.push('');
  9501. }
  9502. }
  9503. keys.forEach(function(key) {
  9504. if (!key.match(/^\d+$/)) {
  9505. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  9506. key, true));
  9507. }
  9508. });
  9509. return output;
  9510. }
  9511. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  9512. var name, str;
  9513. if (value.__lookupGetter__) {
  9514. if (value.__lookupGetter__(key)) {
  9515. if (value.__lookupSetter__(key)) {
  9516. str = ctx.stylize('[Getter/Setter]', 'special');
  9517. } else {
  9518. str = ctx.stylize('[Getter]', 'special');
  9519. }
  9520. } else {
  9521. if (value.__lookupSetter__(key)) {
  9522. str = ctx.stylize('[Setter]', 'special');
  9523. }
  9524. }
  9525. }
  9526. if (visibleKeys.indexOf(key) < 0) {
  9527. name = '[' + key + ']';
  9528. }
  9529. if (!str) {
  9530. if (ctx.seen.indexOf(value[key]) < 0) {
  9531. if (recurseTimes === null) {
  9532. str = formatValue(ctx, value[key], null);
  9533. } else {
  9534. str = formatValue(ctx, value[key], recurseTimes - 1);
  9535. }
  9536. if (str.indexOf('\n') > -1) {
  9537. if (array) {
  9538. str = str.split('\n').map(function(line) {
  9539. return ' ' + line;
  9540. }).join('\n').substr(2);
  9541. } else {
  9542. str = '\n' + str.split('\n').map(function(line) {
  9543. return ' ' + line;
  9544. }).join('\n');
  9545. }
  9546. }
  9547. } else {
  9548. str = ctx.stylize('[Circular]', 'special');
  9549. }
  9550. }
  9551. if (typeof name === 'undefined') {
  9552. if (array && key.match(/^\d+$/)) {
  9553. return str;
  9554. }
  9555. name = JSON.stringify('' + key);
  9556. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  9557. name = name.substr(1, name.length - 2);
  9558. name = ctx.stylize(name, 'name');
  9559. } else {
  9560. name = name.replace(/'/g, "\\'")
  9561. .replace(/\\"/g, '"')
  9562. .replace(/(^"|"$)/g, "'");
  9563. name = ctx.stylize(name, 'string');
  9564. }
  9565. }
  9566. return name + ': ' + str;
  9567. }
  9568. function reduceToSingleString(output, base, braces) {
  9569. var numLinesEst = 0;
  9570. var length = output.reduce(function(prev, cur) {
  9571. numLinesEst++;
  9572. if (cur.indexOf('\n') >= 0) numLinesEst++;
  9573. return prev + cur.length + 1;
  9574. }, 0);
  9575. if (length > 60) {
  9576. return braces[0] +
  9577. (base === '' ? '' : base + '\n ') +
  9578. ' ' +
  9579. output.join(',\n ') +
  9580. ' ' +
  9581. braces[1];
  9582. }
  9583. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  9584. }
  9585. function isArray(ar) {
  9586. return Array.isArray(ar) ||
  9587. (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  9588. }
  9589. function isRegExp(re) {
  9590. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  9591. }
  9592. function isDate(d) {
  9593. return typeof d === 'object' && objectToString(d) === '[object Date]';
  9594. }
  9595. function isError(e) {
  9596. return typeof e === 'object' && objectToString(e) === '[object Error]';
  9597. }
  9598. function objectToString(o) {
  9599. return Object.prototype.toString.call(o);
  9600. }
  9601. },{"./getEnumerableProperties":15,"./getName":17,"./getProperties":20}],24:[function(require,module,exports){
  9602. /*!
  9603. * Chai - flag utility
  9604. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9605. * MIT Licensed
  9606. */
  9607. /*!
  9608. * Module dependancies
  9609. */
  9610. var inspect = require('./inspect');
  9611. var config = require('../config');
  9612. /**
  9613. * ### .objDisplay (object)
  9614. *
  9615. * Determines if an object or an array matches
  9616. * criteria to be inspected in-line for error
  9617. * messages or should be truncated.
  9618. *
  9619. * @param {Mixed} javascript object to inspect
  9620. * @name objDisplay
  9621. * @namespace Utils
  9622. * @api public
  9623. */
  9624. module.exports = function (obj) {
  9625. var str = inspect(obj)
  9626. , type = Object.prototype.toString.call(obj);
  9627. if (config.truncateThreshold && str.length >= config.truncateThreshold) {
  9628. if (type === '[object Function]') {
  9629. return !obj.name || obj.name === ''
  9630. ? '[Function]'
  9631. : '[Function: ' + obj.name + ']';
  9632. } else if (type === '[object Array]') {
  9633. return '[ Array(' + obj.length + ') ]';
  9634. } else if (type === '[object Object]') {
  9635. var keys = Object.keys(obj)
  9636. , kstr = keys.length > 2
  9637. ? keys.splice(0, 2).join(', ') + ', ...'
  9638. : keys.join(', ');
  9639. return '{ Object (' + kstr + ') }';
  9640. } else {
  9641. return str;
  9642. }
  9643. } else {
  9644. return str;
  9645. }
  9646. };
  9647. },{"../config":4,"./inspect":23}],25:[function(require,module,exports){
  9648. /*!
  9649. * Chai - overwriteChainableMethod utility
  9650. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9651. * MIT Licensed
  9652. */
  9653. /**
  9654. * ### overwriteChainableMethod (ctx, name, method, chainingBehavior)
  9655. *
  9656. * Overwites an already existing chainable method
  9657. * and provides access to the previous function or
  9658. * property. Must return functions to be used for
  9659. * name.
  9660. *
  9661. * utils.overwriteChainableMethod(chai.Assertion.prototype, 'length',
  9662. * function (_super) {
  9663. * }
  9664. * , function (_super) {
  9665. * }
  9666. * );
  9667. *
  9668. * Can also be accessed directly from `chai.Assertion`.
  9669. *
  9670. * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
  9671. *
  9672. * Then can be used as any other assertion.
  9673. *
  9674. * expect(myFoo).to.have.length(3);
  9675. * expect(myFoo).to.have.length.above(3);
  9676. *
  9677. * @param {Object} ctx object whose method / property is to be overwritten
  9678. * @param {String} name of method / property to overwrite
  9679. * @param {Function} method function that returns a function to be used for name
  9680. * @param {Function} chainingBehavior function that returns a function to be used for property
  9681. * @namespace Utils
  9682. * @name overwriteChainableMethod
  9683. * @api public
  9684. */
  9685. module.exports = function (ctx, name, method, chainingBehavior) {
  9686. var chainableBehavior = ctx.__methods[name];
  9687. var _chainingBehavior = chainableBehavior.chainingBehavior;
  9688. chainableBehavior.chainingBehavior = function () {
  9689. var result = chainingBehavior(_chainingBehavior).call(this);
  9690. return result === undefined ? this : result;
  9691. };
  9692. var _method = chainableBehavior.method;
  9693. chainableBehavior.method = function () {
  9694. var result = method(_method).apply(this, arguments);
  9695. return result === undefined ? this : result;
  9696. };
  9697. };
  9698. },{}],26:[function(require,module,exports){
  9699. /*!
  9700. * Chai - overwriteMethod utility
  9701. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9702. * MIT Licensed
  9703. */
  9704. /**
  9705. * ### overwriteMethod (ctx, name, fn)
  9706. *
  9707. * Overwites an already existing method and provides
  9708. * access to previous function. Must return function
  9709. * to be used for name.
  9710. *
  9711. * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
  9712. * return function (str) {
  9713. * var obj = utils.flag(this, 'object');
  9714. * if (obj instanceof Foo) {
  9715. * new chai.Assertion(obj.value).to.equal(str);
  9716. * } else {
  9717. * _super.apply(this, arguments);
  9718. * }
  9719. * }
  9720. * });
  9721. *
  9722. * Can also be accessed directly from `chai.Assertion`.
  9723. *
  9724. * chai.Assertion.overwriteMethod('foo', fn);
  9725. *
  9726. * Then can be used as any other assertion.
  9727. *
  9728. * expect(myFoo).to.equal('bar');
  9729. *
  9730. * @param {Object} ctx object whose method is to be overwritten
  9731. * @param {String} name of method to overwrite
  9732. * @param {Function} method function that returns a function to be used for name
  9733. * @namespace Utils
  9734. * @name overwriteMethod
  9735. * @api public
  9736. */
  9737. module.exports = function (ctx, name, method) {
  9738. var _method = ctx[name]
  9739. , _super = function () { return this; };
  9740. if (_method && 'function' === typeof _method)
  9741. _super = _method;
  9742. ctx[name] = function () {
  9743. var result = method(_super).apply(this, arguments);
  9744. return result === undefined ? this : result;
  9745. }
  9746. };
  9747. },{}],27:[function(require,module,exports){
  9748. /*!
  9749. * Chai - overwriteProperty utility
  9750. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9751. * MIT Licensed
  9752. */
  9753. /**
  9754. * ### overwriteProperty (ctx, name, fn)
  9755. *
  9756. * Overwites an already existing property getter and provides
  9757. * access to previous value. Must return function to use as getter.
  9758. *
  9759. * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
  9760. * return function () {
  9761. * var obj = utils.flag(this, 'object');
  9762. * if (obj instanceof Foo) {
  9763. * new chai.Assertion(obj.name).to.equal('bar');
  9764. * } else {
  9765. * _super.call(this);
  9766. * }
  9767. * }
  9768. * });
  9769. *
  9770. *
  9771. * Can also be accessed directly from `chai.Assertion`.
  9772. *
  9773. * chai.Assertion.overwriteProperty('foo', fn);
  9774. *
  9775. * Then can be used as any other assertion.
  9776. *
  9777. * expect(myFoo).to.be.ok;
  9778. *
  9779. * @param {Object} ctx object whose property is to be overwritten
  9780. * @param {String} name of property to overwrite
  9781. * @param {Function} getter function that returns a getter function to be used for name
  9782. * @namespace Utils
  9783. * @name overwriteProperty
  9784. * @api public
  9785. */
  9786. module.exports = function (ctx, name, getter) {
  9787. var _get = Object.getOwnPropertyDescriptor(ctx, name)
  9788. , _super = function () {};
  9789. if (_get && 'function' === typeof _get.get)
  9790. _super = _get.get
  9791. Object.defineProperty(ctx, name,
  9792. { get: function () {
  9793. var result = getter(_super).call(this);
  9794. return result === undefined ? this : result;
  9795. }
  9796. , configurable: true
  9797. });
  9798. };
  9799. },{}],28:[function(require,module,exports){
  9800. /*!
  9801. * Chai - test utility
  9802. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9803. * MIT Licensed
  9804. */
  9805. /*!
  9806. * Module dependancies
  9807. */
  9808. var flag = require('./flag');
  9809. /**
  9810. * # test(object, expression)
  9811. *
  9812. * Test and object for expression.
  9813. *
  9814. * @param {Object} object (constructed Assertion)
  9815. * @param {Arguments} chai.Assertion.prototype.assert arguments
  9816. * @namespace Utils
  9817. * @name test
  9818. */
  9819. module.exports = function (obj, args) {
  9820. var negate = flag(obj, 'negate')
  9821. , expr = args[0];
  9822. return negate ? !expr : expr;
  9823. };
  9824. },{"./flag":13}],29:[function(require,module,exports){
  9825. /*!
  9826. * Chai - transferFlags utility
  9827. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9828. * MIT Licensed
  9829. */
  9830. /**
  9831. * ### transferFlags(assertion, object, includeAll = true)
  9832. *
  9833. * Transfer all the flags for `assertion` to `object`. If
  9834. * `includeAll` is set to `false`, then the base Chai
  9835. * assertion flags (namely `object`, `ssfi`, and `message`)
  9836. * will not be transferred.
  9837. *
  9838. *
  9839. * var newAssertion = new Assertion();
  9840. * utils.transferFlags(assertion, newAssertion);
  9841. *
  9842. * var anotherAsseriton = new Assertion(myObj);
  9843. * utils.transferFlags(assertion, anotherAssertion, false);
  9844. *
  9845. * @param {Assertion} assertion the assertion to transfer the flags from
  9846. * @param {Object} object the object to transfer the flags to; usually a new assertion
  9847. * @param {Boolean} includeAll
  9848. * @namespace Utils
  9849. * @name transferFlags
  9850. * @api private
  9851. */
  9852. module.exports = function (assertion, object, includeAll) {
  9853. var flags = assertion.__flags || (assertion.__flags = Object.create(null));
  9854. if (!object.__flags) {
  9855. object.__flags = Object.create(null);
  9856. }
  9857. includeAll = arguments.length === 3 ? includeAll : true;
  9858. for (var flag in flags) {
  9859. if (includeAll ||
  9860. (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
  9861. object.__flags[flag] = flags[flag];
  9862. }
  9863. }
  9864. };
  9865. },{}],30:[function(require,module,exports){
  9866. /*!
  9867. * assertion-error
  9868. * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
  9869. * MIT Licensed
  9870. */
  9871. /*!
  9872. * Return a function that will copy properties from
  9873. * one object to another excluding any originally
  9874. * listed. Returned function will create a new `{}`.
  9875. *
  9876. * @param {String} excluded properties ...
  9877. * @return {Function}
  9878. */
  9879. function exclude () {
  9880. var excludes = [].slice.call(arguments);
  9881. function excludeProps (res, obj) {
  9882. Object.keys(obj).forEach(function (key) {
  9883. if (!~excludes.indexOf(key)) res[key] = obj[key];
  9884. });
  9885. }
  9886. return function extendExclude () {
  9887. var args = [].slice.call(arguments)
  9888. , i = 0
  9889. , res = {};
  9890. for (; i < args.length; i++) {
  9891. excludeProps(res, args[i]);
  9892. }
  9893. return res;
  9894. };
  9895. };
  9896. /*!
  9897. * Primary Exports
  9898. */
  9899. module.exports = AssertionError;
  9900. /**
  9901. * ### AssertionError
  9902. *
  9903. * An extension of the JavaScript `Error` constructor for
  9904. * assertion and validation scenarios.
  9905. *
  9906. * @param {String} message
  9907. * @param {Object} properties to include (optional)
  9908. * @param {callee} start stack function (optional)
  9909. */
  9910. function AssertionError (message, _props, ssf) {
  9911. var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
  9912. , props = extend(_props || {});
  9913. // default values
  9914. this.message = message || 'Unspecified AssertionError';
  9915. this.showDiff = false;
  9916. // copy from properties
  9917. for (var key in props) {
  9918. this[key] = props[key];
  9919. }
  9920. // capture stack trace
  9921. ssf = ssf || arguments.callee;
  9922. if (ssf && Error.captureStackTrace) {
  9923. Error.captureStackTrace(this, ssf);
  9924. } else {
  9925. this.stack = new Error().stack;
  9926. }
  9927. }
  9928. /*!
  9929. * Inherit from Error.prototype
  9930. */
  9931. AssertionError.prototype = Object.create(Error.prototype);
  9932. /*!
  9933. * Statically set name
  9934. */
  9935. AssertionError.prototype.name = 'AssertionError';
  9936. /*!
  9937. * Ensure correct constructor
  9938. */
  9939. AssertionError.prototype.constructor = AssertionError;
  9940. /**
  9941. * Allow errors to be converted to JSON for static transfer.
  9942. *
  9943. * @param {Boolean} include stack (default: `true`)
  9944. * @return {Object} object that can be `JSON.stringify`
  9945. */
  9946. AssertionError.prototype.toJSON = function (stack) {
  9947. var extend = exclude('constructor', 'toJSON', 'stack')
  9948. , props = extend({ name: this.name }, this);
  9949. // include stack if exists and not turned off
  9950. if (false !== stack && this.stack) {
  9951. props.stack = this.stack;
  9952. }
  9953. return props;
  9954. };
  9955. },{}],31:[function(require,module,exports){
  9956. module.exports = require('./lib/eql');
  9957. },{"./lib/eql":32}],32:[function(require,module,exports){
  9958. /*!
  9959. * deep-eql
  9960. * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
  9961. * MIT Licensed
  9962. */
  9963. /*!
  9964. * Module dependencies
  9965. */
  9966. var type = require('type-detect');
  9967. /*!
  9968. * Buffer.isBuffer browser shim
  9969. */
  9970. var Buffer;
  9971. try { Buffer = require('buffer').Buffer; }
  9972. catch(ex) {
  9973. Buffer = {};
  9974. Buffer.isBuffer = function() { return false; }
  9975. }
  9976. /*!
  9977. * Primary Export
  9978. */
  9979. module.exports = deepEqual;
  9980. /**
  9981. * Assert super-strict (egal) equality between
  9982. * two objects of any type.
  9983. *
  9984. * @param {Mixed} a
  9985. * @param {Mixed} b
  9986. * @param {Array} memoised (optional)
  9987. * @return {Boolean} equal match
  9988. */
  9989. function deepEqual(a, b, m) {
  9990. if (sameValue(a, b)) {
  9991. return true;
  9992. } else if ('date' === type(a)) {
  9993. return dateEqual(a, b);
  9994. } else if ('regexp' === type(a)) {
  9995. return regexpEqual(a, b);
  9996. } else if (Buffer.isBuffer(a)) {
  9997. return bufferEqual(a, b);
  9998. } else if ('arguments' === type(a)) {
  9999. return argumentsEqual(a, b, m);
  10000. } else if (!typeEqual(a, b)) {
  10001. return false;
  10002. } else if (('object' !== type(a) && 'object' !== type(b))
  10003. && ('array' !== type(a) && 'array' !== type(b))) {
  10004. return sameValue(a, b);
  10005. } else {
  10006. return objectEqual(a, b, m);
  10007. }
  10008. }
  10009. /*!
  10010. * Strict (egal) equality test. Ensures that NaN always
  10011. * equals NaN and `-0` does not equal `+0`.
  10012. *
  10013. * @param {Mixed} a
  10014. * @param {Mixed} b
  10015. * @return {Boolean} equal match
  10016. */
  10017. function sameValue(a, b) {
  10018. if (a === b) return a !== 0 || 1 / a === 1 / b;
  10019. return a !== a && b !== b;
  10020. }
  10021. /*!
  10022. * Compare the types of two given objects and
  10023. * return if they are equal. Note that an Array
  10024. * has a type of `array` (not `object`) and arguments
  10025. * have a type of `arguments` (not `array`/`object`).
  10026. *
  10027. * @param {Mixed} a
  10028. * @param {Mixed} b
  10029. * @return {Boolean} result
  10030. */
  10031. function typeEqual(a, b) {
  10032. return type(a) === type(b);
  10033. }
  10034. /*!
  10035. * Compare two Date objects by asserting that
  10036. * the time values are equal using `saveValue`.
  10037. *
  10038. * @param {Date} a
  10039. * @param {Date} b
  10040. * @return {Boolean} result
  10041. */
  10042. function dateEqual(a, b) {
  10043. if ('date' !== type(b)) return false;
  10044. return sameValue(a.getTime(), b.getTime());
  10045. }
  10046. /*!
  10047. * Compare two regular expressions by converting them
  10048. * to string and checking for `sameValue`.
  10049. *
  10050. * @param {RegExp} a
  10051. * @param {RegExp} b
  10052. * @return {Boolean} result
  10053. */
  10054. function regexpEqual(a, b) {
  10055. if ('regexp' !== type(b)) return false;
  10056. return sameValue(a.toString(), b.toString());
  10057. }
  10058. /*!
  10059. * Assert deep equality of two `arguments` objects.
  10060. * Unfortunately, these must be sliced to arrays
  10061. * prior to test to ensure no bad behavior.
  10062. *
  10063. * @param {Arguments} a
  10064. * @param {Arguments} b
  10065. * @param {Array} memoize (optional)
  10066. * @return {Boolean} result
  10067. */
  10068. function argumentsEqual(a, b, m) {
  10069. if ('arguments' !== type(b)) return false;
  10070. a = [].slice.call(a);
  10071. b = [].slice.call(b);
  10072. return deepEqual(a, b, m);
  10073. }
  10074. /*!
  10075. * Get enumerable properties of a given object.
  10076. *
  10077. * @param {Object} a
  10078. * @return {Array} property names
  10079. */
  10080. function enumerable(a) {
  10081. var res = [];
  10082. for (var key in a) res.push(key);
  10083. return res;
  10084. }
  10085. /*!
  10086. * Simple equality for flat iterable objects
  10087. * such as Arrays or Node.js buffers.
  10088. *
  10089. * @param {Iterable} a
  10090. * @param {Iterable} b
  10091. * @return {Boolean} result
  10092. */
  10093. function iterableEqual(a, b) {
  10094. if (a.length !== b.length) return false;
  10095. var i = 0;
  10096. var match = true;
  10097. for (; i < a.length; i++) {
  10098. if (a[i] !== b[i]) {
  10099. match = false;
  10100. break;
  10101. }
  10102. }
  10103. return match;
  10104. }
  10105. /*!
  10106. * Extension to `iterableEqual` specifically
  10107. * for Node.js Buffers.
  10108. *
  10109. * @param {Buffer} a
  10110. * @param {Mixed} b
  10111. * @return {Boolean} result
  10112. */
  10113. function bufferEqual(a, b) {
  10114. if (!Buffer.isBuffer(b)) return false;
  10115. return iterableEqual(a, b);
  10116. }
  10117. /*!
  10118. * Block for `objectEqual` ensuring non-existing
  10119. * values don't get in.
  10120. *
  10121. * @param {Mixed} object
  10122. * @return {Boolean} result
  10123. */
  10124. function isValue(a) {
  10125. return a !== null && a !== undefined;
  10126. }
  10127. /*!
  10128. * Recursively check the equality of two objects.
  10129. * Once basic sameness has been established it will
  10130. * defer to `deepEqual` for each enumerable key
  10131. * in the object.
  10132. *
  10133. * @param {Mixed} a
  10134. * @param {Mixed} b
  10135. * @return {Boolean} result
  10136. */
  10137. function objectEqual(a, b, m) {
  10138. if (!isValue(a) || !isValue(b)) {
  10139. return false;
  10140. }
  10141. if (a.prototype !== b.prototype) {
  10142. return false;
  10143. }
  10144. var i;
  10145. if (m) {
  10146. for (i = 0; i < m.length; i++) {
  10147. if ((m[i][0] === a && m[i][1] === b)
  10148. || (m[i][0] === b && m[i][1] === a)) {
  10149. return true;
  10150. }
  10151. }
  10152. } else {
  10153. m = [];
  10154. }
  10155. try {
  10156. var ka = enumerable(a);
  10157. var kb = enumerable(b);
  10158. } catch (ex) {
  10159. return false;
  10160. }
  10161. ka.sort();
  10162. kb.sort();
  10163. if (!iterableEqual(ka, kb)) {
  10164. return false;
  10165. }
  10166. m.push([ a, b ]);
  10167. var key;
  10168. for (i = ka.length - 1; i >= 0; i--) {
  10169. key = ka[i];
  10170. if (!deepEqual(a[key], b[key], m)) {
  10171. return false;
  10172. }
  10173. }
  10174. return true;
  10175. }
  10176. },{"buffer":undefined,"type-detect":33}],33:[function(require,module,exports){
  10177. module.exports = require('./lib/type');
  10178. },{"./lib/type":34}],34:[function(require,module,exports){
  10179. /*!
  10180. * type-detect
  10181. * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
  10182. * MIT Licensed
  10183. */
  10184. /*!
  10185. * Primary Exports
  10186. */
  10187. var exports = module.exports = getType;
  10188. /*!
  10189. * Detectable javascript natives
  10190. */
  10191. var natives = {
  10192. '[object Array]': 'array'
  10193. , '[object RegExp]': 'regexp'
  10194. , '[object Function]': 'function'
  10195. , '[object Arguments]': 'arguments'
  10196. , '[object Date]': 'date'
  10197. };
  10198. /**
  10199. * ### typeOf (obj)
  10200. *
  10201. * Use several different techniques to determine
  10202. * the type of object being tested.
  10203. *
  10204. *
  10205. * @param {Mixed} object
  10206. * @return {String} object type
  10207. * @api public
  10208. */
  10209. function getType (obj) {
  10210. var str = Object.prototype.toString.call(obj);
  10211. if (natives[str]) return natives[str];
  10212. if (obj === null) return 'null';
  10213. if (obj === undefined) return 'undefined';
  10214. if (obj === Object(obj)) return 'object';
  10215. return typeof obj;
  10216. }
  10217. exports.Library = Library;
  10218. /**
  10219. * ### Library
  10220. *
  10221. * Create a repository for custom type detection.
  10222. *
  10223. * ```js
  10224. * var lib = new type.Library;
  10225. * ```
  10226. *
  10227. */
  10228. function Library () {
  10229. this.tests = {};
  10230. }
  10231. /**
  10232. * #### .of (obj)
  10233. *
  10234. * Expose replacement `typeof` detection to the library.
  10235. *
  10236. * ```js
  10237. * if ('string' === lib.of('hello world')) {
  10238. * // ...
  10239. * }
  10240. * ```
  10241. *
  10242. * @param {Mixed} object to test
  10243. * @return {String} type
  10244. */
  10245. Library.prototype.of = getType;
  10246. /**
  10247. * #### .define (type, test)
  10248. *
  10249. * Add a test to for the `.test()` assertion.
  10250. *
  10251. * Can be defined as a regular expression:
  10252. *
  10253. * ```js
  10254. * lib.define('int', /^[0-9]+$/);
  10255. * ```
  10256. *
  10257. * ... or as a function:
  10258. *
  10259. * ```js
  10260. * lib.define('bln', function (obj) {
  10261. * if ('boolean' === lib.of(obj)) return true;
  10262. * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ];
  10263. * if ('string' === lib.of(obj)) obj = obj.toLowerCase();
  10264. * return !! ~blns.indexOf(obj);
  10265. * });
  10266. * ```
  10267. *
  10268. * @param {String} type
  10269. * @param {RegExp|Function} test
  10270. * @api public
  10271. */
  10272. Library.prototype.define = function (type, test) {
  10273. if (arguments.length === 1) return this.tests[type];
  10274. this.tests[type] = test;
  10275. return this;
  10276. };
  10277. /**
  10278. * #### .test (obj, test)
  10279. *
  10280. * Assert that an object is of type. Will first
  10281. * check natives, and if that does not pass it will
  10282. * use the user defined custom tests.
  10283. *
  10284. * ```js
  10285. * assert(lib.test('1', 'int'));
  10286. * assert(lib.test('yes', 'bln'));
  10287. * ```
  10288. *
  10289. * @param {Mixed} object
  10290. * @param {String} type
  10291. * @return {Boolean} result
  10292. * @api public
  10293. */
  10294. Library.prototype.test = function (obj, type) {
  10295. if (type === getType(obj)) return true;
  10296. var test = this.tests[type];
  10297. if (test && 'regexp' === getType(test)) {
  10298. return test.test(obj);
  10299. } else if (test && 'function' === getType(test)) {
  10300. return test(obj);
  10301. } else {
  10302. throw new ReferenceError('Type test "' + type + '" not defined or invalid.');
  10303. }
  10304. };
  10305. },{}],35:[function(require,module,exports){
  10306. arguments[4][33][0].apply(exports,arguments)
  10307. },{"./lib/type":36,"dup":33}],36:[function(require,module,exports){
  10308. /*!
  10309. * type-detect
  10310. * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
  10311. * MIT Licensed
  10312. */
  10313. /*!
  10314. * Primary Exports
  10315. */
  10316. var exports = module.exports = getType;
  10317. /**
  10318. * ### typeOf (obj)
  10319. *
  10320. * Use several different techniques to determine
  10321. * the type of object being tested.
  10322. *
  10323. *
  10324. * @param {Mixed} object
  10325. * @return {String} object type
  10326. * @api public
  10327. */
  10328. var objectTypeRegexp = /^\[object (.*)\]$/;
  10329. function getType(obj) {
  10330. var type = Object.prototype.toString.call(obj).match(objectTypeRegexp)[1].toLowerCase();
  10331. // Let "new String('')" return 'object'
  10332. if (typeof Promise === 'function' && obj instanceof Promise) return 'promise';
  10333. // PhantomJS has type "DOMWindow" for null
  10334. if (obj === null) return 'null';
  10335. // PhantomJS has type "DOMWindow" for undefined
  10336. if (obj === undefined) return 'undefined';
  10337. return type;
  10338. }
  10339. exports.Library = Library;
  10340. /**
  10341. * ### Library
  10342. *
  10343. * Create a repository for custom type detection.
  10344. *
  10345. * ```js
  10346. * var lib = new type.Library;
  10347. * ```
  10348. *
  10349. */
  10350. function Library() {
  10351. if (!(this instanceof Library)) return new Library();
  10352. this.tests = {};
  10353. }
  10354. /**
  10355. * #### .of (obj)
  10356. *
  10357. * Expose replacement `typeof` detection to the library.
  10358. *
  10359. * ```js
  10360. * if ('string' === lib.of('hello world')) {
  10361. * // ...
  10362. * }
  10363. * ```
  10364. *
  10365. * @param {Mixed} object to test
  10366. * @return {String} type
  10367. */
  10368. Library.prototype.of = getType;
  10369. /**
  10370. * #### .define (type, test)
  10371. *
  10372. * Add a test to for the `.test()` assertion.
  10373. *
  10374. * Can be defined as a regular expression:
  10375. *
  10376. * ```js
  10377. * lib.define('int', /^[0-9]+$/);
  10378. * ```
  10379. *
  10380. * ... or as a function:
  10381. *
  10382. * ```js
  10383. * lib.define('bln', function (obj) {
  10384. * if ('boolean' === lib.of(obj)) return true;
  10385. * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ];
  10386. * if ('string' === lib.of(obj)) obj = obj.toLowerCase();
  10387. * return !! ~blns.indexOf(obj);
  10388. * });
  10389. * ```
  10390. *
  10391. * @param {String} type
  10392. * @param {RegExp|Function} test
  10393. * @api public
  10394. */
  10395. Library.prototype.define = function(type, test) {
  10396. if (arguments.length === 1) return this.tests[type];
  10397. this.tests[type] = test;
  10398. return this;
  10399. };
  10400. /**
  10401. * #### .test (obj, test)
  10402. *
  10403. * Assert that an object is of type. Will first
  10404. * check natives, and if that does not pass it will
  10405. * use the user defined custom tests.
  10406. *
  10407. * ```js
  10408. * assert(lib.test('1', 'int'));
  10409. * assert(lib.test('yes', 'bln'));
  10410. * ```
  10411. *
  10412. * @param {Mixed} object
  10413. * @param {String} type
  10414. * @return {Boolean} result
  10415. * @api public
  10416. */
  10417. Library.prototype.test = function(obj, type) {
  10418. if (type === getType(obj)) return true;
  10419. var test = this.tests[type];
  10420. if (test && 'regexp' === getType(test)) {
  10421. return test.test(obj);
  10422. } else if (test && 'function' === getType(test)) {
  10423. return test(obj);
  10424. } else {
  10425. throw new ReferenceError('Type test "' + type + '" not defined or invalid.');
  10426. }
  10427. };
  10428. },{}]},{},[1])(1)
  10429. });
  10430. /*
  10431. * vim: ts=4:sw=4:expandtab
  10432. */
  10433. mocha.setup("bdd");
  10434. window.assert = chai.assert;
  10435. (function() {
  10436. var OriginalReporter = mocha._reporter;
  10437. var SauceReporter = function(runner) {
  10438. var failedTests = [];
  10439. runner.on('end', function() {
  10440. window.mochaResults = runner.stats;
  10441. window.mochaResults.reports = failedTests;
  10442. });
  10443. runner.on('fail', function(test, err) {
  10444. var flattenTitles = function(test) {
  10445. var titles = [];
  10446. while (test.parent.title) {
  10447. titles.push(test.parent.title);
  10448. test = test.parent;
  10449. }
  10450. return titles.reverse();
  10451. };
  10452. failedTests.push({
  10453. name: test.title,
  10454. result: false,
  10455. message: err.message,
  10456. stack: err.stack,
  10457. titles: flattenTitles(test)
  10458. });
  10459. });
  10460. new OriginalReporter(runner);
  10461. };
  10462. SauceReporter.prototype = OriginalReporter.prototype;
  10463. mocha.reporter(SauceReporter);
  10464. }());
  10465. // Override the database id.
  10466. window.Whisper = window.Whisper || {};
  10467. window.Whisper.Database = window.Whisper.Database || {};
  10468. Whisper.Database.id = 'test';
  10469. /*
  10470. * global helpers for tests
  10471. */
  10472. function assertEqualArrayBuffers(ab1, ab2) {
  10473. assert.deepEqual(new Uint8Array(ab1), new Uint8Array(ab2));
  10474. };
  10475. function hexToArrayBuffer(str) {
  10476. var ret = new ArrayBuffer(str.length / 2);
  10477. var array = new Uint8Array(ret);
  10478. for (var i = 0; i < str.length/2; i++) {
  10479. array[i] = parseInt(str.substr(i*2, 2), 16);
  10480. }
  10481. return ret;
  10482. };
  10483. /* Delete the database before running any tests */
  10484. before(function(done) {
  10485. var idbReq = indexedDB.deleteDatabase('test');
  10486. idbReq.onsuccess = function() { done(); };
  10487. });
  10488. function clearDatabase(done) {
  10489. var convos = new Whisper.ConversationCollection();
  10490. return convos.fetch().then(function() {
  10491. convos.destroyAll().then(function() {
  10492. var messages = new Whisper.MessageCollection();
  10493. return messages.fetch().then(function() {
  10494. messages.destroyAll().then(function() {
  10495. if (done) {
  10496. done();
  10497. }
  10498. });
  10499. });
  10500. });
  10501. });
  10502. }