├── .gitignore ├── gulpfile.js ├── bower.json ├── package.json ├── test ├── index.html ├── fixtures │ ├── mocha.css │ ├── chai.js │ ├── mocha.js │ └── sinon.js └── tests.js ├── dist └── jax.min.js ├── README.md └── lib └── jax.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var rename = require('gulp-rename'); 3 | var uglify = require('gulp-uglify'); 4 | 5 | gulp.task('build', function() { 6 | gulp 7 | .src('./lib/jax.js') 8 | .pipe(uglify()) 9 | .pipe(rename('jax.min.js')) 10 | .pipe(gulp.dest('./dist')) 11 | }); 12 | 13 | gulp.task('default', ['build']); 14 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Jax", 3 | "version": "1.1.1", 4 | "homepage": "https://github.com/brandonjpierce/jax", 5 | "authors": [ 6 | "Brandon Pierce " 7 | ], 8 | "description": "Fully featured client side ajax library.", 9 | "main": "./dist/jax.min.js", 10 | "keywords": [ 11 | "jax", 12 | "ajax", 13 | "http", 14 | "request", 15 | "get", 16 | "post", 17 | "put", 18 | "delete" 19 | ], 20 | "license": "MIT", 21 | "ignore": [ 22 | "**/.*", 23 | "node_modules", 24 | "bower_components", 25 | "test" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jax", 3 | "version": "1.1.1", 4 | "main": "./dist/jax.min.js", 5 | "description": "Fully featured client side ajax library.", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/brandonjpierce/jax.git" 12 | }, 13 | "author": "Brandon Pierce (http://brandonjpierce.com/)", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/brandonjpierce/jax/issues" 17 | }, 18 | "homepage": "https://github.com/brandonjpierce/jax", 19 | "devDependencies": { 20 | "gulp": "^3.8.10", 21 | "gulp-rename": "^1.2.0", 22 | "gulp-uglify": "^1.0.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Jax · Tests 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /dist/jax.min.js: -------------------------------------------------------------------------------- 1 | !function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e:t.Jax=e(t)}(this,function(t){"use strict";function e(t){this.request=t,this.status=this.request.xhr.status,this.headers=this.parseHeaders(),this.data=this.parseData(),this.raw=this.request.xhr.responseText||null;var e=s(this.status/100);(4===e||5===e)&&(this.error=this.parseError())}function r(t,e){this.url=e,this.method=t,this.xhr=i.getXhr(),this.headers={},this.requestData={},this.queries=[]}function n(t,e,n){return n?new r(t,e).done(n):new r(t,e)}var s=Math.round,i={};return i.isObject=function(t){return t instanceof Object},i.isFunction=function(t){return t&&"[object Function]"=={}.toString.call(t)},i.size=function(t){var e=0;if(t)if(i.isObject(t))for(var r in t)t.hasOwnProperty(r)&&e++;else e=t.length;return e},i.getXhr=function(){var e=!1,r=["Microsoft.XMLHTTP","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP"];if("XMLHttpRequest"in t)e=new t.XMLHttpRequest;else for(var n=0,s=r.length;n!==s;n++)try{e=new t.ActiveXObject(r[n])}catch(i){e=!1}return e},i.serialize=function(t){if(!i.isObject(t))return"";var e=[],r="";for(var n in t)if(t.hasOwnProperty(n)){var s=encodeURIComponent(n),o=encodeURIComponent(t[n]);e.push(s+"="+o)}return r=e.join("&")},i.unserialize=function(t){for(var e={},r=t.split("&"),n=0,s=r.length;n!==s;n++){var i=r[n].split("="),o=decodeURIComponent(i[0]),a=decodeURIComponent(i[1]);e[o]=a}return e},e.prototype.parseHeaders=function(){var t=this.request.xhr.getAllResponseHeaders(),e={};if(t)for(var r=t.split("\r\n"),n=0,s=r.length;n!==s;n++){var i=r[n],o=i.indexOf(": ");if(o>0){var a=i.substring(0,o),u=i.substring(o+2);e[a]=u}}return e["Content-Type"]||(e["Content-Type"]="application/json"),e},e.prototype.parseData=function(){var t=this.request.xhr.responseText||null,e=this.headers["Content-Type"];if(t){var r={"application/x-www-form-urlencoded":i.unserialize,"application/json":JSON.parse};r[e]&&(t=r[e](t))}return t},e.prototype.parseError=function(){var t=this.request.method,e=this.request.url;return new Error("Cannot "+t+" "+e)},r.prototype.header=function(t,e){if(t)if(i.isObject(t))for(var r in t)t.hasOwnProperty(r)&&(this.headers[r]=t[r]);else this.headers[t]=e;return this},r.prototype.type=function(t){return t&&(this.headers["Content-Type"]=t),this},r.prototype.cors=function(){return this.header("X-CORS-Enabled",!0),this.cors=!0,this},r.prototype.nocache=function(){return this.header({"Cache-Control":"no-cache",Expires:"-1","X-Requested-With":"XMLHttpRequest"}),this},r.prototype.query=function(t){return t&&(i.isObject(t)&&(t=i.serialize(t)),this.queries.push(t)),this},r.prototype.data=function(t,e){var r=i.size(this.requestData);if(i.isObject(t))if(r)for(var n in t)t.hasOwnProperty(n)&&(this.requestData[n]=t[n]);else this.requestData=t;else this.requestData[t]=e;return this},r.prototype.formatData=function(){var t=this.requestData;i.size(t)&&(t="application/json"===this.headers["Content-Type"]?JSON.stringify(t):i.serialize(t))},r.prototype.formatQueries=function(){var t=this.queries,e=this.url;if(i.size(t)){var r=t.join("&"),n=e.indexOf("?")>-1?"&":"?";e+=n+r}},r.prototype.formatHeaders=function(){var t=this.headers,e=this.xhr;for(var r in t)t.hasOwnProperty(r)&&e.setRequestHeader(r,t[r])},r.prototype.done=function(t){var r=this,n=this.xhr;n.onreadystatechange=function(){if(4===n.readyState){if(0===n.status){var s=new Error("Cross domain request is not allowed");t(s,null)}try{var i=new e(r);t(null,i)}catch(o){var s=new Error("Unable to parse response");s.original=o,t(s,null)}}},this.formatQueries(),n.open(this.method,this.url,!0),this.cors&&(n.withCredentials=!0),this.formatHeaders(),this.formatData(),n.send(this.requestData)},n.get=function(t,e){return e=i.isFunction(e)?e:null,new n("GET",t,e)},n.post=function(t,e){return e=i.isFunction(e)?e:null,new n("POST",t,e)},n.put=function(t,e){return e=i.isFunction(e)?e:null,new n("PUT",t,e)},n.del=function(t,e){return e=i.isFunction(e)?e:null,new n("DELETE",t,e)},n.Request=r,n.Response=e,n}); -------------------------------------------------------------------------------- /test/fixtures/mocha.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | 3 | body { 4 | margin:0; 5 | } 6 | 7 | #mocha { 8 | font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif; 9 | margin: 60px auto; 10 | } 11 | 12 | #mocha ul, 13 | #mocha li { 14 | margin: 0; 15 | padding: 0; 16 | } 17 | 18 | #mocha ul { 19 | list-style: none; 20 | } 21 | 22 | #mocha h1, 23 | #mocha h2 { 24 | margin: 0; 25 | } 26 | 27 | #mocha h1 { 28 | margin-top: 15px; 29 | font-size: 1em; 30 | font-weight: 200; 31 | } 32 | 33 | #mocha h1 a { 34 | text-decoration: none; 35 | color: inherit; 36 | } 37 | 38 | #mocha h1 a:hover { 39 | text-decoration: underline; 40 | } 41 | 42 | #mocha .suite .suite h1 { 43 | margin-top: 0; 44 | font-size: .8em; 45 | } 46 | 47 | #mocha .hidden { 48 | display: none; 49 | } 50 | 51 | #mocha h2 { 52 | font-size: 12px; 53 | font-weight: normal; 54 | cursor: pointer; 55 | } 56 | 57 | #mocha .suite { 58 | margin-left: 15px; 59 | } 60 | 61 | #mocha .test { 62 | margin-left: 15px; 63 | overflow: hidden; 64 | } 65 | 66 | #mocha .test.pending:hover h2::after { 67 | content: '(pending)'; 68 | font-family: arial, sans-serif; 69 | } 70 | 71 | #mocha .test.pass.medium .duration { 72 | background: #c09853; 73 | } 74 | 75 | #mocha .test.pass.slow .duration { 76 | background: #b94a48; 77 | } 78 | 79 | #mocha .test.pass::before { 80 | content: '✓'; 81 | font-size: 12px; 82 | display: block; 83 | float: left; 84 | margin-right: 5px; 85 | color: #00d6b2; 86 | } 87 | 88 | #mocha .test.pass .duration { 89 | font-size: 9px; 90 | margin-left: 5px; 91 | padding: 2px 5px; 92 | color: #fff; 93 | -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2); 94 | -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2); 95 | box-shadow: inset 0 1px 1px rgba(0,0,0,.2); 96 | -webkit-border-radius: 5px; 97 | -moz-border-radius: 5px; 98 | -ms-border-radius: 5px; 99 | -o-border-radius: 5px; 100 | border-radius: 5px; 101 | } 102 | 103 | #mocha .test.pass.fast .duration { 104 | display: none; 105 | } 106 | 107 | #mocha .test.pending { 108 | color: #0b97c4; 109 | } 110 | 111 | #mocha .test.pending::before { 112 | content: '◦'; 113 | color: #0b97c4; 114 | } 115 | 116 | #mocha .test.fail { 117 | color: #c00; 118 | } 119 | 120 | #mocha .test.fail pre { 121 | color: black; 122 | } 123 | 124 | #mocha .test.fail::before { 125 | content: '✖'; 126 | font-size: 12px; 127 | display: block; 128 | float: left; 129 | margin-right: 5px; 130 | color: #c00; 131 | } 132 | 133 | #mocha .test pre.error { 134 | color: #c00; 135 | max-height: 300px; 136 | overflow: auto; 137 | } 138 | 139 | /** 140 | * (1): approximate for browsers not supporting calc 141 | * (2): 42 = 2*15 + 2*10 + 2*1 (padding + margin + border) 142 | * ^^ seriously 143 | */ 144 | #mocha .test pre { 145 | display: block; 146 | float: left; 147 | clear: left; 148 | font: 12px/1.5 monaco, monospace; 149 | margin: 5px; 150 | padding: 15px; 151 | border: 1px solid #eee; 152 | max-width: 85%; /*(1)*/ 153 | max-width: calc(100% - 42px); /*(2)*/ 154 | word-wrap: break-word; 155 | border-bottom-color: #ddd; 156 | -webkit-border-radius: 3px; 157 | -webkit-box-shadow: 0 1px 3px #eee; 158 | -moz-border-radius: 3px; 159 | -moz-box-shadow: 0 1px 3px #eee; 160 | border-radius: 3px; 161 | } 162 | 163 | #mocha .test h2 { 164 | position: relative; 165 | } 166 | 167 | #mocha .test a.replay { 168 | position: absolute; 169 | top: 3px; 170 | right: 0; 171 | text-decoration: none; 172 | vertical-align: middle; 173 | display: block; 174 | width: 15px; 175 | height: 15px; 176 | line-height: 15px; 177 | text-align: center; 178 | background: #eee; 179 | font-size: 15px; 180 | -moz-border-radius: 15px; 181 | border-radius: 15px; 182 | -webkit-transition: opacity 200ms; 183 | -moz-transition: opacity 200ms; 184 | transition: opacity 200ms; 185 | opacity: 0.3; 186 | color: #888; 187 | } 188 | 189 | #mocha .test:hover a.replay { 190 | opacity: 1; 191 | } 192 | 193 | #mocha-report.pass .test.fail { 194 | display: none; 195 | } 196 | 197 | #mocha-report.fail .test.pass { 198 | display: none; 199 | } 200 | 201 | #mocha-report.pending .test.pass, 202 | #mocha-report.pending .test.fail { 203 | display: none; 204 | } 205 | #mocha-report.pending .test.pass.pending { 206 | display: block; 207 | } 208 | 209 | #mocha-error { 210 | color: #c00; 211 | font-size: 1.5em; 212 | font-weight: 100; 213 | letter-spacing: 1px; 214 | } 215 | 216 | #mocha-stats { 217 | position: fixed; 218 | top: 15px; 219 | right: 10px; 220 | font-size: 12px; 221 | margin: 0; 222 | color: #888; 223 | z-index: 1; 224 | } 225 | 226 | #mocha-stats .progress { 227 | float: right; 228 | padding-top: 0; 229 | } 230 | 231 | #mocha-stats em { 232 | color: black; 233 | } 234 | 235 | #mocha-stats a { 236 | text-decoration: none; 237 | color: inherit; 238 | } 239 | 240 | #mocha-stats a:hover { 241 | border-bottom: 1px solid #eee; 242 | } 243 | 244 | #mocha-stats li { 245 | display: inline-block; 246 | margin: 0 5px; 247 | list-style: none; 248 | padding-top: 11px; 249 | } 250 | 251 | #mocha-stats canvas { 252 | width: 40px; 253 | height: 40px; 254 | } 255 | 256 | #mocha code .comment { color: #ddd; } 257 | #mocha code .init { color: #2f6fad; } 258 | #mocha code .string { color: #5890ad; } 259 | #mocha code .keyword { color: #8a6343; } 260 | #mocha code .number { color: #2f6fad; } 261 | 262 | @media screen and (max-device-width: 480px) { 263 | #mocha { 264 | margin: 60px 0px; 265 | } 266 | 267 | #mocha #stats { 268 | position: absolute; 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Jax 2 | 3 | Jax is a tiny (1.7kb gzipped) fully featured client-side AJAX library with a expressive syntax inspired by the wonderful Superagent. 4 | 5 | [![Code Climate](https://codeclimate.com/github/brandonjpierce/jax/badges/gpa.svg)](https://codeclimate.com/github/brandonjpierce/jax) 6 | 7 | ## Getting Started 8 | 9 | #### Traditional 10 | ```html 11 | 12 | 13 | 14 | 26 | 27 | ``` 28 | 29 | #### Bower 30 | ``` 31 | bower install jax 32 | ``` 33 | 34 | *Jax also has support for both AMD and CommonJS formats.* 35 | 36 | ## HTTP verb methods 37 | 38 | The HTTP verb methods will all return a new instance of a Jax's internal Request object. These methods are required to be called first before any request methods can be set. 39 | 40 | #### .get(url `String`) 41 | ```javascript 42 | Jax.get('/test').done(callback); 43 | 44 | // or if you don't need any additional methods chained 45 | Jax.get('/test', callback); 46 | ``` 47 | 48 | #### .post(url `String`) 49 | ```javascript 50 | Jax.post('/test').done(callback); 51 | 52 | // or if you don't need any additional methods chained 53 | Jax.post('/test', callback); 54 | ``` 55 | 56 | #### .put(url `String`) 57 | ```javascript 58 | Jax.put('/test').done(callback); 59 | 60 | // or if you don't need any additional methods chained 61 | Jax.put('/test', callback); 62 | ``` 63 | 64 | #### .del(url `String`) 65 | ```javascript 66 | Jax.del('/test').done(callback); 67 | 68 | // or if you don't need any additional methods chained 69 | Jax.del('/test', callback); 70 | ``` 71 | 72 | ## Request Methods 73 | 74 | ### .header(key `String|Object`, val `String`) 75 | 76 | Adds a header field to the request. Will accept a key and value or a object. 77 | 78 | ```javascript 79 | Jax 80 | .get('/test') 81 | .header('Content-Type', 'application/json') 82 | .query({ 'Accept': 'application/json' }) 83 | .done(); 84 | ``` 85 | 86 | ### .data(key `String|Object`, val `String`) 87 | 88 | Send payload data along with request. Will accept a key and value or a object. Before sending off the request the data is serialized into either json or a URL encoded string depending on the content-type. 89 | 90 | ```javascript 91 | Jax 92 | .post('/test') 93 | .data('foo', 'bar') 94 | .data({ 'boz': 'baz' }) 95 | .done(); 96 | ``` 97 | 98 | ### .query(val `String|Object`) 99 | 100 | Adds a query string to the request URL. If a query string already exists it will automatically separate values with `&`. Will accept a string or an object, if object it will be serialized into a URL encoded string. 101 | 102 | ```javascript 103 | Jax 104 | .get('/test') 105 | .query('baz=boz') 106 | .query({ foo: 'bar' }) 107 | .done(); 108 | 109 | // request url will now be /test?baz=boz&foo=bar 110 | ``` 111 | 112 | ### .type(val `String`) 113 | 114 | Syntax sugar for setting the `Content-Type` in the request header. 115 | 116 | ```javascript 117 | Jax 118 | .get('/test') 119 | .type('application/json') 120 | .done(); 121 | ``` 122 | 123 | ### .cors() 124 | 125 | Syntax sugar for setting up the request to handle CORS and allows you to send cookies from the requesting location. 126 | 127 | ```javascript 128 | Jax 129 | .get('/test') 130 | .cors() 131 | .done(); 132 | ``` 133 | 134 | ### .nocache() 135 | 136 | Syntax sugar for setting headers that will notify the requesting server to not cache the response. 137 | 138 | ```javascript 139 | Jax 140 | .get('/test') 141 | .nocache() 142 | .done(); 143 | ``` 144 | 145 | ### .done(err `Object|null`, res `Object|null`) 146 | 147 | The main method to send your request and receive a response. This method will always return 2 items in its callback function. The first argument is the error object if it exists or null. The second argument is the actual response object or null. 148 | 149 | ```javascript 150 | Jax 151 | .get('/test') 152 | .done(function(err, res) {}); 153 | ``` 154 | 155 | ## Response properties 156 | 157 | The response object passed as the second argument in the done() callback contains a variety of properties that will aid you in correctly parsing a response. 158 | 159 | #### res.request 160 | 161 | The request object that was sent to the server, included in this object is the underlining XHR object. 162 | 163 | #### res.status 164 | 165 | The status code of the response 166 | 167 | #### res.data 168 | 169 | The parsed response data. Jax will automatically parse the data sent by the server based on the `Content-Type`. In case incorrect `Content-Type` was set in the response you are also able to access the unparsed data with `res.raw`. 170 | 171 | #### res.raw 172 | 173 | The unparsed response data sent just in case the parser incorrectly parsed the response data because of incorrect `Content-Type` headers sent in the response. 174 | 175 | #### res.headers 176 | 177 | All of the response headers parsed into a object. 178 | 179 | #### res.error 180 | 181 | If the response status starts with a 4 or 5 (most error responses) then it will attach an error obect to the response that you can check against in your callback. 182 | 183 | ## Putting it all together 184 | 185 | ```javascript 186 | Jax 187 | .get('www.site.com') 188 | .query({ foo: 'bar' }) // url is now www.site.com?foo=bar 189 | .query('baz=boz') // url is now www.site.com?foo=bar&baz=boz 190 | .then(function(err, res) { 191 | if (err || res.error) { 192 | // handle error here 193 | } 194 | 195 | // do something with res 196 | }); 197 | 198 | Jax 199 | .post('www.site.com') 200 | .type('application/json') 201 | .data({ foo: 'bar' }) 202 | .nocache() // we do not want our response cached 203 | .then(function(err, res) { 204 | if (err || res.error) { 205 | // handle error here 206 | } 207 | 208 | // do something with res 209 | }); 210 | ``` 211 | 212 | ## Migrating from Superagent 213 | There is not a huge difference between Jax and Superagent besides size and method names but Jax has stripped away some of the what I think were unnecessary methods from Superagent such as auth() and accept(). The response object in Jax is also a little different in what properties are present. 214 | 215 | *Small rundown of differences in methods* 216 | - .send() is now .data() 217 | - .end() is now .done() 218 | - .auth() is removed 219 | - .accept() is removed 220 | 221 | Another small change is that an error object is always passed into your callback even if it is null. I use Node quite a lot and really like the error first style and wanted to do the same for Jax. 222 | 223 | The whole goal of Jax was to have the same expressive syntax and features that I have come to love about Superagent but in the tiniest file size possible. 224 | 225 | ## Contributing 226 | 227 | Try and respect the existing style as best as possible. Also please make sure to add unit tests for any new or changed functionality. Also lint your code using JSHint or similar. 228 | 229 | ## Tests 230 | 231 | Tests can be viewed by downloading source and viewing the `/test/index.html` file in your browser. 232 | 233 | ## Release history 234 | 235 | - 1.1.1 236 | - Reduced some code complexity in the .done() method by breaking up logic into smaller methods 237 | - 1.1.0 238 | - Added sugar syntax to main HTTP verb methods e.g. you now can do `Jax.get(url, callback)` instead of `Jax.get(url).done(callback)` 239 | - 1.0.1 240 | - package.json and bower.json version bump 241 | - 1.0.0 242 | - Initial release 243 | -------------------------------------------------------------------------------- /test/tests.js: -------------------------------------------------------------------------------- 1 | var assert = chai.assert; 2 | var server; 3 | 4 | describe('Object Instances', function() { 5 | it('verb method instance of Jax.Request', function() { 6 | assert.instanceOf(Jax.get('data.json'), Jax.Request); 7 | }); 8 | 9 | it('response instance of Jax.Response', function(end) { 10 | Jax 11 | .get('/') 12 | .done(function(err, res) { 13 | assert.instanceOf(res, Jax.Response); 14 | end(); 15 | }); 16 | }); 17 | }); 18 | 19 | describe('Shorthand methods', function() { 20 | before(function() { 21 | server = sinon.fakeServer.create(); 22 | server.autoRespond = true; 23 | 24 | server.respondWith('/test', [ 25 | 200, 26 | {'Content-Type': 'application/json'}, 27 | '{"foo":"bar"}' 28 | ]); 29 | }); 30 | 31 | after(function() { 32 | server.restore(); 33 | }); 34 | 35 | it('Jax.get(url, callback)', function(end) { 36 | Jax 37 | .get('/test', function(err, res) { 38 | var data = res.data; 39 | 40 | assert.isObject(data); 41 | assert.propertyVal(data, 'foo', 'bar'); 42 | assert.strictEqual(res.status, 200); 43 | 44 | end(); 45 | }); 46 | }); 47 | 48 | it('Jax.post(url, callback)', function(end) { 49 | Jax 50 | .post('/test', function(err, res) { 51 | var data = res.data; 52 | 53 | assert.isObject(data); 54 | assert.propertyVal(data, 'foo', 'bar'); 55 | assert.strictEqual(res.status, 200); 56 | 57 | end(); 58 | }); 59 | }); 60 | 61 | it('Jax.put(url, callback)', function(end) { 62 | Jax 63 | .put('/test', function(err, res) { 64 | var data = res.data; 65 | 66 | assert.isObject(data); 67 | assert.propertyVal(data, 'foo', 'bar'); 68 | assert.strictEqual(res.status, 200); 69 | 70 | end(); 71 | }); 72 | }); 73 | 74 | it('Jax.del(url, callback)', function(end) { 75 | Jax 76 | .del('/test', function(err, res) { 77 | var data = res.data; 78 | 79 | assert.isObject(data); 80 | assert.propertyVal(data, 'foo', 'bar'); 81 | assert.strictEqual(res.status, 200); 82 | 83 | end(); 84 | }); 85 | }); 86 | }); 87 | 88 | describe('Correct Responses', function() { 89 | before(function() { 90 | server = sinon.fakeServer.create(); 91 | server.autoRespond = true; 92 | 93 | server.respondWith('/json', [ 94 | 200, 95 | {'Content-Type': 'application/json'}, 96 | '{"foo":"bar"}' 97 | ]); 98 | 99 | server.respondWith('/form', [ 100 | 200, 101 | {'Content-Type': 'application/x-www-form-urlencoded'}, 102 | 'foo=bar' 103 | ]); 104 | 105 | server.respondWith('/text', [ 106 | 200, 107 | {'Content-Type': 'text/html'}, 108 | 'Hello, world.' 109 | ]); 110 | 111 | server.respondWith('/404', [404, {}, '']); 112 | server.respondWith('/500', [ 113 | 500, 114 | {'Content-Type': 'application/json'}, 115 | '{"message": "There was an internal server error."}' 116 | ]); 117 | }); 118 | 119 | after(function() { 120 | server.restore(); 121 | }); 122 | 123 | it('Parse application/json', function(end) { 124 | Jax 125 | .get('/json') 126 | .done(function(err, res) { 127 | var data = res.data; 128 | 129 | assert.isObject(data); 130 | assert.propertyVal(data, 'foo', 'bar'); 131 | assert.strictEqual(res.status, 200); 132 | 133 | end(); 134 | }); 135 | }); 136 | 137 | it('Parse application/x-www-form-urlencoded', function(end) { 138 | Jax 139 | .get('/form') 140 | .done(function(err, res) { 141 | var data = res.data; 142 | 143 | assert.isObject(data); 144 | assert.propertyVal(data, 'foo', 'bar'); 145 | assert.strictEqual(res.status, 200); 146 | 147 | end(); 148 | }); 149 | }); 150 | 151 | it('Parse text/html', function(end) { 152 | Jax 153 | .get('/text') 154 | .done(function(err, res) { 155 | var data = res.data; 156 | 157 | assert.isString(data); 158 | assert.strictEqual(data, 'Hello, world.'); 159 | assert.strictEqual(res.status, 200); 160 | 161 | end(); 162 | }); 163 | }); 164 | 165 | it('Parse 404', function(end) { 166 | Jax 167 | .get('/404') 168 | .done(function(err, res) { 169 | assert.isObject(res.error); 170 | assert.isNull(res.data); 171 | assert.strictEqual(res.status, 404); 172 | 173 | end(); 174 | }); 175 | }); 176 | 177 | it('Parse 500', function(end) { 178 | Jax 179 | .get('/500') 180 | .done(function(err, res) { 181 | assert.isObject(res.error); 182 | assert.strictEqual(res.status, 500); 183 | 184 | end(); 185 | }); 186 | }); 187 | }); 188 | 189 | describe('Jax Request Object', function() { 190 | before(function() { 191 | server = sinon.fakeServer.create(); 192 | server.autoRespond = true; 193 | 194 | server.respondWith('/json', [ 195 | 200, 196 | {'Content-Type': 'application/json'}, 197 | '{"foo":"bar"}' 198 | ]); 199 | 200 | // I think I can use regex here? 201 | server.respondWith('/json?foo=bar', [ 202 | 200, 203 | {'Content-Type': 'application/json'}, 204 | '{"foo":"bar"}' 205 | ]); 206 | }); 207 | 208 | after(function() { 209 | server.restore(); 210 | }); 211 | 212 | describe('Setting headers | .header()', function() { 213 | it('res.request.headers should be an object', function(end) { 214 | Jax 215 | .get('/json') 216 | .header('foo', 'bar') 217 | .done(function(err, res) { 218 | assert.isObject(res.request.headers); 219 | end(); 220 | }); 221 | }); 222 | 223 | it('method should accept 2 params as strings', function(end) { 224 | Jax 225 | .get('/json') 226 | .header('foo', 'bar') 227 | .done(function(err, res) { 228 | assert.propertyVal(res.request.headers, 'foo', 'bar'); 229 | end(); 230 | }); 231 | }); 232 | 233 | it('method should accept 1 param as object', function(end) { 234 | Jax 235 | .get('/json') 236 | .header({ 237 | foo: 'bar' 238 | }) 239 | .done(function(err, res) { 240 | assert.propertyVal(res.request.headers, 'foo', 'bar'); 241 | end(); 242 | }); 243 | }); 244 | }); 245 | 246 | describe('Sending payload data | .data()', function() { 247 | it('res.request.requestData should be an object', function(end) { 248 | Jax 249 | .post('/json') 250 | .done(function(err, res) { 251 | assert.isObject(res.request.requestData); 252 | end(); 253 | }); 254 | }); 255 | 256 | it('method should accept 2 params as strings', function(end) { 257 | Jax 258 | .post('/json') 259 | .data('foo', 'bar') 260 | .done(function(err, res) { 261 | assert.propertyVal(res.request.requestData, 'foo', 'bar'); 262 | end(); 263 | }); 264 | }); 265 | 266 | it('method should accept 1 param as object', function(end) { 267 | Jax 268 | .post('/json') 269 | .data({ 270 | foo: 'bar' 271 | }) 272 | .done(function(err, res) { 273 | assert.propertyVal(res.request.requestData, 'foo', 'bar'); 274 | end(); 275 | }); 276 | }); 277 | }); 278 | 279 | describe('Setting url queries | .query()', function() { 280 | it('res.request.queries should be an array', function(end) { 281 | Jax 282 | .get('/json') 283 | .query('foo=bar') 284 | .done(function(err, res) { 285 | assert.isArray(res.request.queries); 286 | end(); 287 | }); 288 | }); 289 | 290 | it('method should accept 1 param as string', function(end) { 291 | Jax 292 | .get('/json') 293 | .query('foo=bar') 294 | .done(function(err, res) { 295 | assert.include(res.request.queries, 'foo=bar'); 296 | end(); 297 | }); 298 | }); 299 | 300 | it('method should accept 1 param as object', function(end) { 301 | Jax 302 | .get('/json') 303 | .query({ 304 | foo: 'bar' 305 | }) 306 | .done(function(err, res) { 307 | assert.include(res.request.queries, 'foo=bar'); 308 | end(); 309 | }); 310 | }); 311 | }); 312 | 313 | describe('Setting content type header | .type()', function() { 314 | it('Content-Type should be application/json', function(end) { 315 | Jax 316 | .get('/json') 317 | .type('application/json') 318 | .done(function(err, res) { 319 | assert.equal(res.request.headers['Content-Type'], 'application/json'); 320 | end(); 321 | }); 322 | }); 323 | }); 324 | 325 | describe('Setting CORS on Request | .cors()', function() { 326 | it('XHR should be set to handle CORS', function(end) { 327 | Jax 328 | .get('/json') 329 | .cors() 330 | .done(function(err, res) { 331 | assert.equal(res.request.headers['X-CORS-Enabled'], true); 332 | end(); 333 | }); 334 | }); 335 | }); 336 | 337 | describe('Setting no cache headers | .nocache()', function() { 338 | it('Appropriate headers sent so response is not cached', function(end) { 339 | Jax 340 | .get('/json') 341 | .nocache() 342 | .done(function(err, res) { 343 | var headers = res.request.headers; 344 | 345 | assert.equal(headers['Cache-Control'], 'no-cache'); 346 | assert.equal(headers['Expires'], -1); 347 | assert.equal(headers['X-Requested-With'], 'XMLHttpRequest'); 348 | end(); 349 | }); 350 | }); 351 | }); 352 | }); 353 | -------------------------------------------------------------------------------- /lib/jax.js: -------------------------------------------------------------------------------- 1 | /* global define */ 2 | /* global module */ 3 | /* global exports */ 4 | 5 | (function(root, factory) { 6 | if (typeof define === 'function' && define.amd) { 7 | define(factory); 8 | } else if (typeof exports === 'object') { 9 | module.exports = factory; 10 | } else { 11 | root.Jax = factory(root); 12 | } 13 | })(this, function(root) { 14 | 'use strict'; 15 | 16 | var round = Math.round; 17 | 18 | /** 19 | * Utility library 20 | */ 21 | var util = {}; 22 | 23 | /** 24 | * Determine if value is an object 25 | * @param {*} val The value you want to check against 26 | * @return {boolean} Returns true/false 27 | */ 28 | util.isObject = function(val) { 29 | return val instanceof Object; 30 | }; 31 | 32 | /** 33 | * Determine if value is a function 34 | * @param {*} val The value you want to check against 35 | * @return {boolean} Returns true/false 36 | */ 37 | util.isFunction = function(val) { 38 | return val && {}.toString.call(val) == '[object Function]'; 39 | }; 40 | 41 | /** 42 | * Determine size of passed in data 43 | * @param {*} data Data we want to size, can be object or array. 44 | * @return {Number} The number of items in data 45 | */ 46 | util.size = function(data) { 47 | var len = 0; 48 | 49 | if (data) { 50 | if (util.isObject(data)) { 51 | for (var key in data) { 52 | if (data.hasOwnProperty(key)) { 53 | len++; 54 | } 55 | } 56 | } else { 57 | len = data.length; 58 | } 59 | } 60 | 61 | return len; 62 | }; 63 | 64 | /** 65 | * Get a cross browser XHR instance 66 | * @return {Object|Boolean} Our XHR object or false 67 | */ 68 | util.getXhr = function() { 69 | var transport = false; 70 | var ieVersions = [ 71 | 'Microsoft.XMLHTTP', 72 | 'Msxml2.XMLHTTP.6.0', 73 | 'Msxml2.XMLHTTP.3.0', 74 | 'Msxml2.XMLHTTP' 75 | ]; 76 | 77 | if ('XMLHttpRequest' in root) { 78 | transport = new root.XMLHttpRequest(); 79 | } else { 80 | for (var i = 0, len = ieVersions.length; i !== len; i++) { 81 | try { 82 | transport = new root.ActiveXObject(ieVersions[i]); 83 | } catch (e) { 84 | transport = false; 85 | } 86 | } 87 | } 88 | 89 | return transport; 90 | }; 91 | 92 | /** 93 | * Serialize an object into a URL encoded string 94 | * @param {Object} obj The object we want to serialize 95 | * @return {string} URL encoded string with values separated by & character 96 | */ 97 | util.serialize = function(obj) { 98 | // dont parse if its not an object 99 | if (!util.isObject(obj)) { 100 | return ''; 101 | } 102 | 103 | var pairs = []; 104 | var serializedstring = ''; 105 | 106 | for (var key in obj) { 107 | if (obj.hasOwnProperty(key)) { 108 | var encodedKey = encodeURIComponent(key); 109 | var encodedVal = encodeURIComponent(obj[key]); 110 | 111 | pairs.push(encodedKey + '=' + encodedVal); 112 | } 113 | } 114 | 115 | serializedstring = pairs.join('&'); 116 | 117 | return serializedstring; 118 | }; 119 | 120 | /** 121 | * Unserialize a url encoded string into object format 122 | * @param {string} str The string we wish to unserialize 123 | * @return {Object} Formatted object 124 | */ 125 | util.unserialize = function(str) { 126 | var formatted = {}; 127 | var pairs = str.split('&'); 128 | 129 | for (var i = 0, len = pairs.length; i !== len; i++) { 130 | var split = pairs[i].split('='); 131 | var key = decodeURIComponent(split[0]); 132 | var val = decodeURIComponent(split[1]); 133 | 134 | formatted[key] = val; 135 | } 136 | 137 | return formatted; 138 | }; 139 | 140 | /** 141 | * Return a nicely formatted response object to the user 142 | * @constructor 143 | * @param {Object} req A instance of our Request class 144 | */ 145 | function Response(req) { 146 | this.request = req; 147 | this.status = this.request.xhr.status; 148 | this.headers = this.parseHeaders(); 149 | this.data = this.parseData(); 150 | this.raw = this.request.xhr.responseText || null; 151 | 152 | var shortStatus = round(this.status / 100); 153 | if (shortStatus === 4 || shortStatus === 5) { 154 | this.error = this.parseError(); 155 | } 156 | } 157 | 158 | /** 159 | * Parse response headers into object format 160 | * @return {Object} A nicely formatted object with all headers fields 161 | */ 162 | Response.prototype.parseHeaders = function() { 163 | var str = this.request.xhr.getAllResponseHeaders(); 164 | var headers = {}; 165 | 166 | if (str) { 167 | var pairs = str.split('\u000d\u000a'); 168 | 169 | for (var i = 0, len = pairs.length; i !== len; i++) { 170 | var header = pairs[i]; 171 | var index = header.indexOf('\u003a\u0020'); 172 | 173 | if (index > 0) { 174 | var key = header.substring(0, index); 175 | var val = header.substring(index + 2); 176 | 177 | headers[key] = val; 178 | } 179 | } 180 | } 181 | 182 | // I might want to remove this... 183 | if (!headers['Content-Type']) { 184 | headers['Content-Type'] = 'application/json'; 185 | } 186 | 187 | return headers; 188 | }; 189 | 190 | /** 191 | * Format the return responseText from XHR object 192 | * @return {Object|string|null} Formatted data 193 | */ 194 | Response.prototype.parseData = function() { 195 | var data = this.request.xhr.responseText || null; 196 | var type = this.headers['Content-Type']; 197 | 198 | if (data) { 199 | // determine parser method based on content type 200 | var parsers = { 201 | 'application/x-www-form-urlencoded': util.unserialize, 202 | 'application/json': JSON.parse 203 | }; 204 | 205 | if (parsers[type]) { 206 | data = parsers[type](data); 207 | } 208 | } 209 | 210 | return data; 211 | }; 212 | 213 | /** 214 | * Format the error object if error status was thrown 215 | * @return {object} Error object 216 | */ 217 | Response.prototype.parseError = function() { 218 | var method = this.request.method; 219 | var url = this.request.url; 220 | 221 | return new Error('Cannot ' + method + ' ' + url); 222 | }; 223 | 224 | /** 225 | * Forms a request object with correct XHR headers and payload data 226 | * @constructor 227 | * @param {string} method The HTTP request method 228 | * @param {string} url The HTTP request url 229 | */ 230 | function Request(method, url) { 231 | this.url = url; 232 | this.method = method; 233 | this.xhr = util.getXhr(); 234 | 235 | this.headers = {}; 236 | this.requestData = {}; 237 | this.queries = []; 238 | } 239 | 240 | /** 241 | * Generic request header setter 242 | * @param {Object|string} key Can be a header key or object of key/vals 243 | * @param {string|boolean} [val] Optional value of key (if string) 244 | * @return {Object} Our Request instance for chaining 245 | */ 246 | Request.prototype.header = function(key, val) { 247 | if (key) { 248 | if (util.isObject(key)) { 249 | for (var headerKey in key) { 250 | if (key.hasOwnProperty(headerKey)) { 251 | this.headers[headerKey] = key[headerKey]; 252 | } 253 | } 254 | } else { 255 | this.headers[key] = val; 256 | } 257 | } 258 | 259 | return this; 260 | }; 261 | 262 | /** 263 | * Explicitly set request header Content-Type 264 | * @param {string} val The Content-Type value 265 | * @return {Object} Our Request instance for chaining 266 | */ 267 | Request.prototype.type = function(val) { 268 | if (val) { 269 | this.headers['Content-Type'] = val; 270 | } 271 | 272 | return this; 273 | }; 274 | 275 | /** 276 | * Enable CORS for our XHR instance 277 | * @return {Object} Our Request instance for chaining 278 | */ 279 | Request.prototype.cors = function() { 280 | this.header('X-CORS-Enabled', true); 281 | this.cors = true; 282 | 283 | return this; 284 | }; 285 | 286 | /** 287 | * Explicitly set request headers to disable caching of response 288 | * @return {Object} Our Request instance for chaining 289 | */ 290 | Request.prototype.nocache = function() { 291 | this.header({ 292 | 'Cache-Control': 'no-cache', 293 | 'Expires': '-1', 294 | 'X-Requested-With': 'XMLHttpRequest' 295 | }); 296 | 297 | return this; 298 | }; 299 | 300 | /** 301 | * Set query data in the request URL 302 | * @param {string|Object} val The value we want to set in the URL 303 | * @return {Object} Our Request instance for chaining 304 | */ 305 | Request.prototype.query = function(val) { 306 | if (val) { 307 | if (util.isObject(val)) { 308 | val = util.serialize(val); 309 | } 310 | 311 | this.queries.push(val); 312 | } 313 | 314 | return this; 315 | }; 316 | 317 | /** 318 | * Send payload data with request 319 | * @param {string|Object} key Can be a object key or object of key/vals 320 | * @param {string} val Value of key 321 | * @return {Object} Our Request instance for chaining 322 | */ 323 | Request.prototype.data = function(key, val) { 324 | var hasData = util.size(this.requestData); 325 | 326 | if (util.isObject(key)) { 327 | if (hasData) { 328 | for (var item in key) { 329 | if (key.hasOwnProperty(item)) { 330 | this.requestData[item] = key[item]; 331 | } 332 | } 333 | } else { 334 | this.requestData = key; 335 | } 336 | } else { 337 | this.requestData[key] = val; 338 | } 339 | 340 | return this; 341 | }; 342 | 343 | /** 344 | * Helper method to format data before sending the request 345 | */ 346 | Request.prototype.formatData = function() { 347 | var data = this.requestData; 348 | 349 | if (util.size(data)) { 350 | if (this.headers['Content-Type'] === 'application/json') { 351 | data = JSON.stringify(data); 352 | } else { 353 | data = util.serialize(data); 354 | } 355 | } 356 | }; 357 | 358 | /** 359 | * Helper method to format url queries before sending the request 360 | */ 361 | Request.prototype.formatQueries = function() { 362 | var queries = this.queries; 363 | var url = this.url; 364 | 365 | if (util.size(queries)) { 366 | var query = queries.join('&'); 367 | var start = url.indexOf('?') > -1 ? '&' : '?'; 368 | 369 | url += start + query; 370 | } 371 | }; 372 | 373 | /** 374 | * Helper method to format headers before sending the request 375 | */ 376 | Request.prototype.formatHeaders = function() { 377 | var headers = this.headers; 378 | var xhr = this.xhr; 379 | 380 | for (var field in headers) { 381 | if (headers.hasOwnProperty(field)) { 382 | xhr.setRequestHeader(field, headers[field]); 383 | } 384 | } 385 | }; 386 | 387 | /** 388 | * Format and send request 389 | * @param {Object} callback Handles the response 390 | */ 391 | Request.prototype.done = function(callback) { 392 | var _this = this; 393 | var xhr = this.xhr; 394 | 395 | xhr.onreadystatechange = function() { 396 | if (xhr.readyState === 4) { 397 | if (xhr.status === 0) { 398 | var err = new Error('Cross domain request is not allowed'); 399 | callback(err, null); 400 | } 401 | 402 | try { 403 | var response = new Response(_this); 404 | callback(null, response); 405 | } catch (e) { 406 | var err = new Error('Unable to parse response'); 407 | err.original = e; 408 | callback(err, null); 409 | } 410 | } 411 | }; 412 | 413 | // must be before opening to make sure URL is formatted correctly 414 | this.formatQueries(); 415 | 416 | xhr.open(this.method, this.url, true); 417 | 418 | if (this.cors) { 419 | xhr.withCredentials = true; 420 | } 421 | 422 | this.formatHeaders(); 423 | this.formatData(); 424 | 425 | xhr.send(this.requestData); 426 | }; 427 | 428 | /** 429 | * Jax constructor 430 | * @constructor 431 | * @param {string} method The HTTP request method 432 | * @param {string} url The HTTP request url 433 | * @param {Object|null} callback Optional callback for syntax sugar 434 | */ 435 | function Jax(method, url, callback) { 436 | if (callback) { 437 | return new Request(method, url).done(callback); 438 | } 439 | 440 | return new Request(method, url); 441 | } 442 | 443 | /** 444 | * GET HTTP request method 445 | * @param {string} url The HTTP request method 446 | * @param {Object|null} callback Optional callback for syntax sugar 447 | * @return {Object} An instance of our Request Object 448 | */ 449 | Jax.get = function(url, callback) { 450 | callback = util.isFunction(callback) ? callback : null; 451 | 452 | return new Jax('GET', url, callback); 453 | }; 454 | 455 | /** 456 | * POST HTTP request method 457 | * @param {string} url The HTTP request method 458 | * @param {Object|null} callback Optional callback for syntax sugar 459 | * @return {Object} An instance of our Request Object 460 | */ 461 | Jax.post = function(url, callback) { 462 | callback = util.isFunction(callback) ? callback : null; 463 | 464 | return new Jax('POST', url, callback); 465 | }; 466 | 467 | /** 468 | * PUT HTTP request method 469 | * @param {string} url The HTTP request method 470 | * @param {Object|null} callback Optional callback for syntax sugar 471 | * @return {Object} An instance of our Request Object 472 | */ 473 | Jax.put = function(url, callback) { 474 | callback = util.isFunction(callback) ? callback : null; 475 | 476 | return new Jax('PUT', url, callback); 477 | }; 478 | 479 | /** 480 | * DELETE HTTP request method 481 | * @param {string} url The HTTP request method 482 | * @param {Object|null} callback Optional callback for syntax sugar 483 | * @return {Object} An instance of our Request Object 484 | */ 485 | Jax.del = function(url, callback) { 486 | callback = util.isFunction(callback) ? callback : null; 487 | 488 | return new Jax('DELETE', url, callback); 489 | }; 490 | 491 | Jax.Request = Request; 492 | Jax.Response = Response; 493 | 494 | return Jax; 495 | 496 | }); 497 | -------------------------------------------------------------------------------- /test/fixtures/chai.js: -------------------------------------------------------------------------------- 1 | !function(){function require(a){var b=require.modules[a];if(!b)throw new Error('failed to require "'+a+'"');return"exports"in b||"function"!=typeof b.definition||(b.client=b.component=!0,b.definition.call(this,b.exports={},b),delete b.definition),b.exports}require.loader="component",require.helper={},require.helper.semVerSort=function(a,b){for(var c=a.version.split("."),d=b.version.split("."),e=0;eg?1:-1;var h=c[e].substr((""+f).length),i=d[e].substr((""+g).length);if(""===h&&""!==i)return 1;if(""!==h&&""===i)return-1;if(""!==h&&""!==i)return h>i?1:-1}return 0},require.latest=function(a,b){function c(a){throw new Error('failed to find latest module of "'+a+'"')}var d=/(.*)~(.*)@v?(\d+\.\d+\.\d+[^\/]*)$/,e=/(.*)~(.*)/;e.test(a)||c(a);for(var f=Object.keys(require.modules),g=[],h=[],i=0;i0){var m=g.sort(require.helper.semVerSort).pop().name;return b===!0?m:require(m)}var m=h.pop().name;return b===!0?m:require(m)},require.modules={},require.register=function(a,b){require.modules[a]={definition:b}},require.define=function(a,b){require.modules[a]={exports:b}},require.register("chaijs~assertion-error@1.0.0",function(a,b){function c(){function b(b,c){Object.keys(c).forEach(function(d){~a.indexOf(d)||(b[d]=c[d])})}var a=[].slice.call(arguments);return function(){for(var a=[].slice.call(arguments),c=0,d={};c=0;d--)if(i=e[d],!f(a[i],b[i],c))return!1;return!0}var d,c=require("chaijs~type-detect@0.1.1");try{d=require("buffer").Buffer}catch(e){d={},d.isBuffer=function(){return!1}}b.exports=f}),require.register("chai",function(a,b){b.exports=require("chai/lib/chai.js")}),require.register("chai/lib/chai.js",function(a,b){var c=[],a=b.exports={};a.version="1.10.0",a.AssertionError=require("chaijs~assertion-error@1.0.0");var d=require("chai/lib/chai/utils/index.js");a.use=function(a){return~c.indexOf(a)||(a(this,d),c.push(a)),this};var e=require("chai/lib/chai/config.js");a.config=e;var f=require("chai/lib/chai/assertion.js");a.use(f);var g=require("chai/lib/chai/core/assertions.js");a.use(g);var h=require("chai/lib/chai/interface/expect.js");a.use(h);var i=require("chai/lib/chai/interface/should.js");a.use(i);var j=require("chai/lib/chai/interface/assert.js");a.use(j)}),require.register("chai/lib/chai/assertion.js",function(a,b){var c=require("chai/lib/chai/config.js"),d=function(){};b.exports=function(a,b){function g(a,b,c){f(this,"ssfi",c||arguments.callee),f(this,"object",a),f(this,"message",b)}var e=a.AssertionError,f=b.flag;a.Assertion=g,Object.defineProperty(g,"includeStack",{get:function(){return console.warn("Assertion.includeStack is deprecated, use chai.config.includeStack instead."),c.includeStack},set:function(a){console.warn("Assertion.includeStack is deprecated, use chai.config.includeStack instead."),c.includeStack=a}}),Object.defineProperty(g,"showDiff",{get:function(){return console.warn("Assertion.showDiff is deprecated, use chai.config.showDiff instead."),c.showDiff},set:function(a){console.warn("Assertion.showDiff is deprecated, use chai.config.showDiff instead."),c.showDiff=a}}),g.addProperty=function(a,c){b.addProperty(this.prototype,a,c)},g.addMethod=function(a,c){b.addMethod(this.prototype,a,c)},g.addChainableMethod=function(a,c,d){b.addChainableMethod(this.prototype,a,c,d)},g.addChainableNoop=function(a,c){b.addChainableMethod(this.prototype,a,d,c)},g.overwriteProperty=function(a,c){b.overwriteProperty(this.prototype,a,c)},g.overwriteMethod=function(a,c){b.overwriteMethod(this.prototype,a,c)},g.overwriteChainableMethod=function(a,c,d){b.overwriteChainableMethod(this.prototype,a,c,d)},g.prototype.assert=function(a,d,g,h,i,j){var k=b.test(this,arguments);if(!0!==j&&(j=!1),!0!==c.showDiff&&(j=!1),!k){var d=b.getMessage(this,arguments),l=b.getActual(this,arguments);throw new e(d,{actual:l,expected:h,showDiff:j},c.includeStack?this.assert:f(this,"ssfi"))}},Object.defineProperty(g.prototype,"_obj",{get:function(){return f(this,"object")},set:function(a){f(this,"object",a)}})}}),require.register("chai/lib/chai/config.js",function(a,b){b.exports={includeStack:!1,showDiff:!0,truncateThreshold:40}}),require.register("chai/lib/chai/core/assertions.js",function(a,b){b.exports=function(a,b){function f(a,c){c&&e(this,"message",c),a=a.toLowerCase();var d=e(this,"object"),f=~["a","e","i","o","u"].indexOf(a.charAt(0))?"an ":"a ";this.assert(a===b.type(d),"expected #{this} to be "+f+a,"expected #{this} not to be "+f+a)}function g(){e(this,"contains",!0)}function h(a,d){d&&e(this,"message",d);var f=e(this,"object"),g=!1;if("array"===b.type(f)&&"object"===b.type(a)){for(var h in f)if(b.eql(f[h],a)){g=!0;break}}else if("object"===b.type(a)){if(!e(this,"negate")){for(var i in a)new c(f).property(i,a[i]);return}var j={};for(var i in a)j[i]=f[i];g=b.eql(j,a)}else g=f&&~f.indexOf(a);this.assert(g,"expected #{this} to include "+b.inspect(a),"expected #{this} to not include "+b.inspect(a))}function i(){var a=e(this,"object"),b=Object.prototype.toString.call(a);this.assert("[object Arguments]"===b,"expected #{this} to be arguments but got "+b,"expected #{this} to not be arguments")}function j(a,b){b&&e(this,"message",b);var c=e(this,"object");return e(this,"deep")?this.eql(a):(this.assert(a===c,"expected #{this} to equal #{exp}","expected #{this} to not equal #{exp}",a,this._obj,!0),void 0)}function k(a,c){c&&e(this,"message",c),this.assert(b.eql(a,e(this,"object")),"expected #{this} to deeply equal #{exp}","expected #{this} to not deeply equal #{exp}",a,this._obj,!0)}function l(a,b){b&&e(this,"message",b);var d=e(this,"object");if(e(this,"doLength")){new c(d,b).to.have.property("length");var f=d.length;this.assert(f>a,"expected #{this} to have a length above #{exp} but got #{act}","expected #{this} to not have a length above #{exp}",a,f)}else this.assert(d>a,"expected #{this} to be above "+a,"expected #{this} to be at most "+a)}function m(a,b){b&&e(this,"message",b);var d=e(this,"object");if(e(this,"doLength")){new c(d,b).to.have.property("length");var f=d.length;this.assert(f>=a,"expected #{this} to have a length at least #{exp} but got #{act}","expected #{this} to have a length below #{exp}",a,f)}else this.assert(d>=a,"expected #{this} to be at least "+a,"expected #{this} to be below "+a)}function n(a,b){b&&e(this,"message",b);var d=e(this,"object");if(e(this,"doLength")){new c(d,b).to.have.property("length");var f=d.length;this.assert(a>f,"expected #{this} to have a length below #{exp} but got #{act}","expected #{this} to not have a length below #{exp}",a,f)}else this.assert(a>d,"expected #{this} to be below "+a,"expected #{this} to be at least "+a)}function o(a,b){b&&e(this,"message",b);var d=e(this,"object");if(e(this,"doLength")){new c(d,b).to.have.property("length");var f=d.length;this.assert(a>=f,"expected #{this} to have a length at most #{exp} but got #{act}","expected #{this} to have a length above #{exp}",a,f)}else this.assert(a>=d,"expected #{this} to be at most "+a,"expected #{this} to be above "+a)}function p(a,c){c&&e(this,"message",c);var d=b.getName(a);this.assert(e(this,"object")instanceof a,"expected #{this} to be an instance of "+d,"expected #{this} to not be an instance of "+d)}function q(a,c){c&&e(this,"message",c);var d=e(this,"object");this.assert(d.hasOwnProperty(a),"expected #{this} to have own property "+b.inspect(a),"expected #{this} to not have own property "+b.inspect(a))}function r(){e(this,"doLength",!0)}function s(a,b){b&&e(this,"message",b);var d=e(this,"object");new c(d,b).to.have.property("length");var f=d.length;this.assert(f==a,"expected #{this} to have a length of #{exp} but got #{act}","expected #{this} to not have a length of #{act}",a,f)}function t(a){var d,c=e(this,"object"),f=!0;if(a=a instanceof Array?a:Array.prototype.slice.call(arguments),!a.length)throw new Error("keys required");var g=Object.keys(c),h=a,i=a.length;if(f=a.every(function(a){return~g.indexOf(a)}),e(this,"negate")||e(this,"contains")||(f=f&&a.length==g.length),i>1){a=a.map(function(a){return b.inspect(a)});var j=a.pop();d=a.join(", ")+", and "+j}else d=b.inspect(a[0]);d=(i>1?"keys ":"key ")+d,d=(e(this,"contains")?"contain ":"have ")+d,this.assert(f,"expected #{this} to "+d,"expected #{this} to not "+d,h.sort(),g.sort(),!0)}function u(a,d,f){f&&e(this,"message",f);var g=e(this,"object");new c(g,f).is.a("function");var h=!1,i=null,j=null,k=null;0===arguments.length?(d=null,a=null):a&&(a instanceof RegExp||"string"==typeof a)?(d=a,a=null):a&&a instanceof Error?(i=a,a=null,d=null):"function"==typeof a?(j=a.prototype.name||a.name,"Error"===j&&a!==Error&&(j=(new a).name)):a=null;try{g()}catch(l){if(i)return this.assert(l===i,"expected #{this} to throw #{exp} but #{act} was thrown","expected #{this} to not throw #{exp}",i instanceof Error?i.toString():i,l instanceof Error?l.toString():l),e(this,"object",l),this;if(a&&(this.assert(l instanceof a,"expected #{this} to throw #{exp} but #{act} was thrown","expected #{this} to not throw #{exp} but #{act} was thrown",j,l instanceof Error?l.toString():l),!d))return e(this,"object",l),this;var m="object"===b.type(l)&&"message"in l?l.message:""+l;if(null!=m&&d&&d instanceof RegExp)return this.assert(d.exec(m),"expected #{this} to throw error matching #{exp} but got #{act}","expected #{this} to throw error not matching #{exp}",d,m),e(this,"object",l),this;if(null!=m&&d&&"string"==typeof d)return this.assert(~m.indexOf(d),"expected #{this} to throw error including #{exp} but got #{act}","expected #{this} to throw error not including #{act}",d,m),e(this,"object",l),this;h=!0,k=l}var n="",o=null!==j?j:i?"#{exp}":"an error";h&&(n=" but #{act} was thrown"),this.assert(h===!0,"expected #{this} to throw "+o+n,"expected #{this} to not throw "+o+n,i instanceof Error?i.toString():i,k instanceof Error?k.toString():k),e(this,"object",k)}function v(a,b,c){return a.every(function(a){return c?b.some(function(b){return c(a,b)}):-1!==b.indexOf(a)})}var c=a.Assertion,e=(Object.prototype.toString,b.flag);["to","be","been","is","and","has","have","with","that","at","of","same"].forEach(function(a){c.addProperty(a,function(){return this})}),c.addProperty("not",function(){e(this,"negate",!0)}),c.addProperty("deep",function(){e(this,"deep",!0)}),c.addChainableMethod("an",f),c.addChainableMethod("a",f),c.addChainableMethod("include",h,g),c.addChainableMethod("contain",h,g),c.addChainableNoop("ok",function(){this.assert(e(this,"object"),"expected #{this} to be truthy","expected #{this} to be falsy")}),c.addChainableNoop("true",function(){this.assert(!0===e(this,"object"),"expected #{this} to be true","expected #{this} to be false",this.negate?!1:!0)}),c.addChainableNoop("false",function(){this.assert(!1===e(this,"object"),"expected #{this} to be false","expected #{this} to be true",this.negate?!0:!1)}),c.addChainableNoop("null",function(){this.assert(null===e(this,"object"),"expected #{this} to be null","expected #{this} not to be null")}),c.addChainableNoop("undefined",function(){this.assert(void 0===e(this,"object"),"expected #{this} to be undefined","expected #{this} not to be undefined")}),c.addChainableNoop("exist",function(){this.assert(null!=e(this,"object"),"expected #{this} to exist","expected #{this} to not exist")}),c.addChainableNoop("empty",function(){var a=e(this,"object"),b=a;Array.isArray(a)||"string"==typeof object?b=a.length:"object"==typeof a&&(b=Object.keys(a).length),this.assert(!b,"expected #{this} to be empty","expected #{this} not to be empty")}),c.addChainableNoop("arguments",i),c.addChainableNoop("Arguments",i),c.addMethod("equal",j),c.addMethod("equals",j),c.addMethod("eq",j),c.addMethod("eql",k),c.addMethod("eqls",k),c.addMethod("above",l),c.addMethod("gt",l),c.addMethod("greaterThan",l),c.addMethod("least",m),c.addMethod("gte",m),c.addMethod("below",n),c.addMethod("lt",n),c.addMethod("lessThan",n),c.addMethod("most",o),c.addMethod("lte",o),c.addMethod("within",function(a,b,d){d&&e(this,"message",d);var f=e(this,"object"),g=a+".."+b;if(e(this,"doLength")){new c(f,d).to.have.property("length");var h=f.length;this.assert(h>=a&&b>=h,"expected #{this} to have a length within "+g,"expected #{this} to not have a length within "+g)}else this.assert(f>=a&&b>=f,"expected #{this} to be within "+g,"expected #{this} to not be within "+g)}),c.addMethod("instanceof",p),c.addMethod("instanceOf",p),c.addMethod("property",function(a,c,d){d&&e(this,"message",d);var f=e(this,"deep")?"deep property ":"property ",g=e(this,"negate"),h=e(this,"object"),i=e(this,"deep")?b.getPathValue(a,h):h[a];if(g&&void 0!==c){if(void 0===i)throw d=null!=d?d+": ":"",new Error(d+b.inspect(h)+" has no "+f+b.inspect(a))}else this.assert(void 0!==i,"expected #{this} to have a "+f+b.inspect(a),"expected #{this} to not have "+f+b.inspect(a));void 0!==c&&this.assert(c===i,"expected #{this} to have a "+f+b.inspect(a)+" of #{exp}, but got #{act}","expected #{this} to not have a "+f+b.inspect(a)+" of #{act}",c,i),e(this,"object",i)}),c.addMethod("ownProperty",q),c.addMethod("haveOwnProperty",q),c.addChainableMethod("length",s,r),c.addMethod("lengthOf",s),c.addMethod("match",function(a,b){b&&e(this,"message",b);var c=e(this,"object");this.assert(a.exec(c),"expected #{this} to match "+a,"expected #{this} not to match "+a)}),c.addMethod("string",function(a,d){d&&e(this,"message",d);var f=e(this,"object");new c(f,d).is.a("string"),this.assert(~f.indexOf(a),"expected #{this} to contain "+b.inspect(a),"expected #{this} to not contain "+b.inspect(a))}),c.addMethod("keys",t),c.addMethod("key",t),c.addMethod("throw",u),c.addMethod("throws",u),c.addMethod("Throw",u),c.addMethod("respondTo",function(a,c){c&&e(this,"message",c);var d=e(this,"object"),f=e(this,"itself"),g="function"!==b.type(d)||f?d[a]:d.prototype[a];this.assert("function"==typeof g,"expected #{this} to respond to "+b.inspect(a),"expected #{this} to not respond to "+b.inspect(a))}),c.addProperty("itself",function(){e(this,"itself",!0)}),c.addMethod("satisfy",function(a,c){c&&e(this,"message",c);var d=e(this,"object"),f=a(d);this.assert(f,"expected #{this} to satisfy "+b.objDisplay(a),"expected #{this} to not satisfy"+b.objDisplay(a),this.negate?!1:!0,f)}),c.addMethod("closeTo",function(a,d,f){f&&e(this,"message",f);var g=e(this,"object");if(new c(g,f).is.a("number"),"number"!==b.type(a)||"number"!==b.type(d))throw new Error("the arguments to closeTo must be numbers");this.assert(Math.abs(g-a)<=d,"expected #{this} to be close to "+a+" +/- "+d,"expected #{this} not to be close to "+a+" +/- "+d)}),c.addMethod("members",function(a,d){d&&e(this,"message",d);var f=e(this,"object");new c(f).to.be.an("array"),new c(a).to.be.an("array");var g=e(this,"deep")?b.eql:void 0;return e(this,"contains")?this.assert(v(a,f,g),"expected #{this} to be a superset of #{act}","expected #{this} to not be a superset of #{act}",f,a):(this.assert(v(f,a,g)&&v(a,f,g),"expected #{this} to have the same members as #{act}","expected #{this} to not have the same members as #{act}",f,a),void 0)})}}),require.register("chai/lib/chai/interface/assert.js",function(exports,module){module.exports=function(chai,util){var Assertion=chai.Assertion,flag=util.flag,assert=chai.assert=function(a,b){var c=new Assertion(null,null,chai.assert);c.assert(a,b,"[ negation message unavailable ]")};assert.fail=function(a,b,c,d){throw c=c||"assert.fail()",new chai.AssertionError(c,{actual:a,expected:b,operator:d},assert.fail)},assert.ok=function(a,b){new Assertion(a,b).is.ok},assert.notOk=function(a,b){new Assertion(a,b).is.not.ok},assert.equal=function(a,b,c){var d=new Assertion(a,c,assert.equal);d.assert(b==flag(d,"object"),"expected #{this} to equal #{exp}","expected #{this} to not equal #{act}",b,a)},assert.notEqual=function(a,b,c){var d=new Assertion(a,c,assert.notEqual);d.assert(b!=flag(d,"object"),"expected #{this} to not equal #{exp}","expected #{this} to equal #{act}",b,a)},assert.strictEqual=function(a,b,c){new Assertion(a,c).to.equal(b)},assert.notStrictEqual=function(a,b,c){new Assertion(a,c).to.not.equal(b)},assert.deepEqual=function(a,b,c){new Assertion(a,c).to.eql(b)},assert.notDeepEqual=function(a,b,c){new Assertion(a,c).to.not.eql(b)},assert.isTrue=function(a,b){new Assertion(a,b).is["true"]},assert.isFalse=function(a,b){new Assertion(a,b).is["false"]},assert.isNull=function(a,b){new Assertion(a,b).to.equal(null)},assert.isNotNull=function(a,b){new Assertion(a,b).to.not.equal(null)},assert.isUndefined=function(a,b){new Assertion(a,b).to.equal(void 0)},assert.isDefined=function(a,b){new Assertion(a,b).to.not.equal(void 0)},assert.isFunction=function(a,b){new Assertion(a,b).to.be.a("function")},assert.isNotFunction=function(a,b){new Assertion(a,b).to.not.be.a("function")},assert.isObject=function(a,b){new Assertion(a,b).to.be.a("object")},assert.isNotObject=function(a,b){new Assertion(a,b).to.not.be.a("object")},assert.isArray=function(a,b){new Assertion(a,b).to.be.an("array")},assert.isNotArray=function(a,b){new Assertion(a,b).to.not.be.an("array")},assert.isString=function(a,b){new Assertion(a,b).to.be.a("string")},assert.isNotString=function(a,b){new Assertion(a,b).to.not.be.a("string")},assert.isNumber=function(a,b){new Assertion(a,b).to.be.a("number")},assert.isNotNumber=function(a,b){new Assertion(a,b).to.not.be.a("number")},assert.isBoolean=function(a,b){new Assertion(a,b).to.be.a("boolean")},assert.isNotBoolean=function(a,b){new Assertion(a,b).to.not.be.a("boolean")},assert.typeOf=function(a,b,c){new Assertion(a,c).to.be.a(b)},assert.notTypeOf=function(a,b,c){new Assertion(a,c).to.not.be.a(b)},assert.instanceOf=function(a,b,c){new Assertion(a,c).to.be.instanceOf(b)},assert.notInstanceOf=function(a,b,c){new Assertion(a,c).to.not.be.instanceOf(b)},assert.include=function(a,b,c){new Assertion(a,c,assert.include).include(b)},assert.notInclude=function(a,b,c){new Assertion(a,c,assert.notInclude).not.include(b)},assert.match=function(a,b,c){new Assertion(a,c).to.match(b)},assert.notMatch=function(a,b,c){new Assertion(a,c).to.not.match(b)},assert.property=function(a,b,c){new Assertion(a,c).to.have.property(b)},assert.notProperty=function(a,b,c){new Assertion(a,c).to.not.have.property(b)},assert.deepProperty=function(a,b,c){new Assertion(a,c).to.have.deep.property(b)},assert.notDeepProperty=function(a,b,c){new Assertion(a,c).to.not.have.deep.property(b)},assert.propertyVal=function(a,b,c,d){new Assertion(a,d).to.have.property(b,c)},assert.propertyNotVal=function(a,b,c,d){new Assertion(a,d).to.not.have.property(b,c)},assert.deepPropertyVal=function(a,b,c,d){new Assertion(a,d).to.have.deep.property(b,c)},assert.deepPropertyNotVal=function(a,b,c,d){new Assertion(a,d).to.not.have.deep.property(b,c)},assert.lengthOf=function(a,b,c){new Assertion(a,c).to.have.length(b)},assert.Throw=function(a,b,c,d){("string"==typeof b||b instanceof RegExp)&&(c=b,b=null);var e=new Assertion(a,d).to.Throw(b,c);return flag(e,"object")},assert.doesNotThrow=function(a,b,c){"string"==typeof b&&(c=b,b=null),new Assertion(a,c).to.not.Throw(b)},assert.operator=function(val,operator,val2,msg){if(!~["==","===",">",">=","<","<=","!=","!=="].indexOf(operator))throw new Error('Invalid operator "'+operator+'"');var test=new Assertion(eval(val+operator+val2),msg);test.assert(!0===flag(test,"object"),"expected "+util.inspect(val)+" to be "+operator+" "+util.inspect(val2),"expected "+util.inspect(val)+" to not be "+operator+" "+util.inspect(val2))},assert.closeTo=function(a,b,c,d){new Assertion(a,d).to.be.closeTo(b,c)},assert.sameMembers=function(a,b,c){new Assertion(a,c).to.have.same.members(b)},assert.includeMembers=function(a,b,c){new Assertion(a,c).to.include.members(b)},assert.ifError=function(a,b){new Assertion(a,b).to.not.be.ok},function a(b,c){return assert[c]=assert[b],a}("Throw","throw")("Throw","throws")}}),require.register("chai/lib/chai/interface/expect.js",function(a,b){b.exports=function(a){a.expect=function(b,c){return new a.Assertion(b,c)}}}),require.register("chai/lib/chai/interface/should.js",function(a,b){b.exports=function(a){function d(){function a(){return this instanceof String||this instanceof Number?new c(this.constructor(this),null,a):this instanceof Boolean?new c(1==this,null,a):new c(this,null,a)}function b(a){Object.defineProperty(this,"should",{value:a,enumerable:!0,configurable:!0,writable:!0})}Object.defineProperty(Object.prototype,"should",{set:b,get:a,configurable:!0});var d={};return d.equal=function(a,b,d){new c(a,d).to.equal(b)},d.Throw=function(a,b,d,e){new c(a,e).to.Throw(b,d)},d.exist=function(a,b){new c(a,b).to.exist},d.not={},d.not.equal=function(a,b,d){new c(a,d).to.not.equal(b)},d.not.Throw=function(a,b,d,e){new c(a,e).to.not.Throw(b,d)},d.not.exist=function(a,b){new c(a,b).to.not.exist},d["throw"]=d.Throw,d.not["throw"]=d.not.Throw,d}var c=a.Assertion;a.should=d,a.Should=d}}),require.register("chai/lib/chai/utils/addChainableMethod.js",function(a,b){var c=require("chai/lib/chai/utils/transferFlags.js"),d=require("chai/lib/chai/utils/flag.js"),e=require("chai/lib/chai/config.js"),f="__proto__"in Object,g=/^(?:length|name|arguments|caller)$/,h=Function.prototype.call,i=Function.prototype.apply;b.exports=function(a,b,j,k){"function"!=typeof k&&(k=function(){});var l={method:j,chainingBehavior:k};a.__methods||(a.__methods={}),a.__methods[b]=l,Object.defineProperty(a,b,{get:function(){l.chainingBehavior.call(this);var b=function m(){var a=d(this,"ssfi");a&&e.includeStack===!1&&d(this,"ssfi",m);var b=l.method.apply(this,arguments);return void 0===b?this:b};if(f){var j=b.__proto__=Object.create(this);j.call=h,j.apply=i}else{var k=Object.getOwnPropertyNames(a);k.forEach(function(c){if(!g.test(c)){var d=Object.getOwnPropertyDescriptor(a,c);Object.defineProperty(b,c,d)}})}return c(this,b),b},configurable:!0})}}),require.register("chai/lib/chai/utils/addMethod.js",function(a,b){var c=require("chai/lib/chai/config.js"),d=require("chai/lib/chai/utils/flag.js");b.exports=function(a,b,e){a[b]=function(){var f=d(this,"ssfi");f&&c.includeStack===!1&&d(this,"ssfi",a[b]);var g=e.apply(this,arguments);return void 0===g?this:g}}}),require.register("chai/lib/chai/utils/addProperty.js",function(a,b){b.exports=function(a,b,c){Object.defineProperty(a,b,{get:function(){var a=c.call(this);return void 0===a?this:a},configurable:!0})}}),require.register("chai/lib/chai/utils/flag.js",function(a,b){b.exports=function(a,b,c){var d=a.__flags||(a.__flags=Object.create(null));return 3!==arguments.length?d[b]:(d[b]=c,void 0)}}),require.register("chai/lib/chai/utils/getActual.js",function(a,b){b.exports=function(a,b){return b.length>4?b[4]:a._obj}}),require.register("chai/lib/chai/utils/getEnumerableProperties.js",function(a,b){b.exports=function(a){var b=[];for(var c in a)b.push(c);return b}}),require.register("chai/lib/chai/utils/getMessage.js",function(a,b){var c=require("chai/lib/chai/utils/flag.js"),d=require("chai/lib/chai/utils/getActual.js"),f=(require("chai/lib/chai/utils/inspect.js"),require("chai/lib/chai/utils/objDisplay.js"));b.exports=function(a,b){var e=c(a,"negate"),g=c(a,"object"),h=b[3],i=d(a,b),j=e?b[2]:b[1],k=c(a,"message");return"function"==typeof j&&(j=j()),j=j||"",j=j.replace(/#{this}/g,f(g)).replace(/#{act}/g,f(i)).replace(/#{exp}/g,f(h)),k?k+": "+j:j}}),require.register("chai/lib/chai/utils/getName.js",function(a,b){b.exports=function(a){if(a.name)return a.name;var b=/^\s?function ([^(]*)\(/.exec(a);return b&&b[1]?b[1]:""}}),require.register("chai/lib/chai/utils/getPathValue.js",function(a,b){function d(a){var b=a.replace(/\[/g,".["),c=b.match(/(\\\.|[^.]+?)+/g);return c.map(function(a){var b=/\[(\d+)\]$/,c=b.exec(a);return c?{i:parseFloat(c[1])}:{p:a}})}function e(a,b){for(var d,c=b,e=0,f=a.length;f>e;e++){var g=a[e];c?("undefined"!=typeof g.p?c=c[g.p]:"undefined"!=typeof g.i&&(c=c[g.i]),e==f-1&&(d=c)):d=void 0}return d}b.exports=function(a,b){var c=d(a);return e(c,b)}}),require.register("chai/lib/chai/utils/getProperties.js",function(a,b){b.exports=function(){function c(a){-1===b.indexOf(a)&&b.push(a)}for(var b=Object.getOwnPropertyNames(subject),d=Object.getPrototypeOf(subject);null!==d;)Object.getOwnPropertyNames(d).forEach(c),d=Object.getPrototypeOf(d);return b}}),require.register("chai/lib/chai/utils/index.js",function(a,b){var a=b.exports={};a.test=require("chai/lib/chai/utils/test.js"),a.type=require("chai/lib/chai/utils/type.js"),a.getMessage=require("chai/lib/chai/utils/getMessage.js"),a.getActual=require("chai/lib/chai/utils/getActual.js"),a.inspect=require("chai/lib/chai/utils/inspect.js"),a.objDisplay=require("chai/lib/chai/utils/objDisplay.js"),a.flag=require("chai/lib/chai/utils/flag.js"),a.transferFlags=require("chai/lib/chai/utils/transferFlags.js"),a.eql=require("chaijs~deep-eql@0.1.3"),a.getPathValue=require("chai/lib/chai/utils/getPathValue.js"),a.getName=require("chai/lib/chai/utils/getName.js"),a.addProperty=require("chai/lib/chai/utils/addProperty.js"),a.addMethod=require("chai/lib/chai/utils/addMethod.js"),a.overwriteProperty=require("chai/lib/chai/utils/overwriteProperty.js"),a.overwriteMethod=require("chai/lib/chai/utils/overwriteMethod.js"),a.addChainableMethod=require("chai/lib/chai/utils/addChainableMethod.js"),a.overwriteChainableMethod=require("chai/lib/chai/utils/overwriteChainableMethod.js")}),require.register("chai/lib/chai/utils/inspect.js",function(a,b){function f(a,b,c){var e={showHidden:b,seen:[],stylize:function(a){return a}};return h(e,a,"undefined"==typeof c?2:c)}function h(b,f,r){if(f&&"function"==typeof f.inspect&&f.inspect!==a.inspect&&(!f.constructor||f.constructor.prototype!==f)){var s=f.inspect(r);return"string"!=typeof s&&(s=h(b,s,r)),s}var t=i(b,f);if(t)return t;if(g(f)){if("outerHTML"in f)return f.outerHTML;try{if(document.xmlVersion){var u=new XMLSerializer;return u.serializeToString(f)}var v="http://www.w3.org/1999/xhtml",w=document.createElementNS(v,"_");return w.appendChild(f.cloneNode(!1)),html=w.innerHTML.replace("><",">"+f.innerHTML+"<"),w.innerHTML="",html}catch(x){}}var y=e(f),z=b.showHidden?d(f):y;if(0===z.length||q(f)&&(1===z.length&&"stack"===z[0]||2===z.length&&"description"===z[0]&&"stack"===z[1])){if("function"==typeof f){var A=c(f),B=A?": "+A:"";return b.stylize("[Function"+B+"]","special")}if(o(f))return b.stylize(RegExp.prototype.toString.call(f),"regexp");if(p(f))return b.stylize(Date.prototype.toUTCString.call(f),"date");if(q(f))return j(f)}var C="",D=!1,E=["{","}"];if(n(f)&&(D=!0,E=["[","]"]),"function"==typeof f){var A=c(f),B=A?": "+A:"";C=" [Function"+B+"]"}if(o(f)&&(C=" "+RegExp.prototype.toString.call(f)),p(f)&&(C=" "+Date.prototype.toUTCString.call(f)),q(f))return j(f);if(0===z.length&&(!D||0==f.length))return E[0]+C+E[1];if(0>r)return o(f)?b.stylize(RegExp.prototype.toString.call(f),"regexp"):b.stylize("[Object]","special");b.seen.push(f);var F;return F=D?k(b,f,r,y,z):z.map(function(a){return l(b,f,r,y,a,D)}),b.seen.pop(),m(F,C,E)}function i(a,b){switch(typeof b){case"undefined":return a.stylize("undefined","undefined");case"string":var c="'"+JSON.stringify(b).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return a.stylize(c,"string");case"number":return 0===b&&1/b===-1/0?a.stylize("-0","number"):a.stylize(""+b,"number");case"boolean":return a.stylize(""+b,"boolean")}return null===b?a.stylize("null","null"):void 0}function j(a){return"["+Error.prototype.toString.call(a)+"]"}function k(a,b,c,d,e){for(var f=[],g=0,h=b.length;h>g;++g)Object.prototype.hasOwnProperty.call(b,String(g))?f.push(l(a,b,c,d,String(g),!0)):f.push("");return e.forEach(function(e){e.match(/^\d+$/)||f.push(l(a,b,c,d,e,!0))}),f}function l(a,b,c,d,e,f){var g,i;if(b.__lookupGetter__&&(b.__lookupGetter__(e)?i=b.__lookupSetter__(e)?a.stylize("[Getter/Setter]","special"):a.stylize("[Getter]","special"):b.__lookupSetter__(e)&&(i=a.stylize("[Setter]","special"))),d.indexOf(e)<0&&(g="["+e+"]"),i||(a.seen.indexOf(b[e])<0?(i=null===c?h(a,b[e],null):h(a,b[e],c-1),i.indexOf("\n")>-1&&(i=f?i.split("\n").map(function(a){return" "+a}).join("\n").substr(2):"\n"+i.split("\n").map(function(a){return" "+a}).join("\n"))):i=a.stylize("[Circular]","special")),"undefined"==typeof g){if(f&&e.match(/^\d+$/))return i;g=JSON.stringify(""+e),g.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(g=g.substr(1,g.length-2),g=a.stylize(g,"name")):(g=g.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),g=a.stylize(g,"string"))}return g+": "+i}function m(a,b,c){var d=0,e=a.reduce(function(a,b){return d++,b.indexOf("\n")>=0&&d++,a+b.length+1},0);return e>60?c[0]+(""===b?"":b+"\n ")+" "+a.join(",\n ")+" "+c[1]:c[0]+b+" "+a.join(", ")+" "+c[1]}function n(a){return Array.isArray(a)||"object"==typeof a&&"[object Array]"===r(a)}function o(a){return"object"==typeof a&&"[object RegExp]"===r(a)}function p(a){return"object"==typeof a&&"[object Date]"===r(a)}function q(a){return"object"==typeof a&&"[object Error]"===r(a)}function r(a){return Object.prototype.toString.call(a)}var c=require("chai/lib/chai/utils/getName.js"),d=require("chai/lib/chai/utils/getProperties.js"),e=require("chai/lib/chai/utils/getEnumerableProperties.js");b.exports=f;var g=function(a){return"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&1===a.nodeType&&"string"==typeof a.nodeName}}),require.register("chai/lib/chai/utils/objDisplay.js",function(a,b){var c=require("chai/lib/chai/utils/inspect.js"),d=require("chai/lib/chai/config.js");b.exports=function(a){var b=c(a),e=Object.prototype.toString.call(a); 2 | if(d.truncateThreshold&&b.length>=d.truncateThreshold){if("[object Function]"===e)return a.name&&""!==a.name?"[Function: "+a.name+"]":"[Function]";if("[object Array]"===e)return"[ Array("+a.length+") ]";if("[object Object]"===e){var f=Object.keys(a),g=f.length>2?f.splice(0,2).join(", ")+", ...":f.join(", ");return"{ Object ("+g+") }"}return b}return b}}),require.register("chai/lib/chai/utils/overwriteMethod.js",function(a,b){b.exports=function(a,b,c){var d=a[b],e=function(){return this};d&&"function"==typeof d&&(e=d),a[b]=function(){var a=c(e).apply(this,arguments);return void 0===a?this:a}}}),require.register("chai/lib/chai/utils/overwriteProperty.js",function(a,b){b.exports=function(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b),e=function(){};d&&"function"==typeof d.get&&(e=d.get),Object.defineProperty(a,b,{get:function(){var a=c(e).call(this);return void 0===a?this:a},configurable:!0})}}),require.register("chai/lib/chai/utils/overwriteChainableMethod.js",function(a,b){b.exports=function(a,b,c,d){var e=a.__methods[b],f=e.chainingBehavior;e.chainingBehavior=function(){var a=d(f).call(this);return void 0===a?this:a};var g=e.method;e.method=function(){var a=c(g).apply(this,arguments);return void 0===a?this:a}}}),require.register("chai/lib/chai/utils/test.js",function(a,b){var c=require("chai/lib/chai/utils/flag.js");b.exports=function(a,b){var d=c(a,"negate"),e=b[0];return d?!e:e}}),require.register("chai/lib/chai/utils/transferFlags.js",function(a,b){b.exports=function(a,b,c){var d=a.__flags||(a.__flags=Object.create(null));b.__flags||(b.__flags=Object.create(null)),c=3===arguments.length?c:!0;for(var e in d)(c||"object"!==e&&"ssfi"!==e&&"message"!=e)&&(b.__flags[e]=d[e])}}),require.register("chai/lib/chai/utils/type.js",function(a,b){var c={"[object Arguments]":"arguments","[object Array]":"array","[object Date]":"date","[object Function]":"function","[object Number]":"number","[object RegExp]":"regexp","[object String]":"string"};b.exports=function(a){var b=Object.prototype.toString.call(a);return c[b]?c[b]:null===a?"null":void 0===a?"undefined":a===Object(a)?"object":typeof a}}),"object"==typeof exports?module.exports=require("chai"):"function"==typeof define&&define.amd?define("chai",[],function(){return require("chai")}):(this||window).chai=require("chai")}(); 3 | -------------------------------------------------------------------------------- /test/fixtures/mocha.js: -------------------------------------------------------------------------------- 1 | !function(){function a(b){var c=a.resolve(b),d=a.modules[c];if(!d)throw new Error('failed to require "'+b+'"');return d.exports||(d.exports={},d.call(d.exports,d,d.exports,a.relative(c))),d.exports}function o(){for(var a=(new c).getTime();m.length&&(new c).getTime()-a<100;)m.shift()();n=m.length?d(o,0):null}a.modules={},a.resolve=function(b){var c=b,d=b+".js",e=b+"/index.js";return a.modules[d]&&d||a.modules[e]&&e||c},a.register=function(b,c){a.modules[b]=c},a.relative=function(b){return function(c){if("."!=c.charAt(0))return a(c);var d=b.split("/"),e=c.split("/");d.pop();for(var f=0;f/g,">"),b=b.replace(/"/g,""")}var d=function(a){this.ignoreWhitespace=a};d.prototype={diff:function(b,c){if(c===b)return[{value:c}];if(!c)return[{value:b,removed:!0}];if(!b)return[{value:c,added:!0}];c=this.tokenize(c),b=this.tokenize(b);var d=c.length,e=b.length,f=d+e,g=[{newPos:-1,components:[]}],h=this.extractCommon(g[0],c,b,0);if(g[0].newPos+1>=d&&h+1>=e)return g[0].components;for(var i=1;f>=i;i++)for(var j=-1*i;i>=j;j+=2){var k,l=g[j-1],m=g[j+1];h=(m?m.newPos:0)-j,l&&(g[j-1]=void 0);var n=l&&l.newPos+1=0&&e>h;if(n||o){!n||o&&l.newPos=d&&h+1>=e)return k.components;g[j]=k}else g[j]=void 0}},pushComponent:function(a,b,c,d){var e=a[a.length-1];e&&e.added===c&&e.removed===d?a[a.length-1]={value:this.join(e.value,b),added:c,removed:d}:a.push({value:b,added:c,removed:d})},extractCommon:function(a,b,c,d){for(var e=b.length,f=c.length,g=a.newPos,h=g-d;e>g+1&&f>h+1&&this.equals(b[g+1],c[h+1]);)g++,h++,this.pushComponent(a.components,b[g],void 0,void 0);return a.newPos=g,h},equals:function(a,b){var c=/\S/;return!this.ignoreWhitespace||c.test(a)||c.test(b)?a===b:!0},join:function(a,b){return a+b},tokenize:function(a){return a}};var e=new d,f=new d(!0),g=new d;f.tokenize=g.tokenize=function(a){return b(a.split(/(\s+|\b)/))};var h=new d(!0);h.tokenize=function(a){return b(a.split(/([{}:;,]|\s+)/))};var i=new d;return i.tokenize=function(a){return a.split(/^/m)},{Diff:d,diffChars:function(a,b){return e.diff(a,b)},diffWords:function(a,b){return f.diff(a,b)},diffWordsWithSpace:function(a,b){return g.diff(a,b)},diffLines:function(a,b){return i.diff(a,b)},diffCss:function(a,b){return h.diff(a,b)},createPatch:function(a,b,c,d,e){function h(a){return a.map(function(a){return" "+a})}function j(a,b,c){var d=g[g.length-2],e=b===g.length-2,f=b===g.length-3&&(c.added!==d.added||c.removed!==d.removed);/\n$/.test(c.value)||!e&&!f||a.push("\\ No newline at end of file")}var f=[];f.push("Index: "+a),f.push("==================================================================="),f.push("--- "+a+("undefined"==typeof d?"":" "+d)),f.push("+++ "+a+("undefined"==typeof e?"":" "+e));var g=i.diff(b,c);g[g.length-1].value||g.pop(),g.push({value:"",lines:[]});for(var k=0,l=0,m=[],n=1,o=1,p=0;p=0;g--){for(var j=d[g],k=0;k"):e.removed&&b.push(""),b.push(c(e.value)),e.added?b.push(""):e.removed&&b.push("")}return b.join("")},convertChangesToDMP:function(a){for(var c,b=[],d=0;df;f++)if(c[f]===b||c[f].listener&&c[f].listener===b){e=f;break}if(0>e)return this;c.splice(e,1),c.length||delete this.$events[a]}else(c===b||c.listener&&c.listener===b)&&delete this.$events[a]}return this},e.prototype.removeAllListeners=function(a){return void 0===a?(this.$events={},this):(this.$events&&this.$events[a]&&(this.$events[a]=null),this)},e.prototype.listeners=function(a){return this.$events||(this.$events={}),this.$events[a]||(this.$events[a]=[]),d(this.$events[a])||(this.$events[a]=[this.$events[a]]),this.$events[a]},e.prototype.emit=function(a){if(!this.$events)return!1;var b=this.$events[a];if(!b)return!1;var c=[].slice.call(arguments,1);if("function"==typeof b)b.apply(this,c);else{if(!d(b))return!1;for(var e=b.slice(),f=0,g=e.length;g>f;f++)e[f].apply(this,c)}return!0}}),a.register("browser/fs.js",function(){}),a.register("browser/glob.js",function(){}),a.register("browser/path.js",function(){}),a.register("browser/progress.js",function(a){function d(){this.percent=0,this.size(0),this.fontSize(11),this.font("helvetica, arial, sans-serif")}a.exports=d,d.prototype.size=function(a){return this._size=a,this},d.prototype.text=function(a){return this._text=a,this},d.prototype.fontSize=function(a){return this._fontSize=a,this},d.prototype.font=function(a){return this._font=a,this},d.prototype.update=function(a){return this.percent=a,this},d.prototype.draw=function(a){try{var b=Math.min(this.percent,100),c=this._size,d=c/2,e=d,f=d,g=d-1,h=this._fontSize;a.font=h+"px "+this._font;var i=2*Math.PI*(b/100);a.clearRect(0,0,c,c),a.strokeStyle="#9f9f9f",a.beginPath(),a.arc(e,f,g,0,i,!1),a.stroke(),a.strokeStyle="#eee",a.beginPath(),a.arc(e,f,g-1,0,i,!0),a.stroke();var j=this._text||(0|b)+"%",k=a.measureText(j).width;a.fillText(j,e-k/2+1,f+h/2-1)}catch(l){}return this}}),a.register("browser/tty.js",function(a,c){c.isatty=function(){return!0},c.getWindowSize=function(){return"innerHeight"in b?[b.innerHeight,b.innerWidth]:[640,480]}}),a.register("context.js",function(a){function d(){}a.exports=d,d.prototype.runnable=function(a){return 0==arguments.length?this._runnable:(this.test=this._runnable=a,this)},d.prototype.timeout=function(a){return 0===arguments.length?this.runnable().timeout():(this.runnable().timeout(a),this)},d.prototype.enableTimeouts=function(a){return this.runnable().enableTimeouts(a),this},d.prototype.slow=function(a){return this.runnable().slow(a),this},d.prototype.inspect=function(){return JSON.stringify(this,function(a,b){return"_runnable"!=a&&"test"!=a?b:void 0},2)}}),a.register("hook.js",function(a,b,c){function e(a,b){d.call(this,a,b),this.type="hook"}function f(){}var d=c("./runnable");a.exports=e,f.prototype=d.prototype,e.prototype=new f,e.prototype.constructor=e,e.prototype.error=function(a){if(0==arguments.length){var a=this._error;return this._error=null,a}this._error=a}}),a.register("interfaces/bdd.js",function(a,b,c){var d=c("../suite"),e=c("../test"),g=(c("../utils"),c("browser/escape-string-regexp"));a.exports=function(a){var b=[a];a.on("pre-require",function(a,c,f){a.before=function(a,c){b[0].beforeAll(a,c)},a.after=function(a,c){b[0].afterAll(a,c)},a.beforeEach=function(a,c){b[0].beforeEach(a,c)},a.afterEach=function(a,c){b[0].afterEach(a,c)},a.describe=a.context=function(a,e){var f=d.create(b[0],a);return f.file=c,b.unshift(f),e.call(f),b.shift(),f},a.xdescribe=a.xcontext=a.describe.skip=function(a,c){var e=d.create(b[0],a);e.pending=!0,b.unshift(e),c.call(e),b.shift()},a.describe.only=function(b,c){var d=a.describe(b,c);return f.grep(d.fullTitle()),d},a.it=a.specify=function(a,d){var f=b[0];f.pending&&(d=null);var g=new e(a,d);return g.file=c,f.addTest(g),g},a.it.only=function(b,c){var d=a.it(b,c),e="^"+g(d.fullTitle())+"$";return f.grep(new RegExp(e)),d},a.xit=a.xspecify=a.it.skip=function(b){a.it(b)}})}}),a.register("interfaces/exports.js",function(a,b,c){var d=c("../suite"),e=c("../test");a.exports=function(a){function c(a,f){var g;for(var h in a)if("function"==typeof a[h]){var i=a[h];switch(h){case"before":b[0].beforeAll(i);break;case"after":b[0].afterAll(i);break;case"beforeEach":b[0].beforeEach(i);break;case"afterEach":b[0].afterEach(i);break;default:var j=new e(h,i);j.file=f,b[0].addTest(j)}}else g=d.create(b[0],h),b.unshift(g),c(a[h]),b.shift()}var b=[a];a.on("require",c)}}),a.register("interfaces/index.js",function(a,b,c){b.bdd=c("./bdd"),b.tdd=c("./tdd"),b.qunit=c("./qunit"),b.exports=c("./exports")}),a.register("interfaces/qunit.js",function(a,b,c){var d=c("../suite"),e=c("../test"),f=c("browser/escape-string-regexp");c("../utils"),a.exports=function(a){var b=[a];a.on("pre-require",function(a,c,g){a.before=function(a,c){b[0].beforeAll(a,c)},a.after=function(a,c){b[0].afterAll(a,c)},a.beforeEach=function(a,c){b[0].beforeEach(a,c)},a.afterEach=function(a,c){b[0].afterEach(a,c)},a.suite=function(a){b.length>1&&b.shift();var e=d.create(b[0],a);return e.file=c,b.unshift(e),e},a.suite.only=function(b,c){var d=a.suite(b,c);g.grep(d.fullTitle())},a.test=function(a,d){var f=new e(a,d);return f.file=c,b[0].addTest(f),f},a.test.only=function(b,c){var d=a.test(b,c),e="^"+f(d.fullTitle())+"$";g.grep(new RegExp(e))},a.test.skip=function(b){a.test(b)}})}}),a.register("interfaces/tdd.js",function(a,b,c){var d=c("../suite"),e=c("../test"),f=c("browser/escape-string-regexp");c("../utils"),a.exports=function(a){var b=[a];a.on("pre-require",function(a,c,g){a.setup=function(a,c){b[0].beforeEach(a,c)},a.teardown=function(a,c){b[0].afterEach(a,c)},a.suiteSetup=function(a,c){b[0].beforeAll(a,c)},a.suiteTeardown=function(a,c){b[0].afterAll(a,c)},a.suite=function(a,e){var f=d.create(b[0],a);return f.file=c,b.unshift(f),e.call(f),b.shift(),f},a.suite.skip=function(a,c){var e=d.create(b[0],a);e.pending=!0,b.unshift(e),c.call(e),b.shift()},a.suite.only=function(b,c){var d=a.suite(b,c);g.grep(d.fullTitle())},a.test=function(a,d){var f=b[0];f.pending&&(d=null);var g=new e(a,d);return g.file=c,f.addTest(g),g},a.test.only=function(b,c){var d=a.test(b,c),e="^"+f(d.fullTitle())+"$";g.grep(new RegExp(e))},a.test.skip=function(b){a.test(b)}})}}),a.register("mocha.js",function(a,c,d){function k(a){return __dirname+"/../images/"+a+".png"}function l(a){a=a||{},this.files=[],this.options=a,this.grep(a.grep),this.suite=new c.Suite("",new c.Context),this.ui(a.ui),this.bail(a.bail),this.reporter(a.reporter),null!=a.timeout&&this.timeout(a.timeout),this.useColors(a.useColors),null!==a.enableTimeouts&&this.enableTimeouts(a.enableTimeouts),a.slow&&this.slow(a.slow),this.suite.on("pre-require",function(a){c.afterEach=a.afterEach||a.teardown,c.after=a.after||a.suiteTeardown,c.beforeEach=a.beforeEach||a.setup,c.before=a.before||a.suiteSetup,c.describe=a.describe||a.suite,c.it=a.it||a.test,c.setup=a.setup||a.beforeEach,c.suiteSetup=a.suiteSetup||a.before,c.suiteTeardown=a.suiteTeardown||a.after,c.suite=a.suite||a.describe,c.teardown=a.teardown||a.afterEach,c.test=a.test||a.it})}var e=d("browser/path"),f=d("browser/escape-string-regexp"),g=d("./utils");if(c=a.exports=l,"undefined"!=typeof h&&"function"==typeof h.cwd){var i=e.join,j=h.cwd();a.paths.push(j,i(j,"node_modules"))}c.utils=g,c.interfaces=d("./interfaces"),c.reporters=d("./reporters"),c.Runnable=d("./runnable"),c.Context=d("./context"),c.Runner=d("./runner"),c.Suite=d("./suite"),c.Hook=d("./hook"),c.Test=d("./test"),l.prototype.bail=function(a){return 0==arguments.length&&(a=!0),this.suite.bail(a),this},l.prototype.addFile=function(a){return this.files.push(a),this},l.prototype.reporter=function(a){if("function"==typeof a)this._reporter=a;else{a=a||"spec";var b;try{b=d("./reporters/"+a)}catch(c){}if(!b)try{b=d(a)}catch(c){}if(b||"teamcity"!==a||console.warn("The Teamcity reporter was moved to a package named mocha-teamcity-reporter (https://npmjs.org/package/mocha-teamcity-reporter)."),!b)throw new Error('invalid reporter "'+a+'"');this._reporter=b}return this},l.prototype.ui=function(a){if(a=a||"bdd",this._ui=c.interfaces[a],!this._ui)try{this._ui=d(a)}catch(b){}if(!this._ui)throw new Error('invalid interface "'+a+'"');return this._ui=this._ui(this.suite),this},l.prototype.loadFiles=function(a){var c=this,f=this.suite,g=this.files.length;this.files.forEach(function(h){h=e.resolve(h),f.emit("pre-require",b,h,c),f.emit("require",d(h),h,c),f.emit("post-require",b,h,c),--g||a&&a()})},l.prototype._growl=function(a,b){var c=d("growl");a.on("end",function(){var d=b.stats;if(d.failures){var e=d.failures+" of "+a.total+" tests failed";c(e,{name:"mocha",title:"Failed",image:k("error")})}else c(d.passes+" tests passed in "+d.duration+"ms",{name:"mocha",title:"Passed",image:k("ok")})})},l.prototype.grep=function(a){return this.options.grep="string"==typeof a?new RegExp(f(a)):a,this},l.prototype.invert=function(){return this.options.invert=!0,this},l.prototype.ignoreLeaks=function(a){return this.options.ignoreLeaks=!!a,this},l.prototype.checkLeaks=function(){return this.options.ignoreLeaks=!1,this},l.prototype.growl=function(){return this.options.growl=!0,this},l.prototype.globals=function(a){return this.options.globals=(this.options.globals||[]).concat(a),this},l.prototype.useColors=function(a){return this.options.useColors=arguments.length&&void 0!=a?a:!0,this},l.prototype.useInlineDiffs=function(a){return this.options.useInlineDiffs=arguments.length&&void 0!=a?a:!1,this},l.prototype.timeout=function(a){return this.suite.timeout(a),this},l.prototype.slow=function(a){return this.suite.slow(a),this},l.prototype.enableTimeouts=function(a){return this.suite.enableTimeouts(arguments.length&&void 0!==a?a:!0),this},l.prototype.asyncOnly=function(){return this.options.asyncOnly=!0,this},l.prototype.noHighlighting=function(){return this.options.noHighlighting=!0,this},l.prototype.run=function(a){this.files.length&&this.loadFiles();var b=this.suite,d=this.options;d.files=this.files;var e=new c.Runner(b),f=new this._reporter(e,d);return e.ignoreLeaks=!1!==d.ignoreLeaks,e.asyncOnly=d.asyncOnly,d.grep&&e.grep(d.grep,d.invert),d.globals&&e.globals(d.globals),d.growl&&this._growl(e,f),c.reporters.Base.useColors=d.useColors,c.reporters.Base.inlineDiffs=d.useInlineDiffs,e.run(a)}}),a.register("ms.js",function(a){function i(a){var b=/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(a);if(b){var c=parseFloat(b[1]),i=(b[2]||"ms").toLowerCase();switch(i){case"years":case"year":case"y":return c*h;case"days":case"day":case"d":return c*g;case"hours":case"hour":case"h":return c*f;case"minutes":case"minute":case"m":return c*e;case"seconds":case"second":case"s":return c*d;case"ms":return c}}}function j(a){return a>=g?Math.round(a/g)+"d":a>=f?Math.round(a/f)+"h":a>=e?Math.round(a/e)+"m":a>=d?Math.round(a/d)+"s":a+"ms"}function k(a){return l(a,g,"day")||l(a,f,"hour")||l(a,e,"minute")||l(a,d,"second")||a+" ms"}function l(a,b,c){return b>a?void 0:1.5*b>a?Math.floor(a/b)+" "+c:Math.ceil(a/b)+" "+c+"s"}var d=1e3,e=60*d,f=60*e,g=24*f,h=365.25*g;a.exports=function(a,b){return b=b||{},"string"==typeof a?i(a):b["long"]?k(a):j(a)}}),a.register("reporters/base.js",function(a,c,d){function q(a){var c=this.stats={suites:0,tests:0,passes:0,pending:0,failures:0},d=this.failures=[];a&&(this.runner=a,a.stats=c,a.on("start",function(){c.start=new j}),a.on("suite",function(a){c.suites=c.suites||0,a.root||c.suites++}),a.on("test end",function(){c.tests=c.tests||0,c.tests++}),a.on("pass",function(a){c.passes=c.passes||0;var b=a.slow()/2;a.speed=a.duration>a.slow()?"slow":a.duration>b?"medium":"fast",c.passes++}),a.on("fail",function(a,b){c.failures=c.failures||0,c.failures++,a.err=b,d.push(a)}),a.on("end",function(){c.end=new j,c.duration=new j-c.start}),a.on("pending",function(){c.pending++}))}function r(a,b){return a=String(a),Array(b-a.length+1).join(" ")+a}function s(a,b){var c=u(a,"WordsWithSpace",b),d=c.split("\n");if(d.length>4){var e=String(d.length).length;c=d.map(function(a,b){return r(++b,e)+" |"+" "+a}).join("\n")}return c="\n"+p("diff removed","actual")+" "+p("diff added","expected")+"\n\n"+c+"\n",c=c.replace(/^/gm," ")}function t(a,b){function d(a){return b&&(a=v(a)),"+"===a[0]?c+w("diff added",a):"-"===a[0]?c+w("diff removed",a):a.match(/\@\@/)?null:a.match(/\\ No newline/)?null:c+a}function e(a){return null!=a}var c=" ";msg=f.createPatch("string",a.actual,a.expected);var g=msg.split("\n").splice(4);return"\n "+w("diff added","+ expected")+" "+w("diff removed","- actual")+"\n\n"+g.map(d).filter(e).join("\n")}function u(a,b,c){var d=c?v(a.actual):a.actual,e=c?v(a.expected):a.expected;return f["diff"+b](d,e).map(function(a){return a.added?w("diff added",a.value):a.removed?w("diff removed",a.value):a.value}).join("")}function v(a){return a.replace(/\t/g,"").replace(/\r/g,"").replace(/\n/g,"\n")}function w(a,b){return b.split("\n").map(function(b){return p(a,b)}).join("\n")}function x(a,b){return a=Object.prototype.toString.call(a),b=Object.prototype.toString.call(b),a==b}var e=d("browser/tty"),f=d("browser/diff"),g=d("../ms"),i=d("../utils"),j=b.Date;b.setTimeout,b.setInterval,b.clearTimeout,b.clearInterval;var o=e.isatty(1)&&e.isatty(2);c=a.exports=q,c.useColors=o||void 0!==h.env.MOCHA_COLORS,c.inlineDiffs=!1,c.colors={pass:90,fail:31,"bright pass":92,"bright fail":91,"bright yellow":93,pending:36,suite:0,"error title":0,"error message":31,"error stack":90,checkmark:32,fast:90,medium:33,slow:31,green:32,light:90,"diff gutter":90,"diff added":42,"diff removed":41},c.symbols={ok:"\u2713",err:"\u2716",dot:"\u2024"},"win32"==h.platform&&(c.symbols.ok="\u221a",c.symbols.err="\xd7",c.symbols.dot=".");var p=c.color=function(a,b){return c.useColors?"["+c.colors[a]+"m"+b+"":b};c.window={width:o?h.stdout.getWindowSize?h.stdout.getWindowSize(1)[0]:e.getWindowSize()[1]:75},c.cursor={hide:function(){o&&h.stdout.write("[?25l")},show:function(){o&&h.stdout.write("[?25h")},deleteLine:function(){o&&h.stdout.write("")},beginningOfLine:function(){o&&h.stdout.write("")},CR:function(){o?(c.cursor.deleteLine(),c.cursor.beginningOfLine()):h.stdout.write("\r")}},c.list=function(a){console.error(),a.forEach(function(a,b){var d=p("error title"," %s) %s:\n")+p("error message"," %s")+p("error stack","\n%s\n"),e=a.err,f=e.message||"",g=e.stack||f,h=g.indexOf(f)+f.length,j=g.slice(0,h),k=e.actual,l=e.expected,m=!0;if(e.uncaught&&(j="Uncaught "+j),e.showDiff&&x(k,l)&&(m=!1,e.actual=k=i.stringify(k),e.expected=l=i.stringify(l)),e.showDiff&&"string"==typeof k&&"string"==typeof l){d=p("error title"," %s) %s:\n%s")+p("error stack","\n%s\n");var n=f.match(/^([^:]+): expected/);j="\n "+p("error message",n?n[1]:j),j+=c.inlineDiffs?s(e,m):t(e,m)}g=g.slice(h?h+1:h).replace(/^/gm," "),console.error(d,b+1,a.fullTitle(),j,g)})},q.prototype.epilogue=function(){var c,a=this.stats;console.log(),c=p("bright pass"," ")+p("green"," %d passing")+p("light"," (%s)"),console.log(c,a.passes||0,g(a.duration)),a.pending&&(c=p("pending"," ")+p("pending"," %d pending"),console.log(c,a.pending)),a.failures&&(c=p("fail"," %d failing"),console.error(c,a.failures),q.list(this.failures),console.error()),console.log()}}),a.register("reporters/doc.js",function(a,b,c){function f(a){function h(){return Array(g).join(" ")}d.call(this,a);var g=(this.stats,a.total,2);a.on("suite",function(a){a.root||(++g,console.log('%s
',h()),++g,console.log("%s

%s

",h(),e.escape(a.title)),console.log("%s
",h()))}),a.on("suite end",function(a){a.root||(console.log("%s
",h()),--g,console.log("%s
",h()),--g)}),a.on("pass",function(a){console.log("%s
%s
",h(),e.escape(a.title));var b=e.escape(e.clean(a.fn.toString()));console.log("%s
%s
",h(),b)}),a.on("fail",function(a,b){console.log('%s
%s
',h(),e.escape(a.title));var c=e.escape(e.clean(a.fn.toString()));console.log('%s
%s
',h(),c),console.log('%s
%s
',h(),e.escape(b))})}var d=c("./base"),e=c("../utils");b=a.exports=f}),a.register("reporters/dot.js",function(a,b,c){function f(a){d.call(this,a);var b=this,f=(this.stats,0|.75*d.window.width),g=-1;a.on("start",function(){h.stdout.write("\n ")}),a.on("pending",function(){0==++g%f&&h.stdout.write("\n "),h.stdout.write(e("pending",d.symbols.dot))}),a.on("pass",function(a){0==++g%f&&h.stdout.write("\n "),"slow"==a.speed?h.stdout.write(e("bright yellow",d.symbols.dot)):h.stdout.write(e(a.speed,d.symbols.dot))}),a.on("fail",function(){0==++g%f&&h.stdout.write("\n "),h.stdout.write(e("fail",d.symbols.dot))}),a.on("end",function(){console.log(),b.epilogue()})}function g(){}var d=c("./base"),e=d.color;b=a.exports=f,g.prototype=d.prototype,f.prototype=new g,f.prototype.constructor=f}),a.register("reporters/html-cov.js",function(a,b,c){function f(a){var b=c("jade"),f=__dirname+"/templates/coverage.jade",i=e.readFileSync(f,"utf8"),j=b.compile(i,{filename:f}),k=this;d.call(this,a,!1),a.on("end",function(){h.stdout.write(j({cov:k.cov,coverageClass:g}))})}function g(a){return a>=75?"high":a>=50?"medium":a>=25?"low":"terrible"}var d=c("./json-cov"),e=c("browser/fs");b=a.exports=f}),a.register("reporters/html.js",function(a,c,d){function o(a){e.call(this,a);var A,B,b=this,c=this.stats,j=(a.total,r(n)),k=j.getElementsByTagName("li"),l=k[1].getElementsByTagName("em")[0],m=k[1].getElementsByTagName("a")[0],o=k[2].getElementsByTagName("em")[0],p=k[2].getElementsByTagName("a")[0],w=k[3].getElementsByTagName("em")[0],x=j.getElementsByTagName("canvas")[0],y=r('
    '),z=[y],C=document.getElementById("mocha");if(x.getContext){var D=window.devicePixelRatio||1;x.style.width=x.width,x.style.height=x.height,x.width*=D,x.height*=D,B=x.getContext("2d"),B.scale(D,D),A=new g}return C?(v(m,"click",function(){t();var a=/pass/.test(y.className)?"":" pass";y.className=y.className.replace(/fail|pass/g,"")+a,y.className.trim()&&s("test pass")}),v(p,"click",function(){t();var a=/fail/.test(y.className)?"":" fail";y.className=y.className.replace(/fail|pass/g,"")+a,y.className.trim()&&s("test fail")}),C.appendChild(j),C.appendChild(y),A&&A.size(40),a.on("suite",function(a){if(!a.root){var c=b.suiteURL(a),d=r('
  • %s

  • ',c,h(a.title));z[0].appendChild(d),z.unshift(document.createElement("ul")),d.appendChild(z[0])}}),a.on("suite end",function(a){a.root||z.shift()}),a.on("fail",function(b){"hook"==b.type&&a.emit("test end",b)}),a.on("test end",function(a){var d=0|100*(c.tests/this.total);A&&A.update(d).draw(B);var e=new i-c.start;if(u(l,c.passes),u(o,c.failures),u(w,(e/1e3).toFixed(2)),"passed"==a.state)var g=b.testURL(a),h=r('
  • %e%ems \u2023

  • ',a.speed,a.title,a.duration,g);else if(a.pending)var h=r('
  • %e

  • ',a.title);else{var h=r('
  • %e \u2023

  • ',a.title,encodeURIComponent(a.fullTitle())),j=a.err.stack||a.err.toString();~j.indexOf(a.err.message)||(j=a.err.message+"\n"+j),"[object Error]"==j&&(j=a.err.message),!a.err.stack&&a.err.sourceURL&&void 0!==a.err.line&&(j+="\n("+a.err.sourceURL+":"+a.err.line+")"),h.appendChild(r('
    %e
    ',j))}if(!a.pending){var k=h.getElementsByTagName("h2")[0];v(k,"click",function(){m.style.display="none"==m.style.display?"block":"none"});var m=r("
    %e
    ",f.clean(a.fn.toString()));h.appendChild(m),m.style.display="none"}z[0]&&z[0].appendChild(h)}),void 0):q("#mocha div missing, add it to your document")}function q(a){document.body.appendChild(r('
    %s
    ',a))}function r(a){var b=arguments,c=document.createElement("div"),d=1;return c.innerHTML=a.replace(/%([se])/g,function(a,c){switch(c){case"s":return String(b[d++]);case"e":return h(b[d++])}}),c.firstChild}function s(a){for(var b=document.getElementsByClassName("suite"),c=0;c0&&(b.coverage=100*(b.hits/b.sloc)),b}function i(a,b){var c={filename:a,coverage:0,hits:0,misses:0,sloc:0,source:{}};return b.source.forEach(function(a,d){d++,0===b[d]?(c.misses++,c.sloc++):void 0!==b[d]&&(c.hits++,c.sloc++),c.source[d]={source:a,coverage:void 0===b[d]?"":b[d]}}),c.coverage=100*(c.hits/c.sloc),c}function j(a){return{title:a.title,fullTitle:a.fullTitle(),duration:a.duration}}var e=d("./base");c=a.exports=f}),a.register("reporters/json-stream.js",function(a,b,c){function f(a){d.call(this,a);var b=this,e=(this.stats,a.total);a.on("start",function(){console.log(JSON.stringify(["start",{total:e}]))}),a.on("pass",function(a){console.log(JSON.stringify(["pass",g(a)]))}),a.on("fail",function(a,b){a=g(a),a.err=b.message,console.log(JSON.stringify(["fail",a]))}),a.on("end",function(){h.stdout.write(JSON.stringify(["end",b.stats]))})}function g(a){return{title:a.title,fullTitle:a.fullTitle(),duration:a.duration}}var d=c("./base");d.color,b=a.exports=f}),a.register("reporters/json.js",function(a,b,c){function g(a){var b=this;d.call(this,a);var c=[],e=[],f=[],g=[];a.on("test end",function(a){c.push(a)}),a.on("pass",function(a){g.push(a)}),a.on("fail",function(a){f.push(a)}),a.on("pending",function(a){e.push(a)}),a.on("end",function(){var d={stats:b.stats,tests:c.map(i),pending:e.map(i),failures:f.map(i),passes:g.map(i)};a.testResults=d,h.stdout.write(JSON.stringify(d,null,2))})}function i(a){return{title:a.title,fullTitle:a.fullTitle(),duration:a.duration,err:j(a.err||{})}}function j(a){var b={};return Object.getOwnPropertyNames(a).forEach(function(c){b[c]=a[c]},a),b}var d=c("./base");d.cursor,d.color,b=a.exports=g}),a.register("reporters/landing.js",function(a,b,c){function g(a){function n(){var a=Array(g).join("-");return" "+f("runway",a)}d.call(this,a);var b=this,g=(this.stats,0|.75*d.window.width),i=a.total,j=h.stdout,k=f("plane","\u2708"),l=-1,m=0;a.on("start",function(){j.write("\n\n\n "),e.hide()}),a.on("test end",function(a){var b=-1==l?0|g*++m/i:l;"failed"==a.state&&(k=f("plane crash","\u2708"),l=b),j.write("["+(g+1)+"D"),j.write(n()),j.write("\n "),j.write(f("runway",Array(b).join("\u22c5"))),j.write(k),j.write(f("runway",Array(g-b).join("\u22c5")+"\n")),j.write(n()),j.write("")}),a.on("end",function(){e.show(),console.log(),b.epilogue()})}function i(){}var d=c("./base"),e=d.cursor,f=d.color;b=a.exports=g,d.colors.plane=0,d.colors["plane crash"]=31,d.colors.runway=90,i.prototype=d.prototype,g.prototype=new i,g.prototype.constructor=g}),a.register("reporters/list.js",function(a,b,c){function g(a){d.call(this,a);var b=this,g=(this.stats,0);a.on("start",function(){console.log()}),a.on("test",function(a){h.stdout.write(f("pass"," "+a.fullTitle()+": "))}),a.on("pending",function(a){var b=f("checkmark"," -")+f("pending"," %s");console.log(b,a.fullTitle())}),a.on("pass",function(a){var b=f("checkmark"," "+d.symbols.dot)+f("pass"," %s: ")+f(a.speed,"%dms");e.CR(),console.log(b,a.fullTitle(),a.duration)}),a.on("fail",function(a){e.CR(),console.log(f("fail"," %d) %s"),++g,a.fullTitle())}),a.on("end",b.epilogue.bind(b))}function i(){}var d=c("./base"),e=d.cursor,f=d.color;b=a.exports=g,i.prototype=d.prototype,g.prototype=new i,g.prototype.constructor=g}),a.register("reporters/markdown.js",function(a,b,c){function f(a){function i(a){return Array(f).join("#")+" "+a}function k(a,b){var c=b;return b=b[a.title]=b[a.title]||{suite:a},a.suites.forEach(function(a){k(a,b)}),c}function l(a,b){++b;var d,c="";for(var f in a)"suite"!=f&&(f&&(d=" - ["+f+"](#"+e.slug(a[f].suite.fullTitle())+")\n"),f&&(c+=Array(b).join(" ")+d),c+=l(a[f],b));return--b,c}function m(a){var b=k(a,{});return l(b,0)}d.call(this,a);var f=(this.stats,0),g="";m(a.suite),a.on("suite",function(a){++f;var b=e.slug(a.fullTitle());g+=''+"\n",g+=i(a.title)+"\n"}),a.on("suite end",function(){--f}),a.on("pass",function(a){var b=e.clean(a.fn.toString()); 2 | g+=a.title+".\n",g+="\n```js\n",g+=b+"\n",g+="```\n\n"}),a.on("end",function(){h.stdout.write("# TOC\n"),h.stdout.write(m(a.suite)),h.stdout.write(g)})}var d=c("./base"),e=c("../utils");b=a.exports=f}),a.register("reporters/min.js",function(a,b,c){function e(a){d.call(this,a),a.on("start",function(){h.stdout.write(""),h.stdout.write("")}),a.on("end",this.epilogue.bind(this))}function f(){}var d=c("./base");b=a.exports=e,f.prototype=d.prototype,e.prototype=new f,e.prototype.constructor=e}),a.register("reporters/nyan.js",function(a,b,c){function f(a){d.call(this,a);var b=this,e=(this.stats,0|.75*d.window.width),k=(this.rainbowColors=b.generateColors(),this.colorIndex=0,this.numberOfLines=4,this.trajectories=[[],[],[],[]],this.nyanCatWidth=11);this.trajectoryWidthMax=e-k,this.scoreboardWidth=5,this.tick=0,a.on("start",function(){d.cursor.hide(),b.draw()}),a.on("pending",function(){b.draw()}),a.on("pass",function(){b.draw()}),a.on("fail",function(){b.draw()}),a.on("end",function(){d.cursor.show();for(var a=0;a=this.trajectoryWidthMax&&d.shift(),d.push(b)}},f.prototype.drawRainbow=function(){var a=this;this.trajectories.forEach(function(b){g("["+a.scoreboardWidth+"C"),g(b.join("")),g("\n")}),this.cursorUp(this.numberOfLines)},f.prototype.drawNyanCat=function(){var a=this,b=this.scoreboardWidth+this.trajectories[0].length,c="["+b+"C",d="";g(c),g("_,------,"),g("\n"),g(c),d=a.tick?" ":" ",g("_|"+d+"/\\_/\\ "),g("\n"),g(c),d=a.tick?"_":"__";var e=a.tick?"~":"^";g(e+"|"+d+this.face()+" "),g("\n"),g(c),d=a.tick?" ":" ",g(d+'"" "" '),g("\n"),this.cursorUp(this.numberOfLines)},f.prototype.face=function(){var a=this.stats;return a.failures?"( x .x)":a.pending?"( o .o)":a.passes?"( ^ .^)":"( - .-)"},f.prototype.cursorUp=function(a){g("["+a+"A")},f.prototype.cursorDown=function(a){g("["+a+"B")},f.prototype.generateColors=function(){for(var a=[],b=0;42>b;b++){var c=Math.floor(Math.PI/3),d=b*(1/6),e=Math.floor(3*Math.sin(d)+3),f=Math.floor(3*Math.sin(d+2*c)+3),g=Math.floor(3*Math.sin(d+4*c)+3);a.push(36*e+6*f+g+16)}return a},f.prototype.rainbowify=function(a){var b=this.rainbowColors[this.colorIndex%this.rainbowColors.length];return this.colorIndex+=1,"[38;5;"+b+"m"+a+""},i.prototype=d.prototype,f.prototype=new i,f.prototype.constructor=f}),a.register("reporters/progress.js",function(a,b,c){function g(a,b){d.call(this,a);var c=this,b=b||{},i=(this.stats,0|.5*d.window.width),j=a.total,k=0,m=(Math.max,-1);b.open=b.open||"[",b.complete=b.complete||"\u25ac",b.incomplete=b.incomplete||d.symbols.dot,b.close=b.close||"]",b.verbose=!1,a.on("start",function(){console.log(),e.hide()}),a.on("test end",function(){k++;var c=k/j,d=0|i*c,g=i-d;(m!==d||b.verbose)&&(m=d,e.CR(),h.stdout.write(""),h.stdout.write(f("progress"," "+b.open)),h.stdout.write(Array(d).join(b.complete)),h.stdout.write(Array(g).join(b.incomplete)),h.stdout.write(f("progress",b.close)),b.verbose&&h.stdout.write(f("progress"," "+k+" of "+j)))}),a.on("end",function(){e.show(),console.log(),c.epilogue()})}function i(){}var d=c("./base"),e=d.cursor,f=d.color;b=a.exports=g,d.colors.progress=90,i.prototype=d.prototype,g.prototype=new i,g.prototype.constructor=g}),a.register("reporters/spec.js",function(a,b,c){function g(a){function i(){return Array(g).join(" ")}d.call(this,a);var b=this,g=(this.stats,0),h=0;a.on("start",function(){console.log()}),a.on("suite",function(a){++g,console.log(f("suite","%s%s"),i(),a.title)}),a.on("suite end",function(){--g,1==g&&console.log()}),a.on("pending",function(a){var b=i()+f("pending"," - %s");console.log(b,a.title)}),a.on("pass",function(a){if("fast"==a.speed){var b=i()+f("checkmark"," "+d.symbols.ok)+f("pass"," %s ");e.CR(),console.log(b,a.title)}else{var b=i()+f("checkmark"," "+d.symbols.ok)+f("pass"," %s ")+f(a.speed,"(%dms)");e.CR(),console.log(b,a.title,a.duration)}}),a.on("fail",function(a){e.CR(),console.log(i()+f("fail"," %d) %s"),++h,a.title)}),a.on("end",b.epilogue.bind(b))}function h(){}var d=c("./base"),e=d.cursor,f=d.color;b=a.exports=g,h.prototype=d.prototype,g.prototype=new h,g.prototype.constructor=g}),a.register("reporters/tap.js",function(a,b,c){function g(a){d.call(this,a);var e=(this.stats,1),f=0,g=0;a.on("start",function(){var b=a.grepTotal(a.suite);console.log("%d..%d",1,b)}),a.on("test end",function(){++e}),a.on("pending",function(a){console.log("ok %d %s # SKIP -",e,h(a))}),a.on("pass",function(a){f++,console.log("ok %d %s",e,h(a))}),a.on("fail",function(a,b){g++,console.log("not ok %d %s",e,h(a)),b.stack&&console.log(b.stack.replace(/^/gm," "))}),a.on("end",function(){console.log("# tests "+(f+g)),console.log("# pass "+f),console.log("# fail "+g)})}function h(a){return a.fullTitle().replace(/#/g,"")}var d=c("./base");d.cursor,d.color,b=a.exports=g}),a.register("reporters/xunit.js",function(a,c,d){function m(a){e.call(this,a);var b=this.stats,c=[];a.on("pending",function(a){c.push(a)}),a.on("pass",function(a){c.push(a)}),a.on("fail",function(a){c.push(a)}),a.on("end",function(){console.log(p("testsuite",{name:"Mocha Tests",tests:b.tests,failures:b.failures,errors:b.failures,skipped:b.tests-b.failures-b.passes,timestamp:(new h).toUTCString(),time:b.duration/1e3||0},!1)),c.forEach(o),console.log("")})}function n(){}function o(a){var b={classname:a.parent.fullTitle(),name:a.title,time:a.duration/1e3||0};if("failed"==a.state){var c=a.err;console.log(p("testcase",b,!1,p("failure",{},!1,q(g(c.message)+"\n"+c.stack))))}else a.pending?console.log(p("testcase",b,!1,p("skipped",{},!0))):console.log(p("testcase",b,!0))}function p(a,b,c,d){var h,e=c?"/>":">",f=[];for(var i in b)f.push(i+'="'+g(b[i])+'"');return h="<"+a+(f.length?" "+f.join(" "):"")+e,d&&(h+=d+""}var e=d("./base"),f=d("../utils"),g=f.escape,h=b.Date;b.setTimeout,b.setInterval,b.clearTimeout,b.clearInterval,c=a.exports=m,n.prototype=e.prototype,m.prototype=new n,m.prototype.constructor=m}),a.register("runnable.js",function(a,c,d){function n(a,b){this.title=a,this.fn=b,this.async=b&&b.length,this.sync=!this.async,this._timeout=2e3,this._slow=75,this._enableTimeouts=!0,this.timedOut=!1,this._trace=new Error("done() called multiple times")}function o(){}var e=d("browser/events").EventEmitter,f=d("browser/debug")("mocha:runnable"),g=d("./ms"),h=b.Date,i=b.setTimeout,k=(b.setInterval,b.clearTimeout);b.clearInterval;var m=Object.prototype.toString;a.exports=n,o.prototype=e.prototype,n.prototype=new o,n.prototype.constructor=n,n.prototype.timeout=function(a){return 0==arguments.length?this._timeout:(0===a&&(this._enableTimeouts=!1),"string"==typeof a&&(a=g(a)),f("timeout %d",a),this._timeout=a,this.timer&&this.resetTimeout(),this)},n.prototype.slow=function(a){return 0===arguments.length?this._slow:("string"==typeof a&&(a=g(a)),f("timeout %d",a),this._slow=a,this)},n.prototype.enableTimeouts=function(a){return 0===arguments.length?this._enableTimeouts:(f("enableTimeouts %s",a),this._enableTimeouts=a,this)},n.prototype.fullTitle=function(){return this.parent.fullTitle()+" "+this.title},n.prototype.clearTimeout=function(){k(this.timer)},n.prototype.inspect=function(){return JSON.stringify(this,function(a,b){return"_"!=a[0]?"parent"==a?"#":"ctx"==a?"#":b:void 0},2)},n.prototype.resetTimeout=function(){var a=this,b=this.timeout()||1e9;this._enableTimeouts&&(this.clearTimeout(),this.timer=i(function(){a._enableTimeouts&&(a.callback(new Error("timeout of "+b+"ms exceeded")),a.timedOut=!0)},b))},n.prototype.globals=function(a){this._allowedGlobals=a},n.prototype.run=function(a){function g(a){f||(f=!0,b.emit("error",a||new Error("done() called multiple times; stacktrace may be inaccurate")))}function i(d){var f=b.timeout();if(!b.timedOut){if(e)return g(d||b._trace);b.clearTimeout(),b.duration=new h-c,e=!0,!d&&b.duration>f&&b._enableTimeouts&&(d=new Error("timeout of "+f+"ms exceeded")),a(d)}}function k(a){var c=a.call(d);c&&"function"==typeof c.then?(b.resetTimeout(),c.then(function(){i()},function(a){i(a||new Error("Promise rejected with no or falsy reason"))})):i()}var e,f,b=this,c=new h,d=this.ctx;if(d&&d.runnable&&d.runnable(this),this.callback=i,this.async){this.resetTimeout();try{this.fn.call(d,function(a){return a instanceof Error||"[object Error]"===m.call(a)?i(a):null!=a?"[object Object]"===Object.prototype.toString.call(a)?i(new Error("done() invoked with non-Error: "+JSON.stringify(a))):i(new Error("done() invoked with non-Error: "+a)):(i(),void 0)})}catch(j){i(j)}}else{if(this.asyncOnly)return i(new Error("--async-only option in use without declaring `done()`"));try{this.pending?i():k(this.fn)}catch(j){i(j)}}}}),a.register("runner.js",function(a,c,d){function m(a){var b=this;this._globals=[],this._abort=!1,this.suite=a,this.total=a.total(),this.failures=0,this.on("test end",function(a){b.checkGlobals(a)}),this.on("hook end",function(a){b.checkGlobals(a)}),this.grep(/.*/),this.globals(this.globalProps().concat(p()))}function n(){}function o(a,c){return j(c,function(c){if(/^d+/.test(c))return!1;if(b.navigator&&/^getInterface/.test(c))return!1;if(b.navigator&&/^\d+/.test(c))return!1;if(/^mocha-/.test(c))return!1;var d=j(a,function(a){return~a.indexOf("*")?0==c.indexOf(a.split("*")[0]):c==a});return 0==d.length&&(!b.navigator||"onerror"!==c)})}function p(){if("object"==typeof h&&"string"==typeof h.version){var a=h.version.split(".").reduce(function(a,b){return a<<8|b});if(2315>a)return["errno"]}return[]}var e=d("browser/events").EventEmitter,f=d("browser/debug")("mocha:runner"),i=(d("./test"),d("./utils")),j=i.filter;i.keys;var l=["setTimeout","clearTimeout","setInterval","clearInterval","XMLHttpRequest","Date"];a.exports=m,m.immediately=b.setImmediate||h.nextTick,n.prototype=e.prototype,m.prototype=new n,m.prototype.constructor=m,m.prototype.grep=function(a,b){return f("grep %s",a),this._grep=a,this._invert=b,this.total=this.grepTotal(this.suite),this},m.prototype.grepTotal=function(a){var b=this,c=0;return a.eachTest(function(a){var d=b._grep.test(a.fullTitle());b._invert&&(d=!d),d&&c++}),c},m.prototype.globalProps=function(){for(var a=i.keys(b),c=0;c1?this.fail(a,new Error("global leaks detected: "+d.join(", "))):d.length&&this.fail(a,new Error("global leak detected: "+d[0])))}},m.prototype.fail=function(a,b){++this.failures,a.state="failed","string"==typeof b&&(b=new Error('the string "'+b+'" was thrown, throw an Error :)')),this.emit("fail",a,b)},m.prototype.failHook=function(a,b){this.fail(a,b),this.suite.bail()&&this.emit("end")},m.prototype.hook=function(a,b){function g(a){var f=d[a];return f?e.failures&&c.bail()?b():(e.currentRunnable=f,f.ctx.currentTest=e.test,e.emit("hook",f),f.on("error",function(a){e.failHook(f,a)}),f.run(function(c){f.removeAllListeners("error");var d=f.error();return d&&e.fail(e.test,d),c?(e.failHook(f,c),b(c)):(e.emit("hook end",f),delete f.ctx.currentTest,g(++a),void 0)}),void 0):b()}var c=this.suite,d=c["_"+a],e=this;m.immediately(function(){g(0)})},m.prototype.hooks=function(a,b,c){function f(g){return d.suite=g,g?(d.hook(a,function(a){if(a){var g=d.suite;return d.suite=e,c(a,g)}f(b.pop())}),void 0):(d.suite=e,c())}var d=this,e=this.suite;f(b.pop())},m.prototype.hookUp=function(a,b){var c=[this.suite].concat(this.parents()).reverse();this.hooks(a,c,b)},m.prototype.hookDown=function(a,b){var c=[this.suite].concat(this.parents());this.hooks(a,c,b)},m.prototype.parents=function(){for(var a=this.suite,b=[];a=a.parent;)b.push(a);return b},m.prototype.runTest=function(a){var b=this.test,c=this;this.asyncOnly&&(b.asyncOnly=!0);try{b.on("error",function(a){c.fail(b,a)}),b.run(a)}catch(d){a(d)}},m.prototype.runTests=function(a,b){function f(a,d,e){var g=c.suite;c.suite=e?d.parent:d,c.suite?c.hookUp("afterEach",function(a,e){return c.suite=g,a?f(a,e,!0):(b(d),void 0)}):(c.suite=g,b(d))}function g(h,i){if(c.failures&&a._bail)return b();if(c._abort)return b();if(h)return f(h,i,!0);if(e=d.shift(),!e)return b();var j=c._grep.test(e.fullTitle());return c._invert&&(j=!j),j?e.pending?(c.emit("pending",e),c.emit("test end",e),g()):(c.emit("test",c.test=e),c.hookDown("beforeEach",function(a,b){return a?f(a,b,!1):(c.currentRunnable=c.test,c.runTest(function(a){return e=c.test,a?(c.fail(e,a),c.emit("test end",e),c.hookUp("afterEach",g)):(e.state="passed",c.emit("pass",e),c.emit("test end",e),c.hookUp("afterEach",g),void 0)}),void 0)}),void 0):g()}var e,c=this,d=a.tests.slice();this.next=g,g()},m.prototype.runSuite=function(a,b){function g(b){if(b)return b==a?h():h(b);if(d._abort)return h();var c=a.suites[e++];return c?(d.runSuite(c,g),void 0):h()}function h(c){d.suite=a,d.hook("afterAll",function(){d.emit("suite end",a),b(c)})}var c=this.grepTotal(a),d=this,e=0;return f("run suite %s",a.fullTitle()),c?(this.emit("suite",this.suite=a),this.hook("beforeAll",function(b){return b?h():(d.runTests(a,g),void 0)}),void 0):b()},m.prototype.uncaught=function(a){a?f("uncaught exception %s",a!==function(){return this}.call(a)?a:a.message||a):(f("uncaught undefined exception"),a=new Error("Caught undefined error, did you throw without specifying what?")),a.uncaught=!0;var b=this.currentRunnable;if(b){var c=b.state;if(this.fail(b,a),b.clearTimeout(),!c)return"test"==b.type?(this.emit("test end",b),this.hookUp("afterEach",this.next),void 0):(this.emit("end"),void 0)}},m.prototype.run=function(a){function c(a){b.uncaught(a)}var b=this,a=a||function(){};return f("start"),this.on("end",function(){f("end"),h.removeListener("uncaughtException",c),a(b.failures)}),this.emit("start"),this.runSuite(this.suite,function(){f("finished running"),b.emit("end")}),h.on("uncaughtException",c),this},m.prototype.abort=function(){f("aborting"),this._abort=!0}}),a.register("suite.js",function(a,b,c){function i(a,b){this.title=a;var c=function(){};c.prototype=b,this.ctx=new c,this.suites=[],this.tests=[],this.pending=!1,this._beforeEach=[],this._beforeAll=[],this._afterEach=[],this._afterAll=[],this.root=!a,this._timeout=2e3,this._enableTimeouts=!0,this._slow=75,this._bail=!1}function j(){}var d=c("browser/events").EventEmitter,e=c("browser/debug")("mocha:suite"),f=c("./ms"),g=c("./utils"),h=c("./hook");b=a.exports=i,b.create=function(a,b){var c=new i(b,a.ctx);return c.parent=a,a.pending&&(c.pending=!0),b=c.fullTitle(),a.addSuite(c),c},j.prototype=d.prototype,i.prototype=new j,i.prototype.constructor=i,i.prototype.clone=function(){var a=new i(this.title);return e("clone"),a.ctx=this.ctx,a.timeout(this.timeout()),a.enableTimeouts(this.enableTimeouts()),a.slow(this.slow()),a.bail(this.bail()),a},i.prototype.timeout=function(a){return 0==arguments.length?this._timeout:(0===a&&(this._enableTimeouts=!1),"string"==typeof a&&(a=f(a)),e("timeout %d",a),this._timeout=parseInt(a,10),this)},i.prototype.enableTimeouts=function(a){return 0===arguments.length?this._enableTimeouts:(e("enableTimeouts %s",a),this._enableTimeouts=a,this)},i.prototype.slow=function(a){return 0===arguments.length?this._slow:("string"==typeof a&&(a=f(a)),e("slow %d",a),this._slow=a,this)},i.prototype.bail=function(a){return 0==arguments.length?this._bail:(e("bail %s",a),this._bail=a,this)},i.prototype.beforeAll=function(a,b){if(this.pending)return this;"function"==typeof a&&(b=a,a=b.name),a='"before all" hook'+(a?": "+a:"");var c=new h(a,b);return c.parent=this,c.timeout(this.timeout()),c.enableTimeouts(this.enableTimeouts()),c.slow(this.slow()),c.ctx=this.ctx,this._beforeAll.push(c),this.emit("beforeAll",c),this},i.prototype.afterAll=function(a,b){if(this.pending)return this;"function"==typeof a&&(b=a,a=b.name),a='"after all" hook'+(a?": "+a:"");var c=new h(a,b);return c.parent=this,c.timeout(this.timeout()),c.enableTimeouts(this.enableTimeouts()),c.slow(this.slow()),c.ctx=this.ctx,this._afterAll.push(c),this.emit("afterAll",c),this},i.prototype.beforeEach=function(a,b){if(this.pending)return this;"function"==typeof a&&(b=a,a=b.name),a='"before each" hook'+(a?": "+a:"");var c=new h(a,b);return c.parent=this,c.timeout(this.timeout()),c.enableTimeouts(this.enableTimeouts()),c.slow(this.slow()),c.ctx=this.ctx,this._beforeEach.push(c),this.emit("beforeEach",c),this},i.prototype.afterEach=function(a,b){if(this.pending)return this;"function"==typeof a&&(b=a,a=b.name),a='"after each" hook'+(a?": "+a:"");var c=new h(a,b);return c.parent=this,c.timeout(this.timeout()),c.enableTimeouts(this.enableTimeouts()),c.slow(this.slow()),c.ctx=this.ctx,this._afterEach.push(c),this.emit("afterEach",c),this},i.prototype.addSuite=function(a){return a.parent=this,a.timeout(this.timeout()),a.enableTimeouts(this.enableTimeouts()),a.slow(this.slow()),a.bail(this.bail()),this.suites.push(a),this.emit("suite",a),this},i.prototype.addTest=function(a){return a.parent=this,a.timeout(this.timeout()),a.enableTimeouts(this.enableTimeouts()),a.slow(this.slow()),a.ctx=this.ctx,this.tests.push(a),this.emit("test",a),this},i.prototype.fullTitle=function(){if(this.parent){var a=this.parent.fullTitle();if(a)return a+" "+this.title}return this.title},i.prototype.total=function(){return g.reduce(this.suites,function(a,b){return a+b.total()},0)+this.tests.length},i.prototype.eachTest=function(a){return g.forEach(this.tests,a),g.forEach(this.suites,function(b){b.eachTest(a)}),this}}),a.register("test.js",function(a,b,c){function e(a,b){d.call(this,a,b),this.pending=!b,this.type="test"}function f(){}var d=c("./runnable");a.exports=e,f.prototype=d.prototype,e.prototype=new f,e.prototype.constructor=e}),a.register("utils.js",function(a,b,c){function l(a){return!~k.indexOf(a)}function m(a){return a.replace(//g,">").replace(/\/\/(.*)/gm,'//$1').replace(/('.*?')/gm,'$1').replace(/(\d+\.\d+)/gm,'$1').replace(/(\d+)/gm,'$1').replace(/\bnew[ \t]+(\w+)/gm,'new $1').replace(/\b(function|new|throw|return|var|if|else)\b/gm,'$1')}var d=c("browser/fs"),e=c("browser/path"),f=e.basename,g=d.existsSync||e.existsSync,h=c("browser/glob"),i=e.join,j=c("browser/debug")("mocha:watch"),k=["node_modules",".git"];b.escape=function(a){return String(a).replace(/&/g,"&").replace(/"/g,""").replace(//g,">")},b.forEach=function(a,b,c){for(var d=0,e=a.length;e>d;d++)b.call(c,a[d],d)},b.map=function(a,b,c){for(var d=[],e=0,f=a.length;f>e;e++)d.push(b.call(c,a[e],e));return d},b.indexOf=function(a,b,c){for(var d=c||0,e=a.length;e>d;d++)if(a[d]===b)return d;return-1},b.reduce=function(a,b,c){for(var d=c,e=0,f=a.length;f>e;e++)d=b(d,a[e],e,a);return d},b.filter=function(a,b){for(var c=[],d=0,e=a.length;e>d;d++){var f=a[d];b(f,d,a)&&c.push(f)}return c},b.keys=Object.keys||function(a){var b=[],c=Object.prototype.hasOwnProperty;for(var d in a)c.call(a,d)&&b.push(d);return b},b.watch=function(a,b){var c={interval:100};a.forEach(function(a){j("file %s",a),d.watchFile(a,c,function(c,d){d.mtime *{?/,"").replace(/\s+\}$/,"");var c=a.match(/^\n?( *)/)[1].length,d=a.match(/^\n?(\t*)/)[1].length,e=new RegExp("^\n?"+(d?" ":" ")+"{"+(d?d:c)+"}","gm");return a=a.replace(e,""),b.trim(a)},b.trim=function(a){return a.replace(/^\s+|\s+$/g,"")},b.parseQuery=function(a){return b.reduce(a.replace("?","").split("&"),function(a,b){var c=b.indexOf("="),d=b.slice(0,c),e=b.slice(++c);return a[d]=decodeURIComponent(e),a},{})},b.highlightTags=function(a){for(var b=document.getElementById("mocha").getElementsByTagName(a),c=0,d=b.length;d>c;++c)b[c].innerHTML=m(b[c].innerHTML)},b.stringify=function(a){return a instanceof RegExp?a.toString():JSON.stringify(b.canonicalize(a),null,2).replace(/,(\n|$)/g,"$1")},b.canonicalize=function(a,c){if(c=c||[],-1!==b.indexOf(c,a))return"[Circular]";var d;return"[object Array]"==={}.toString.call(a)?(c.push(a),d=b.map(a,function(a){return b.canonicalize(a,c)}),c.pop()):"object"==typeof a&&null!==a?(c.push(a),d={},b.forEach(b.keys(a).sort(),function(e){d[e]=b.canonicalize(a[e],c)}),c.pop()):d=a,d},b.lookupFiles=function n(a,b,c){var e=[],j=new RegExp("\\.("+b.join("|")+")$");if(!g(a)){if(!g(a+".js")){if(e=h.sync(a),!e.length)throw new Error("cannot resolve path (or pattern) '"+a+"'");return e}a+=".js"}try{var k=d.statSync(a);if(k.isFile())return a}catch(l){return}return d.readdirSync(a).forEach(function(g){g=i(a,g);try{var h=d.statSync(g);if(h.isDirectory())return c&&(e=e.concat(n(g,b,c))),void 0}catch(k){return}h.isFile()&&j.test(g)&&"."!==f(g)[0]&&e.push(g)}),e}});var b=function(){return this}(),c=b.Date,d=b.setTimeout;b.setInterval,b.clearTimeout,b.clearInterval;var h={};h.exit=function(){},h.stdout={};var i=[],j=b.onerror;h.removeListener=function(a,c){if("uncaughtException"==a){b.onerror=j?j:function(){};var d=k.utils.indexOf(i,c);-1!=d&&i.splice(d,1)}},h.on=function(a,c){"uncaughtException"==a&&(b.onerror=function(a,b,d){return c(new Error(a+" ("+b+":"+d+")")),!0},i.push(c))};var k=b.Mocha=a("mocha"),l=b.mocha=new k({reporter:"html"});l.suite.removeAllListeners("pre-require");var n,m=[];k.Runner.immediately=function(a){m.push(a),n||(n=d(o,0))},l.throwError=function(a){throw k.utils.forEach(i,function(b){b(a)}),a},l.ui=function(a){return k.prototype.ui.call(this,a),this.suite.emit("pre-require",b,null,this),this},l.setup=function(a){"string"==typeof a&&(a={ui:a});for(var b in a)this[b](a[b]);return this},l.run=function(a){var c=l.options;l.globals("location");var d=k.utils.parseQuery(b.location.search||"");return d.grep&&l.grep(d.grep),d.invert&&l.invert(),k.prototype.run.call(l,function(d){var e=b.document;e&&e.getElementById("mocha")&&c.noHighlighting!==!0&&k.utils.highlightTags("code"),a&&a(d)})},k.process=h}(); 3 | -------------------------------------------------------------------------------- /test/fixtures/sinon.js: -------------------------------------------------------------------------------- 1 | this.sinon=function(){var buster=function(a,b){var c="function"==typeof require&&"object"==typeof module,d="undefined"!=typeof document&&document.createElement("div"),e=function(){},f={bind:function(a,b){var c="string"==typeof b?a[b]:b,d=Array.prototype.slice.call(arguments,2);return function(){var b=d.concat(Array.prototype.slice.call(arguments));return c.apply(a,b)}},partial:function(a){var b=[].slice.call(arguments,1);return function(){return a.apply(this,b.concat([].slice.call(arguments)))}},create:function(a){return e.prototype=a,new e},extend:function(a){if(a){for(var d,b=1,c=arguments.length;c>b;++b)for(d in arguments[b])a[d]=arguments[b][d];return a}},nextTick:function(b){return"undefined"!=typeof process&&process.nextTick?process.nextTick(b):(a(b,0),void 0)},functionName:function(a){if(!a)return"";if(a.displayName)return a.displayName;if(a.name)return a.name;var b=a.toString().match(/function\s+([^\(]+)/m);return b&&b[1]||""},isNode:function(a){if(!d)return!1;try{a.appendChild(d),a.removeChild(d)}catch(b){return!1}return!0},isElement:function(a){return a&&1===a.nodeType&&f.isNode(a)},isArray:function(a){return"[object Array]"==Object.prototype.toString.call(a)},flatten:function r(a){for(var b=[],a=a||[],c=0,d=a.length;d>c;++c)b=b.concat(f.isArray(a[c])?r(a[c]):a[c]);return b},each:function(a,b){for(var c=0,d=a.length;d>c;++c)b(a[c])},map:function(a,b){for(var c=[],d=0,e=a.length;e>d;++d)c.push(b(a[d]));return c},parallel:function(a,b){function c(a,c){"function"==typeof b&&(b(a,c),b=null)}function f(a){return function(b,f){return b?c(b):(e[a]=f,0==--d&&c(null,e),void 0)}}if(0==a.length)return c(null,[]);for(var d=a.length,e=[],g=0,h=a.length;h>g;++g)a[g](f(g))},series:function(a,b){function c(a,c){"function"==typeof b&&b(a,c)}function g(){if(0==d.length)return c(null,e);var a=d.shift()(h);a&&"function"==typeof a.then&&a.then(f.partial(h,null),h)}function h(a,b){return a?c(a):(e.push(b),g(),void 0)}var d=a.slice(),e=[];g()},countdown:function(a,b){return function(){0==--a&&b()}}};if("object"==typeof process&&"function"==typeof require&&"object"==typeof module){var g=require("crypto"),h=require("path");f.tmpFile=function(a){var b=g.createHash("sha1");b.update(a);var c=b.digest("hex");return"win32"==process.platform?h.join(process.env.TEMP,c):h.join("/tmp",c)}}return f.some=Array.prototype.some?function(a,b,c){return a.some(b,c)}:function(a,b,c){if(null==a)throw new TypeError;a=Object(a);var d=a.length>>>0;if("function"!=typeof b)throw new TypeError;for(var e=0;d>e;e++)if(a.hasOwnProperty(e)&&b.call(c,a[e],e,a))return!0;return!1},f.filter=Array.prototype.filter?function(a,b,c){return a.filter(b,c)}:function(a,b){if(null==this)throw new TypeError;var c=Object(this),d=c.length>>>0;if("function"!=typeof a)throw new TypeError;for(var e=[],f=0;d>f;f++)if(f in c){var g=c[f];a.call(b,g,f,c)&&e.push(g)}return e},c&&(module.exports=f,f.eventEmitter=require("./buster-event-emitter"),Object.defineProperty(f,"defineVersionGetter",{get:function(){return require("./define-version-getter")}})),f.extend(b||{},f)}(setTimeout,buster);if("undefined"==typeof buster)var buster={};"object"==typeof module&&"function"==typeof require&&(buster=require("buster-core")),buster.format=buster.format||{},buster.format.excludeConstructors=["Object",/^.$/],buster.format.quoteStrings=!0,buster.format.ascii=function(){function c(b){var c=Object.keys&&Object.keys(b)||[];if(0==c.length)for(var d in b)a.call(b,d)&&c.push(d);return c.sort()}function d(a,b){if("object"!=typeof a)return!1;for(var c=0,d=b.length;d>c;++c)if(b[c]===a)return!0;return!1}function e(a,c,f){if("string"==typeof a){var g="boolean"!=typeof this.quoteStrings||this.quoteStrings;return c||g?'"'+a+'"':a}if("function"==typeof a&&!(a instanceof RegExp))return e.func(a);if(c=c||[],d(a,c))return"[Circular]";if("[object Array]"==Object.prototype.toString.call(a))return e.array.call(this,a,c);if(!a)return""+a;if(buster.isElement(a))return e.element(a);if("function"==typeof a.toString&&a.toString!==Object.prototype.toString)return a.toString();for(var h=0,i=b.length;i>h;h++)if(a===b[h].obj)return b[h].value;return e.object.call(this,a,c,f)}var a=Object.prototype.hasOwnProperty,b=[];return"undefined"!=typeof global&&b.push({obj:global,value:"[object global]"}),"undefined"!=typeof document&&b.push({obj:document,value:"[object HTMLDocument]"}),"undefined"!=typeof window&&b.push({obj:window,value:"[object Window]"}),e.func=function(a){return"function "+buster.functionName(a)+"() {}"},e.array=function(a,b){b=b||[],b.push(a);for(var c=[],d=0,f=a.length;f>d;++d)c.push(e.call(this,a[d],b));return"["+c.join(", ")+"]"},e.object=function(a,b,f){b=b||[],b.push(a),f=f||0;for(var i,j,k,g=[],h=c(a),l="",m=3,n=0,o=f;o>n;++n)l+=" ";for(n=0,o=h.length;o>n;++n)i=h[n],k=a[i],j=d(k,b)?"[Circular]":e.call(this,k,b,f+2),j=(/\s/.test(i)?'"'+i+'"':i)+": "+j,m+=j.length,g.push(j);var p=e.constructorName.call(this,a),q=p?"["+p+"] ":"";return m+f>80?q+"{\n "+l+g.join(",\n "+l)+"\n"+l+"}":q+"{ "+g.join(", ")+" }"},e.element=function(a){for(var d,f,b=a.tagName.toLowerCase(),c=a.attributes,e=[],g=0,h=c.length;h>g;++g)d=c.item(g),f=d.nodeName.toLowerCase().replace("html:",""),("contenteditable"!=f||"inherit"!=d.nodeValue)&&d.nodeValue&&e.push(f+'="'+d.nodeValue+'"');var i="<"+b+(e.length>0?" ":""),j=a.innerHTML;j.length>20&&(j=j.substr(0,20)+"[...]");var k=i+e.join(" ")+">"+j+"";return k.replace(/ contentEditable="inherit"/,"")},e.constructorName=function(a){for(var b=buster.functionName(a&&a.constructor),c=this.excludeConstructors||buster.format.excludeConstructors||[],d=0,e=c.length;e>d;++d){if("string"==typeof c[d]&&c[d]==b)return"";if(c[d].test&&c[d].test(b))return""}return b},e}(),"undefined"!=typeof module&&(module.exports=buster.format);var sinon=function(a){function d(a){var c=!1;try{a.appendChild(b),c=b.parentNode==a}catch(d){return!1}finally{try{a.removeChild(b)}catch(d){}}return c}function e(a){return b&&a&&1===a.nodeType&&d(a)}function f(a){return"function"==typeof a||!!(a&&a.constructor&&a.call&&a.apply)}function g(a,b){for(var d in b)c.call(a,d)||(a[d]=b[d])}function h(a){return"function"==typeof a&&"function"==typeof a.restore&&a.restore.sinon}var b="undefined"!=typeof document&&document.createElement("div"),c=Object.prototype.hasOwnProperty,i={wrapMethod:function(a,b,d){if(!a)throw new TypeError("Should wrap property of object");if("function"!=typeof d)throw new TypeError("Method wrapper should be function");var e=a[b];if(!f(e))throw new TypeError("Attempted to wrap "+typeof e+" property "+b+" as function");if(e.restore&&e.restore.sinon)throw new TypeError("Attempted to wrap "+b+" which is already wrapped");if(e.calledBefore){var h=e.returns?"stubbed":"spied on";throw new TypeError("Attempted to wrap "+b+" which is already "+h)}var i=c.call(a,b);return a[b]=d,d.displayName=b,d.restore=function(){i||delete a[b],a[b]===d&&(a[b]=e)},d.restore.sinon=!0,g(d,e),d},extend:function(a){for(var b=1,c=arguments.length;c>b;b+=1)for(var d in arguments[b])arguments[b].hasOwnProperty(d)&&(a[d]=arguments[b][d]),arguments[b].hasOwnProperty("toString")&&arguments[b].toString!=a.toString&&(a.toString=arguments[b].toString);return a},create:function(a){var b=function(){};return b.prototype=a,new b},deepEqual:function q(a,b){if(i.match&&i.match.isMatcher(a))return a.test(b);if("object"!=typeof a||"object"!=typeof b)return a===b;if(e(a)||e(b))return a===b;if(a===b)return!0;if(null===a&&null!==b||null!==a&&null===b)return!1;var c=Object.prototype.toString.call(a);if(c!=Object.prototype.toString.call(b))return!1;if("[object Array]"==c){if(a.length!==b.length)return!1;for(var d=0,f=a.length;f>d;d+=1)if(!q(a[d],b[d]))return!1;return!0}if("[object Date]"==c)return a.valueOf()===b.valueOf();var g,h=0,j=0;for(g in a)if(h+=1,!q(a[g],b[g]))return!1;for(g in b)j+=1;return h==j},functionName:function(a){var b=a.displayName||a.name;if(!b){var c=a.toString().match(/function ([^\s\(]+)/);b=c&&c[1]}return b},functionToString:function(){if(this.getCall&&this.callCount)for(var a,b,c=this.callCount;c--;){a=this.getCall(c).thisValue;for(b in a)if(a[b]===this)return b}return this.displayName||"sinon fake"},getConfig:function(a){var b={};a=a||{};var c=i.defaultConfig;for(var d in c)c.hasOwnProperty(d)&&(b[d]=a.hasOwnProperty(d)?a[d]:c[d]);return b},format:function(a){return""+a},defaultConfig:{injectIntoThis:!0,injectInto:null,properties:["spy","stub","mock","clock","server","requests"],useFakeTimers:!0,useFakeServer:!0},timesInWords:function(a){return 1==a&&"once"||2==a&&"twice"||3==a&&"thrice"||(a||0)+" times"},calledInOrder:function(a){for(var b=1,c=a.length;c>b;b++)if(!a[b-1].calledBefore(a[b])||!a[b].called)return!1;return!0},orderByFirstCall:function(a){return a.sort(function(a,b){var c=a.getCall(0),d=b.getCall(0),e=c&&c.callId||-1,f=d&&d.callId||-1;return f>e?-1:1})},log:function(){},logError:function(a,b){var c=a+" threw exception: ";i.log(c+"["+b.name+"] "+b.message),b.stack&&i.log(b.stack),setTimeout(function(){throw b.message=c+b.message,b},0)},typeOf:function(a){if(null===a)return"null";if(void 0===a)return"undefined";var b=Object.prototype.toString.call(a);return b.substring(8,b.length-1).toLowerCase()},createStubInstance:function(a){if("function"!=typeof a)throw new TypeError("The constructor should be a function.");return i.stub(i.create(a.prototype))},restore:function(a){if(null!==a&&"object"==typeof a)for(var b in a)h(a[b])&&a[b].restore();else h(a)&&a.restore()}},j="object"==typeof module&&"function"==typeof require;if(j){try{a={format:require("buster-format")}}catch(k){}module.exports=i,module.exports.spy=require("./sinon/spy"),module.exports.stub=require("./sinon/stub"),module.exports.mock=require("./sinon/mock"),module.exports.collection=require("./sinon/collection"),module.exports.assert=require("./sinon/assert"),module.exports.sandbox=require("./sinon/sandbox"),module.exports.test=require("./sinon/test"),module.exports.testCase=require("./sinon/test_case"),module.exports.assert=require("./sinon/assert"),module.exports.match=require("./sinon/match")}if(a){var l=i.create(a.format);l.quoteStrings=!1,i.format=function(){return l.ascii.apply(l,arguments)}}else if(j)try{var m=require("util");i.format=function(a){return"object"==typeof a&&a.toString===Object.prototype.toString?m.inspect(a):a}}catch(k){}return i}("object"==typeof buster&&buster);!function(a){function c(b,c,d){var e=a.typeOf(b);if(e!==c)throw new TypeError("Expected type of "+d+" to be "+c+", but was "+e)}function e(a){return d.isPrototypeOf(a)}function f(b,c){if(null===c||void 0===c)return!1;for(var d in b)if(b.hasOwnProperty(d)){var e=b[d],h=c[d];if(g.isMatcher(e)){if(!e.test(h))return!1}else if("object"===a.typeOf(e)){if(!f(e,h))return!1}else if(!a.deepEqual(e,h))return!1}return!0}function h(b,d){return function(e,f){c(e,"string","property");var h=1===arguments.length,i=d+'("'+e+'"';return h||(i+=", "+f),i+=")",g(function(c){return void 0!==c&&null!==c&&b(c,e)?h||a.deepEqual(f,c[e]):!1},i)}}var b="object"==typeof module&&"function"==typeof require;if(!a&&b&&(a=require("../sinon")),a){var d={toString:function(){return this.message}};d.or=function(b){if(!e(b))throw new TypeError("Matcher expected");var c=this,f=a.create(d);return f.test=function(a){return c.test(a)||b.test(a)},f.message=c.message+".or("+b.message+")",f},d.and=function(b){if(!e(b))throw new TypeError("Matcher expected");var c=this,f=a.create(d);return f.test=function(a){return c.test(a)&&b.test(a)},f.message=c.message+".and("+b.message+")",f};var g=function(b,c){var e=a.create(d),g=a.typeOf(b);switch(g){case"object":if("function"==typeof b.test)return e.test=function(a){return b.test(a)===!0},e.message="match("+a.functionName(b.test)+")",e;var h=[];for(var i in b)b.hasOwnProperty(i)&&h.push(i+": "+b[i]);e.test=function(a){return f(b,a)},e.message="match("+h.join(", ")+")";break;case"number":e.test=function(a){return b==a};break;case"string":e.test=function(a){return"string"!=typeof a?!1:-1!==a.indexOf(b)},e.message='match("'+b+'")';break;case"regexp":e.test=function(a){return"string"!=typeof a?!1:b.test(a)};break;case"function":e.test=b,e.message=c?c:"match("+a.functionName(b)+")";break;default:e.test=function(c){return a.deepEqual(b,c)}}return e.message||(e.message="match("+b+")"),e};g.isMatcher=e,g.any=g(function(){return!0},"any"),g.defined=g(function(a){return null!==a&&void 0!==a},"defined"),g.truthy=g(function(a){return!!a},"truthy"),g.falsy=g(function(a){return!a},"falsy"),g.same=function(a){return g(function(b){return a===b},"same("+a+")")},g.typeOf=function(b){return c(b,"string","type"),g(function(c){return a.typeOf(c)===b},'typeOf("'+b+'")')},g.instanceOf=function(b){return c(b,"function","type"),g(function(a){return a instanceof b},"instanceOf("+a.functionName(b)+")")},g.has=h(function(a,b){return"object"==typeof a?b in a:void 0!==a[b]},"has"),g.hasOwn=h(function(a,b){return a.hasOwnProperty(b)},"hasOwn"),g.bool=g.typeOf("boolean"),g.number=g.typeOf("number"),g.string=g.typeOf("string"),g.object=g.typeOf("object"),g.func=g.typeOf("function"),g.array=g.typeOf("array"),g.regexp=g.typeOf("regexp"),g.date=g.typeOf("date"),b?module.exports=g:a.match=g}}("object"==typeof sinon&&sinon||null);var commonJSModule="object"==typeof module&&"function"==typeof require;if(!this.sinon&&commonJSModule)var sinon=require("../sinon");if(function(a){function b(b,d,e){var f=a.functionName(b)+d;throw e.length&&(f+=" Received ["+c.call(e).join(", ")+"]"),new Error(f)}function e(b,c,e,f,g,h){if("number"!=typeof h)throw new TypeError("Call id is not a number");var i=a.create(d);return i.proxy=b,i.thisValue=c,i.args=e,i.returnValue=f,i.exception=g,i.callId=h,i}var c=Array.prototype.slice,d={calledOn:function(b){return a.match&&a.match.isMatcher(b)?b.test(this.thisValue):this.thisValue===b},calledWith:function(){for(var b=0,c=arguments.length;c>b;b+=1)if(!a.deepEqual(arguments[b],this.args[b]))return!1;return!0},calledWithMatch:function(){for(var b=0,c=arguments.length;c>b;b+=1){var d=this.args[b],e=arguments[b];if(!a.match||!a.match(e).test(d))return!1}return!0},calledWithExactly:function(){return arguments.length==this.args.length&&this.calledWith.apply(this,arguments)},notCalledWith:function(){return!this.calledWith.apply(this,arguments)},notCalledWithMatch:function(){return!this.calledWithMatch.apply(this,arguments)},returned:function(b){return a.deepEqual(b,this.returnValue)},threw:function(a){return"undefined"!=typeof a&&this.exception?this.exception===a||this.exception.name===a:!!this.exception},calledWithNew:function(){return this.thisValue instanceof this.proxy},calledBefore:function(a){return this.callIda.callId},callArg:function(a){this.args[a]()},callArgOn:function(a,b){this.args[a].apply(b)},callArgWith:function(a){this.callArgOnWith.apply(this,[a,null].concat(c.call(arguments,1)))},callArgOnWith:function(a,b){var d=c.call(arguments,2);this.args[a].apply(b,d)},yield:function(){this.yieldOn.apply(this,[null].concat(c.call(arguments,0)))},yieldOn:function(a){for(var d=this.args,e=0,f=d.length;f>e;++e)if("function"==typeof d[e])return d[e].apply(a,c.call(arguments,1)),void 0;b(this.proxy," cannot yield since no callback was passed.",d)},yieldTo:function(a){this.yieldToOn.apply(this,[a,null].concat(c.call(arguments,1)))},yieldToOn:function(a,d){for(var e=this.args,f=0,g=e.length;g>f;++f)if(e[f]&&"function"==typeof e[f][a])return e[f][a].apply(d,c.call(arguments,2)),void 0;b(this.proxy," cannot yield to '"+a+"' since no callback was passed.",e)},toString:function(){for(var b=this.proxy.toString()+"(",c=[],d=0,e=this.args.length;e>d;++d)c.push(a.format(this.args[d]));return b=b+c.join(", ")+")","undefined"!=typeof this.returnValue&&(b+=" => "+a.format(this.returnValue)),this.exception&&(b+=" !"+this.exception.name,this.exception.message&&(b+="("+this.exception.message+")")),b}};d.invokeCallback=d.yield,e.toString=d.toString,a.spyCall=e}("object"==typeof sinon&&sinon||null),function(sinon){function spy(a,b){if(!b&&"function"==typeof a)return spy.create(a);if(!a&&!b)return spy.create(function(){});var c=a[b];return sinon.wrapMethod(a,b,spy.create(c))}function matchingFake(a,b,c){if(a){b.length;for(var e=0,f=a.length;f>e;e++)if(a[e].matches(b,c))return a[e]}}function incrementCallCount(){this.called=!0,this.callCount+=1,this.notCalled=!1,this.calledOnce=1==this.callCount,this.calledTwice=2==this.callCount,this.calledThrice=3==this.callCount}function createCallProperties(){this.firstCall=this.getCall(0),this.secondCall=this.getCall(1),this.thirdCall=this.getCall(2),this.lastCall=this.getCall(this.callCount-1)}function createProxy(func){var p;return func.length?eval("p = (function proxy("+vars.substring(0,2*func.length-1)+") { return p.invoke(func, this, slice.call(arguments)); });"):p=function(){return p.invoke(func,this,slice.call(arguments))},p}function delegateToCalls(a,b,c,d){spyApi[a]=function(){if(!this.called)return d?d.apply(this,arguments):!1;for(var e,f=0,g=0,h=this.callCount;h>g;g+=1)if(e=this.getCall(g),e[c||a].apply(e,arguments)&&(f+=1,b))return!0;return f===this.callCount}}var commonJSModule="object"==typeof module&&"function"==typeof require,push=Array.prototype.push,slice=Array.prototype.slice,callId=0,vars="a,b,c,d,e,f,g,h,i,j,k,l",uuid=0,spyApi={reset:function(){if(this.called=!1,this.notCalled=!0,this.calledOnce=!1,this.calledTwice=!1,this.calledThrice=!1,this.callCount=0,this.firstCall=null,this.secondCall=null,this.thirdCall=null,this.lastCall=null,this.args=[],this.returnValues=[],this.thisValues=[],this.exceptions=[],this.callIds=[],this.fakes)for(var a=0;aa||a>=this.callCount?null:sinon.spyCall(this,this.thisValues[a],this.args[a],this.returnValues[a],this.exceptions[a],this.callIds[a])},calledBefore:function(a){return this.called?a.called?this.callIds[0]a.callIds[a.callCount-1]:!1},withArgs:function(){var a=slice.call(arguments);if(this.fakes){var b=matchingFake(this.fakes,a,!0);if(b)return b}else this.fakes=[];var c=this,d=this._create();d.matchingAguments=a,push.call(this.fakes,d),d.withArgs=function(){return c.withArgs.apply(c,arguments)};for(var e=0;ec;++c){var e=" "+a.getCall(c).toString();/\n/.test(b[c-1])&&(e="\n"+e),push.call(b,e)}return b.length>0?"\n"+b.join("\n"):""},t:function(a){for(var b=[],c=0,d=a.callCount;d>c;++c)push.call(b,sinon.format(a.thisValues[c]));return b.join(", ")},"*":function(a,b){for(var c=[],d=0,e=b.length;e>d;++d)push.call(c,sinon.format(b[d]));return c.join(", ")}},sinon.extend(spy,spyApi),spy.spyCall=sinon.spyCall,commonJSModule?module.exports=spy:sinon.spy=spy}("object"==typeof sinon&&sinon||null),function(a){function c(b,d,e){if(e&&"function"!=typeof e)throw new TypeError("Custom stub should be function");var f;if(f=e?a.spy&&a.spy.create?a.spy.create(e):e:c.create(),!b&&!d)return a.stub.create();if(!d&&b&&"object"==typeof b){for(var g in b)"function"==typeof b[g]&&c(b,g);return b}return a.wrapMethod(b,d,f)}function d(a,b){var c=a.callCount-1,d=a[b],e=c in d?d[c]:d[d.length-1];return a[b+"Last"]=e,e}function e(a,b){var c=d(a,"callArgAts");if(0>c){for(var e=d(a,"callArgProps"),f=0,g=b.length;g>f;++f){if(!e&&"function"==typeof b[f])return b[f];if(e&&b[f]&&"function"==typeof b[f][e])return b[f][e]}return null}return b[c]}function g(b,c,d){if(b.callArgAtsLast<0){var e;return e=b.callArgPropsLast?a.functionName(b)+" expected to yield to '"+b.callArgPropsLast+"', but no object with such a property was passed.":a.functionName(b)+" expected to yield, but no callback was passed.",d.length>0&&(e+=" Received ["+f.call(d,", ")+"]"),e}return"argument at index "+b.callArgAtsLast+" is not a function: "+c}function i(a,b){if(a.callArgAts.length>0){var c=e(a,b);if("function"!=typeof c)throw new TypeError(g(a,c,b));var f=d(a,"callbackArguments"),i=d(a,"callbackContexts");a.callbackAsync?h(function(){c.apply(i,f)}):c.apply(i,f)}}var b="object"==typeof module&&"function"==typeof require;if(!a&&b&&(a=require("../sinon")),a){var f=Array.prototype.join,h=function(){return"object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:"function"==typeof setImmediate?setImmediate:function(a){setTimeout(a,0)}}(),j=0;a.extend(c,function(){function e(a,b){return"string"==typeof a?(this.exception=new Error(b||""),this.exception.name=a):this.exception=a?a:new Error("Error"),this}var d,b=Array.prototype.slice;d={create:function(){var b=function(){if(i(b,arguments),b.exception)throw b.exception;return"number"==typeof b.returnArgAt?arguments[b.returnArgAt]:b.returnThis?this:b.returnValue};b.id="stub#"+j++;var d=b;return b=a.spy.create(b),b.func=d,b.callArgAts=[],b.callbackArguments=[],b.callbackContexts=[],b.callArgProps=[],a.extend(b,c),b._create=a.stub.create,b.displayName="stub",b.toString=a.functionToString,b},resetBehavior:function(){var a;if(this.callArgAts=[],this.callbackArguments=[],this.callbackContexts=[],this.callArgProps=[],delete this.returnValue,delete this.returnArgAt,this.returnThis=!1,this.fakes)for(a=0;ac;c+=1)b(a[c])}return{create:function(b){if(!b)throw new TypeError("object is null");var c=a.extend({},d);return c.object=b,delete c.create,c},expects:function(b){if(!b)throw new TypeError("method is falsy");if(this.expectations||(this.expectations={},this.proxies=[]),!this.expectations[b]){this.expectations[b]=[];var d=this;a.wrapMethod(this.object,b,function(){return d.invokeMethod(b,this,arguments)}),c.call(this.proxies,b)}var e=a.expectation.create(b);return c.call(this.expectations[b],e),e},restore:function(){var a=this.object;b(this.proxies,function(b){"function"==typeof a[b].restore&&a[b].restore()})},verify:function(){var d=this.expectations||{},e=[],f=[];return b(this.proxies,function(a){b(d[a],function(a){a.met()?c.call(f,a.toString()):c.call(e,a.toString())})}),this.restore(),e.length>0?a.expectation.fail(e.concat(f).join("\n")):a.expectation.pass(e.concat(f).join("\n")),!0},invokeMethod:function(b,d,e){var h,f=this.expectations&&this.expectations[b],g=f&&f.length||0;for(h=0;g>h;h+=1)if(!f[h].met()&&f[h].allowsCall(d,e))return f[h].apply(d,e);var j,i=[],k=0;for(h=0;g>h;h+=1)f[h].allowsCall(d,e)?j=j||f[h]:k+=1,c.call(i," "+f[h].toString());return 0===k?j.apply(d,e):(i.unshift("Unexpected call: "+a.spyCall.toString.call({proxy:b,args:e})),a.expectation.fail(i.join("\n")),void 0)}}}());var e=a.timesInWords;a.expectation=function(){function f(a){return 0==a?"never called":"called "+e(a)}function g(a){var b=a.minCalls,c=a.maxCalls;if("number"==typeof b&&"number"==typeof c){var d=e(b);return b!=c&&(d="at least "+d+" and at most "+e(c)),d}return"number"==typeof b?"at least "+e(b):"at most "+e(c)}function h(a){var b="number"==typeof a.minCalls;return!b||a.callCount>=a.minCalls}function i(a){return"number"!=typeof a.maxCalls?!1:a.callCount==a.maxCalls}var b=Array.prototype.slice,d=a.spy.invoke;return{minCalls:1,maxCalls:1,create:function(b){var c=a.extend(a.stub.create(),a.expectation);return delete c.create,c.method=b,c},invoke:function(a,b,c){return this.verifyCallAllowed(b,c),d.apply(this,arguments)},atLeast:function(a){if("number"!=typeof a)throw new TypeError("'"+a+"' is not number");return this.limitsSet||(this.maxCalls=null,this.limitsSet=!0),this.minCalls=a,this},atMost:function(a){if("number"!=typeof a)throw new TypeError("'"+a+"' is not number");return this.limitsSet||(this.minCalls=null,this.limitsSet=!0),this.maxCalls=a,this},never:function(){return this.exactly(0)},once:function(){return this.exactly(1)},twice:function(){return this.exactly(2)},thrice:function(){return this.exactly(3)},exactly:function(a){if("number"!=typeof a)throw new TypeError("'"+a+"' is not a number");return this.atLeast(a),this.atMost(a)},met:function(){return!this.failed&&h(this)},verifyCallAllowed:function(b,c){if(i(this)&&(this.failed=!0,a.expectation.fail(this.method+" already called "+e(this.maxCalls))),"expectedThis"in this&&this.expectedThis!==b&&a.expectation.fail(this.method+" called with "+b+" as thisValue, expected "+this.expectedThis),"expectedArguments"in this){c||a.expectation.fail(this.method+" received no arguments, expected "+a.format(this.expectedArguments)),c.lengthd;d+=1)a.deepEqual(this.expectedArguments[d],c[d])||a.expectation.fail(this.method+" received wrong arguments "+a.format(c)+", expected "+a.format(this.expectedArguments))}},allowsCall:function(b,c){if(this.met()&&i(this))return!1;if("expectedThis"in this&&this.expectedThis!==b)return!1;if(!("expectedArguments"in this))return!0;if(c=c||[],c.lengthd;d+=1)if(!a.deepEqual(this.expectedArguments[d],c[d]))return!1;return!0},withArgs:function(){return this.expectedArguments=b.call(arguments),this},withExactArgs:function(){return this.withArgs.apply(this,arguments),this.expectsExactArgCount=!0,this},on:function(a){return this.expectedThis=a,this},toString:function(){var b=(this.expectedArguments||[]).slice();this.expectsExactArgCount||c.call(b,"[...]");var d=a.spyCall.toString.call({proxy:this.method||"anonymous mock expectation",args:b}),e=d.replace(", [...","[, ...")+" "+g(this);return this.met()?"Expectation met: "+e:"Expected "+e+" ("+f(this.callCount)+")"},verify:function(){return this.met()?a.expectation.pass(this.toString()):a.expectation.fail(this.toString()),!0},pass:function(b){a.assert.pass(b) 2 | },fail:function(a){var b=new Error(a);throw b.name="ExpectationError",b}}}(),b?module.exports=d:a.mock=d}}("object"==typeof sinon&&sinon||null),function(a){function e(a){return a.fakes||(a.fakes=[]),a.fakes}function f(a,b){for(var c=e(a),d=0,f=c.length;f>d;d+=1)"function"==typeof c[d][b]&&c[d][b]()}function g(a){for(var b=e(a),c=0;c3||!/^(\d\d:){0,2}\d\d?$/.test(a))throw new Error("tick only understands numbers and 'h:m:s'");for(;d--;){if(f=parseInt(b[d],10),f>=60)throw new Error("Invalid time "+a);e+=f*Math.pow(60,c-d-1)}return 1e3*e}function createObject(a){var b;if(Object.create)b=Object.create(a);else{var c=function(){};c.prototype=a,b=new c}return b.Date.clock=b,b}function mirrorDateProperties(a,b){return b.now?a.now=function(){return a.clock.now}:delete a.now,b.toSource?a.toSource=function(){return b.toSource()}:delete a.toSource,a.toString=function(){return b.toString()},a.prototype=b.prototype,a.parse=b.parse,a.UTC=b.UTC,a.prototype.toUTCString=b.prototype.toUTCString,a}function restore(){for(var a,b=0,c=this.methods.length;c>b;b++)a=this.methods[b],global[a].hadOwnProperty?global[a]=this["_"+a]:delete global[a];this.methods=[]}function stubGlobal(a,b){if(b[a].hadOwnProperty=Object.prototype.hasOwnProperty.call(global,a),b["_"+a]=global[a],"Date"==a){var c=mirrorDateProperties(b[a],global[a]);global[a]=c}else{global[a]=function(){return b[a].apply(b,arguments)};for(var d in b[a])b[a].hasOwnProperty(d)&&(global[a][d]=b[a][d])}global[a].clock=b}var id=1;sinon.clock={now:0,create:function(a){var b=createObject(this);if("number"==typeof a&&(b.now=a),a&&"object"==typeof a)throw new TypeError("now should be milliseconds since UNIX epoch");return b},setTimeout:function(){return addTimer.call(this,arguments,!1)},clearTimeout:function(a){this.timeouts||(this.timeouts=[]),a in this.timeouts&&delete this.timeouts[a]},setInterval:function(){return addTimer.call(this,arguments,!0)},clearInterval:function(a){this.clearTimeout(a)},tick:function(a){a="number"==typeof a?a:parseTime(a);for(var f,b=this.now,c=this.now+a,d=this.now,e=this.firstTimerInRange(b,c);e&&c>=b;){if(this.timeouts[e.id]){b=this.now=e.callAt;try{this.callTimer(e)}catch(g){f=f||g}}e=this.firstTimerInRange(d,c),d=b}if(this.now=c,f)throw f;return this.now},firstTimerInRange:function(a,b){var c,d,e;for(var f in this.timeouts)if(this.timeouts.hasOwnProperty(f)){if(this.timeouts[f].callAtb)continue;(!d||this.timeouts[f].callAtc;c++)stubGlobal(b.methods[c],b);return b}}("undefined"!=typeof global&&"function"!=typeof global?global:this),sinon.timers={setTimeout:setTimeout,clearTimeout:clearTimeout,setInterval:setInterval,clearInterval:clearInterval,Date:Date},"object"==typeof module&&"function"==typeof require&&(module.exports=sinon),"undefined"==typeof sinon&&(this.sinon={}),function(){var a=[].push;sinon.Event=function(a,b,c,d){this.initEvent(a,b,c,d)},sinon.Event.prototype={initEvent:function(a,b,c,d){this.type=a,this.bubbles=b,this.cancelable=c,this.target=d},stopPropagation:function(){},preventDefault:function(){this.defaultPrevented=!0}},sinon.EventTarget={addEventListener:function(b,c){this.eventListeners=this.eventListeners||{},this.eventListeners[b]=this.eventListeners[b]||[],a.call(this.eventListeners[b],c)},removeEventListener:function(a,b){for(var d=this.eventListeners&&this.eventListeners[a]||[],e=0,f=d.length;f>e;++e)if(d[e]==b)return d.splice(e,1)},dispatchEvent:function(a){for(var b=a.type,c=this.eventListeners&&this.eventListeners[b]||[],d=0;d=0;e--)c(b[e]);"function"==typeof d.onCreate&&d.onCreate(this)}function e(a){if(a.readyState!==d.OPENED)throw new Error("INVALID_STATE_ERR");if(a.sendFlag)throw new Error("INVALID_STATE_ERR")}function f(a,b){if(a)for(var c=0,d=a.length;d>c;c+=1)b(a[c])}function g(a,b){for(var c=0;c=d.HEADERS_RECEIVED&&e(["status","statusText"]),c.readyState>=d.LOADING&&e(["responseText"]),c.readyState===d.DONE&&e(["responseXML"]),a.onreadystatechange&&a.onreadystatechange.call(a)};if(c.addEventListener){for(var j in a.eventListeners)a.eventListeners.hasOwnProperty(j)&&f(a.eventListeners[j],function(a){c.addEventListener(j,a)});c.addEventListener("readystatechange",g)}else c.onreadystatechange=g;h(c,"open",b)},d.useFilters=!1,sinon.extend(d.prototype,sinon.EventTarget,{async:!0,open:function(a,b,c,e,f){if(this.method=a,this.url=b,this.async="boolean"==typeof c?c:!0,this.username=e,this.password=f,this.responseText=null,this.responseXML=null,this.requestHeaders={},this.sendFlag=!1,sinon.FakeXMLHttpRequest.useFilters===!0){var h=arguments,i=g(d.filters,function(a){return a.apply(this,h)});if(i)return sinon.FakeXMLHttpRequest.defake(this,arguments)}this.readyStateChange(d.OPENED)},readyStateChange:function(a){if(this.readyState=a,"function"==typeof this.onreadystatechange)try{this.onreadystatechange()}catch(b){sinon.logError("Fake XHR onreadystatechange handler",b)}switch(this.dispatchEvent(new sinon.Event("readystatechange")),this.readyState){case d.DONE:this.dispatchEvent(new sinon.Event("load",!1,!1,this)),this.dispatchEvent(new sinon.Event("loadend",!1,!1,this))}},setRequestHeader:function(a,b){if(e(this),c[a]||/^(Sec-|Proxy-)/.test(a))throw new Error('Refused to set unsafe header "'+a+'"');this.requestHeaders[a]?this.requestHeaders[a]+=","+b:this.requestHeaders[a]=b},setResponseHeaders:function(a){this.responseHeaders={};for(var b in a)a.hasOwnProperty(b)&&(this.responseHeaders[b]=a[b]);this.async?this.readyStateChange(d.HEADERS_RECEIVED):this.readyState=d.HEADERS_RECEIVED},send:function(a){if(e(this),!/^(get|head)$/i.test(this.method)){if(this.requestHeaders["Content-Type"]){var b=this.requestHeaders["Content-Type"].split(";");this.requestHeaders["Content-Type"]=b[0]+";charset=utf-8"}else this.requestHeaders["Content-Type"]="text/plain;charset=utf-8";this.requestBody=a}this.errorFlag=!1,this.sendFlag=this.async,this.readyStateChange(d.OPENED),"function"==typeof this.onSend&&this.onSend(this),this.dispatchEvent(new sinon.Event("loadstart",!1,!1,this))},abort:function(){this.aborted=!0,this.responseText=null,this.errorFlag=!0,this.requestHeaders={},this.readyState>sinon.FakeXMLHttpRequest.UNSENT&&this.sendFlag&&(this.readyStateChange(sinon.FakeXMLHttpRequest.DONE),this.sendFlag=!1),this.readyState=sinon.FakeXMLHttpRequest.UNSENT,this.dispatchEvent(new sinon.Event("abort",!1,!1,this)),"function"==typeof this.onerror&&this.onerror()},getResponseHeader:function(a){if(this.readyState0&&this.respondWith.apply(this,arguments);for(var b,a=this.queue||[];b=a.shift();)this.processRequest(b)},processRequest:function(a){try{if(a.aborted)return;var b=this.response||[404,{},""];if(this.responses)for(var c=0,d=this.responses.length;d>c;c++)if(h.call(this,this.responses[c],a)){b=this.responses[c].response;break}4!=a.readyState&&(i(b,a),a.respond(b[0],b[1],b[2]))}catch(e){sinon.logError("Fake server request processing",e)}},restore:function(){return this.xhr.restore&&this.xhr.restore.apply(this.xhr,arguments)}}}(),"object"==typeof module&&"function"==typeof require&&(module.exports=sinon),function(){function a(){}a.prototype=sinon.fakeServer,sinon.fakeServerWithClock=new a,sinon.fakeServerWithClock.addRequest=function(a){if(a.async&&("object"==typeof setTimeout.clock?this.clock=setTimeout.clock:(this.clock=sinon.useFakeTimers(),this.resetClock=!0),!this.longestTimeout)){var b=this.clock.setTimeout,c=this.clock.setInterval,d=this;this.clock.setTimeout=function(a,c){return d.longestTimeout=Math.max(c,d.longestTimeout||0),b.apply(this,arguments)},this.clock.setInterval=function(a,b){return d.longestTimeout=Math.max(b,d.longestTimeout||0),c.apply(this,arguments)}}return sinon.fakeServer.addRequest.call(this,a)},sinon.fakeServerWithClock.respond=function(){var a=sinon.fakeServer.respond.apply(this,arguments);return this.clock&&(this.clock.tick(this.longestTimeout||0),this.longestTimeout=0,this.resetClock&&(this.clock.restore(),this.resetClock=!1)),a},sinon.fakeServerWithClock.restore=function(){return this.clock&&this.clock.restore(),sinon.fakeServer.restore.apply(this,arguments)}}(),"object"==typeof module&&"function"==typeof require){var sinon=require("../sinon");sinon.extend(sinon,require("./util/fake_timers"))}return function(){function b(b,c,d,e){e&&(c.injectInto?c.injectInto[d]=e:a.call(b.args,e))}function c(a){var b=sinon.create(sinon.sandbox);return a.useFakeServer&&("object"==typeof a.useFakeServer&&(b.serverPrototype=a.useFakeServer),b.useFakeServer()),a.useFakeTimers&&("object"==typeof a.useFakeTimers?b.useFakeTimers.apply(b,a.useFakeTimers):b.useFakeTimers()),b}var a=[].push;sinon.sandbox=sinon.extend(sinon.create(sinon.collection),{useFakeTimers:function(){return this.clock=sinon.useFakeTimers.apply(sinon,arguments),this.add(this.clock)},serverPrototype:sinon.fakeServer,useFakeServer:function(){var a=this.serverPrototype||sinon.fakeServer;return a&&a.create?(this.server=a.create(),this.add(this.server)):null},inject:function(a){return sinon.collection.inject.call(this,a),this.clock&&(a.clock=this.clock),this.server&&(a.server=this.server,a.requests=this.server.requests),a},create:function(a){if(!a)return sinon.create(sinon.sandbox);var d=c(a);d.args=d.args||[];var e,f,g=d.inject({});if(a.properties)for(var h=0,i=a.properties.length;i>h;h++)e=a.properties[h],f=g[e]||"sandbox"==e&&d,b(d,a,e,f);else b(d,a,"sandbox",f);return d}}),sinon.sandbox.useFakeXMLHttpRequest=sinon.sandbox.useFakeServer,"object"==typeof module&&"function"==typeof require&&(module.exports=sinon.sandbox)}(),function(a){function c(b){var c=typeof b;if("function"!=c)throw new TypeError("sinon.test needs to wrap a test function, got "+c);return function(){var c=a.getConfig(a.config);c.injectInto=c.injectIntoThis&&this||c.injectInto;var e,f,d=a.sandbox.create(c),g=Array.prototype.slice.call(arguments).concat(d.args);try{f=b.apply(this,g)}catch(h){e=h}if("undefined"!=typeof e)throw d.restore(),e;return d.verifyAndRestore(),f}}var b="object"==typeof module&&"function"==typeof require;!a&&b&&(a=require("../sinon")),a&&(c.config={injectIntoThis:!0,injectInto:null,properties:["spy","stub","mock","clock","server","requests"],useFakeTimers:!0,useFakeServer:!0},b?module.exports=c:a.test=c)}("object"==typeof sinon&&sinon||null),function(a){function c(a,b,c){return function(){b&&b.apply(this,arguments);var d,e;try{e=a.apply(this,arguments)}catch(f){d=f}if(c&&c.apply(this,arguments),d)throw d;return e}}function d(b,d){if(!b||"object"!=typeof b)throw new TypeError("sinon.testCase needs an object with test functions");d=d||"test";var g,h,i,e=new RegExp("^"+d),f={},j=b.setUp,k=b.tearDown;for(g in b)if(b.hasOwnProperty(g)){if(h=b[g],/^(setUp|tearDown)$/.test(g))continue;"function"==typeof h&&e.test(g)?(i=h,(j||k)&&(i=c(h,j,k)),f[g]=a.test(i)):f[g]=b[g]}return f}var b="object"==typeof module&&"function"==typeof require;!a&&b&&(a=require("../sinon")),a&&Object.prototype.hasOwnProperty&&(b?module.exports=d:a.testCase=d)}("object"==typeof sinon&&sinon||null),function(a,b){function f(){for(var a,b=0,c=arguments.length;c>b;++b)a=arguments[b],a||e.fail("fake is not a spy"),"function"!=typeof a&&e.fail(a+" is not a function"),"function"!=typeof a.getCall&&e.fail(a+" is not stubbed")}function g(a,c){a=a||b;var d=a.fail||e.fail;d.call(a,c)}function h(a,b,c){2==arguments.length&&(c=b,b=a),e[a]=function(h){f(h);var i=d.call(arguments,1),j=!1;j="function"==typeof b?!b(h):"function"==typeof h[b]?!h[b].apply(h,i):!h[b],j?g(this,h.printf.apply(h,[c].concat(i))):e.pass(a)}}function i(a,b){return!a||/^fail/.test(b)?b:a+b.slice(0,1).toUpperCase()+b.slice(1)}var e,c="object"==typeof module&&"function"==typeof require,d=Array.prototype.slice;!a&&c&&(a=require("../sinon")),a&&(e={failException:"AssertError",fail:function(a){var b=new Error(a);throw b.name=this.failException||e.failException,b},pass:function(){},callOrder:function(){f.apply(null,arguments);var b="",c="";if(a.calledInOrder(arguments))e.pass("callOrder");else{try{b=[].join.call(arguments,", ");for(var h=d.call(arguments),i=h.length;i;)h[--i].called||h.splice(i,1);c=a.orderByFirstCall(h).join(", ")}catch(j){}g(this,"expected "+b+" to be "+"called in order but were called as "+c)}},callCount:function(b,c){if(f(b),b.callCount!=c){var d="expected %n to be called "+a.timesInWords(c)+" but was called %c%C";g(this,b.printf(d))}else e.pass("callCount")},expose:function(a,b){if(!a)throw new TypeError("target is null or undefined");var c=b||{},d="undefined"==typeof c.prefix&&"assert"||c.prefix,e="undefined"==typeof c.includeFail||!!c.includeFail;for(var f in this)"export"==f||!e&&/^(fail)/.test(f)||(a[i(d,f)]=this[f]);return a}},h("called","expected %n to have been called at least once but was never called"),h("notCalled",function(a){return!a.called},"expected %n to not have been called but was called %c%C"),h("calledOnce","expected %n to be called once but was called %c%C"),h("calledTwice","expected %n to be called twice but was called %c%C"),h("calledThrice","expected %n to be called thrice but was called %c%C"),h("calledOn","expected %n to be called with %1 as this but was called with %t"),h("alwaysCalledOn","expected %n to always be called with %1 as this but was called with %t"),h("calledWithNew","expected %n to be called with new"),h("alwaysCalledWithNew","expected %n to always be called with new"),h("calledWith","expected %n to be called with arguments %*%C"),h("calledWithMatch","expected %n to be called with match %*%C"),h("alwaysCalledWith","expected %n to always be called with arguments %*%C"),h("alwaysCalledWithMatch","expected %n to always be called with match %*%C"),h("calledWithExactly","expected %n to be called with exact arguments %*%C"),h("alwaysCalledWithExactly","expected %n to always be called with exact arguments %*%C"),h("neverCalledWith","expected %n to never be called with arguments %*%C"),h("neverCalledWithMatch","expected %n to never be called with match %*%C"),h("threw","%n did not throw exception%C"),h("alwaysThrew","%n did not always throw exception%C"),c?module.exports=e:a.assert=e)}("object"==typeof sinon&&sinon||null,"undefined"!=typeof window?window:"undefined"!=typeof self?self:global),sinon}.call("undefined"!=typeof window&&window||{}); 3 | --------------------------------------------------------------------------------