├── .gitignore ├── README.md ├── browserify-mocha-should ├── README.md ├── _tests.js ├── index.html ├── mocha.css ├── mocha.js ├── package.json └── tests.js ├── index.html ├── karma-browserify-mocha-should ├── karma.conf.js ├── package.json └── test.js ├── karma-requirejs-mocha-should ├── karma.conf.js ├── lib │ └── my_code.js ├── main.js ├── package.json └── test │ └── test.js ├── my_code.js ├── package.json ├── simple-mocha-should-requirejs ├── README.md ├── index.html ├── mocha.css ├── mocha.js ├── package.json ├── tests-main.js └── tests.js ├── simple-mocha-should ├── README.md ├── index.html ├── mocha.css ├── mocha.js ├── package.json └── tests.js └── zuul-mocha-should ├── package.json └── tests.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Examples of tests 2 | 3 | All examples assume you have node and npm, and you know what is it. 4 | 5 | First do in root of repo: 6 | 7 | ``` 8 | npm i 9 | ``` 10 | 11 | ## Most simple way - include all script's 12 | 13 | Look in `simple-mocha-should` directory to look on most basic way to run tests with `mocha` and `should`. To repeat such steps: 14 | 15 | Assume you in project folder 16 | 17 | ```shell 18 | //if it is not inited before, provide some answers 19 | npm init 20 | 21 | // install dependencies 22 | npm i --save-dev mocha should 23 | 24 | ./node_modules/.bin/mocha init folder_with_browser_tests 25 | ``` 26 | 27 | This will create basic structure you can see in `simple-mocha-should`, now you need to add script tags 28 | for should **before** your tests (mocha will add tests.js file by default). That is all, simple and practically useless. 29 | //if it is not inited before, provide some answers 30 | To run this example run `npm run browser` and open http://localhost:8080/simple-mocha-should/index.html 31 | 32 | ## The same simple way but load tests with requirejs 33 | 34 | In this example we load everything with requirejs, you can see simple-mocha-should-requirejs to understand how it works. 35 | 36 | To run this example run `npm run browser` and open http://localhost:8080/simple-mocha-should-requirejs/index.html 37 | 38 | ## Build test scripts with browserify 39 | 40 | To run build of tests `npm run build` in folder `browserify-mocha-should` and then run as before: 41 | 42 | `npm run browser` and open http://localhost:8080/browserify-mocha-should/index.html 43 | 44 | ## Adding zuul 45 | 46 | zuul allow automatically build tests in bundle and have good integration with sauce-labs. 47 | But you still need locally open each browser by hands for tests 48 | 49 | ## Launch browsers with karma 50 | 51 | Karma allow to run browser (also it sauce labs integration). All configuration happen in karma.conf.js files. 52 | To run tests just `npm test`. 53 | 54 | `karma-browserify-mocha-should` contain example of using browserify to bundle files. 55 | 56 | `karma-requirejs-mocha-should` contain example of using requirejs to load files 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /browserify-mocha-should/README.md: -------------------------------------------------------------------------------- 1 | `Browserify` require that you build test first, for automation you can use `watchify` module. 2 | 3 | To build tests: 4 | ``` 5 | npm i 6 | npm run build 7 | ``` 8 | Now you can open this index.html in browser. Don't forget to look on package.json to see how browserify called. 9 | As an additional step you will need to combine you tests in some way (e.g. require each from one file, or concat them). -------------------------------------------------------------------------------- /browserify-mocha-should/_tests.js: -------------------------------------------------------------------------------- 1 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 6 | * @license MIT 7 | */ 8 | 9 | var base64 = require('base64-js') 10 | var ieee754 = require('ieee754') 11 | var isArray = require('is-array') 12 | 13 | exports.Buffer = Buffer 14 | exports.SlowBuffer = SlowBuffer 15 | exports.INSPECT_MAX_BYTES = 50 16 | Buffer.poolSize = 8192 // not used by this implementation 17 | 18 | var kMaxLength = 0x3fffffff 19 | var rootParent = {} 20 | 21 | /** 22 | * If `Buffer.TYPED_ARRAY_SUPPORT`: 23 | * === true Use Uint8Array implementation (fastest) 24 | * === false Use Object implementation (most compatible, even IE6) 25 | * 26 | * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, 27 | * Opera 11.6+, iOS 4.2+. 28 | * 29 | * Note: 30 | * 31 | * - Implementation must support adding new properties to `Uint8Array` instances. 32 | * Firefox 4-29 lacked support, fixed in Firefox 30+. 33 | * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. 34 | * 35 | * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. 36 | * 37 | * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of 38 | * incorrect length in some situations. 39 | * 40 | * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will 41 | * get the Object implementation, which is slower but will work correctly. 42 | */ 43 | Buffer.TYPED_ARRAY_SUPPORT = (function () { 44 | try { 45 | var buf = new ArrayBuffer(0) 46 | var arr = new Uint8Array(buf) 47 | arr.foo = function () { return 42 } 48 | return 42 === arr.foo() && // typed array instances can be augmented 49 | typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` 50 | new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` 51 | } catch (e) { 52 | return false 53 | } 54 | })() 55 | 56 | /** 57 | * Class: Buffer 58 | * ============= 59 | * 60 | * The Buffer constructor returns instances of `Uint8Array` that are augmented 61 | * with function properties for all the node `Buffer` API functions. We use 62 | * `Uint8Array` so that square bracket notation works as expected -- it returns 63 | * a single octet. 64 | * 65 | * By augmenting the instances, we can avoid modifying the `Uint8Array` 66 | * prototype. 67 | */ 68 | function Buffer (subject, encoding, noZero) { 69 | if (!(this instanceof Buffer)) 70 | return new Buffer(subject, encoding, noZero) 71 | 72 | var type = typeof subject 73 | 74 | // Find the length 75 | var length 76 | if (type === 'number') 77 | length = subject > 0 ? subject >>> 0 : 0 78 | else if (type === 'string') { 79 | length = Buffer.byteLength(subject, encoding) 80 | } else if (type === 'object' && subject !== null) { // assume object is array-like 81 | if (subject.type === 'Buffer' && isArray(subject.data)) 82 | subject = subject.data 83 | length = +subject.length > 0 ? Math.floor(+subject.length) : 0 84 | } else 85 | throw new TypeError('must start with number, buffer, array or string') 86 | 87 | if (length > kMaxLength) 88 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 89 | 'size: 0x' + kMaxLength.toString(16) + ' bytes') 90 | 91 | var buf 92 | if (Buffer.TYPED_ARRAY_SUPPORT) { 93 | // Preferred: Return an augmented `Uint8Array` instance for best performance 94 | buf = Buffer._augment(new Uint8Array(length)) 95 | } else { 96 | // Fallback: Return THIS instance of Buffer (created by `new`) 97 | buf = this 98 | buf.length = length 99 | buf._isBuffer = true 100 | } 101 | 102 | var i 103 | if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') { 104 | // Speed optimization -- use set if we're copying from a typed array 105 | buf._set(subject) 106 | } else if (isArrayish(subject)) { 107 | // Treat array-ish objects as a byte array 108 | if (Buffer.isBuffer(subject)) { 109 | for (i = 0; i < length; i++) 110 | buf[i] = subject.readUInt8(i) 111 | } else { 112 | for (i = 0; i < length; i++) 113 | buf[i] = ((subject[i] % 256) + 256) % 256 114 | } 115 | } else if (type === 'string') { 116 | buf.write(subject, 0, encoding) 117 | } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT && !noZero) { 118 | for (i = 0; i < length; i++) { 119 | buf[i] = 0 120 | } 121 | } 122 | 123 | if (length > 0 && length <= Buffer.poolSize) 124 | buf.parent = rootParent 125 | 126 | return buf 127 | } 128 | 129 | function SlowBuffer(subject, encoding, noZero) { 130 | if (!(this instanceof SlowBuffer)) 131 | return new SlowBuffer(subject, encoding, noZero) 132 | 133 | var buf = new Buffer(subject, encoding, noZero) 134 | delete buf.parent 135 | return buf 136 | } 137 | 138 | Buffer.isBuffer = function (b) { 139 | return !!(b != null && b._isBuffer) 140 | } 141 | 142 | Buffer.compare = function (a, b) { 143 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) 144 | throw new TypeError('Arguments must be Buffers') 145 | 146 | var x = a.length 147 | var y = b.length 148 | for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {} 149 | if (i !== len) { 150 | x = a[i] 151 | y = b[i] 152 | } 153 | if (x < y) return -1 154 | if (y < x) return 1 155 | return 0 156 | } 157 | 158 | Buffer.isEncoding = function (encoding) { 159 | switch (String(encoding).toLowerCase()) { 160 | case 'hex': 161 | case 'utf8': 162 | case 'utf-8': 163 | case 'ascii': 164 | case 'binary': 165 | case 'base64': 166 | case 'raw': 167 | case 'ucs2': 168 | case 'ucs-2': 169 | case 'utf16le': 170 | case 'utf-16le': 171 | return true 172 | default: 173 | return false 174 | } 175 | } 176 | 177 | Buffer.concat = function (list, totalLength) { 178 | if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])') 179 | 180 | if (list.length === 0) { 181 | return new Buffer(0) 182 | } else if (list.length === 1) { 183 | return list[0] 184 | } 185 | 186 | var i 187 | if (totalLength === undefined) { 188 | totalLength = 0 189 | for (i = 0; i < list.length; i++) { 190 | totalLength += list[i].length 191 | } 192 | } 193 | 194 | var buf = new Buffer(totalLength) 195 | var pos = 0 196 | for (i = 0; i < list.length; i++) { 197 | var item = list[i] 198 | item.copy(buf, pos) 199 | pos += item.length 200 | } 201 | return buf 202 | } 203 | 204 | Buffer.byteLength = function (str, encoding) { 205 | var ret 206 | str = str + '' 207 | switch (encoding || 'utf8') { 208 | case 'ascii': 209 | case 'binary': 210 | case 'raw': 211 | ret = str.length 212 | break 213 | case 'ucs2': 214 | case 'ucs-2': 215 | case 'utf16le': 216 | case 'utf-16le': 217 | ret = str.length * 2 218 | break 219 | case 'hex': 220 | ret = str.length >>> 1 221 | break 222 | case 'utf8': 223 | case 'utf-8': 224 | ret = utf8ToBytes(str).length 225 | break 226 | case 'base64': 227 | ret = base64ToBytes(str).length 228 | break 229 | default: 230 | ret = str.length 231 | } 232 | return ret 233 | } 234 | 235 | // pre-set for values that may exist in the future 236 | Buffer.prototype.length = undefined 237 | Buffer.prototype.parent = undefined 238 | 239 | // toString(encoding, start=0, end=buffer.length) 240 | Buffer.prototype.toString = function (encoding, start, end) { 241 | var loweredCase = false 242 | 243 | start = start >>> 0 244 | end = end === undefined || end === Infinity ? this.length : end >>> 0 245 | 246 | if (!encoding) encoding = 'utf8' 247 | if (start < 0) start = 0 248 | if (end > this.length) end = this.length 249 | if (end <= start) return '' 250 | 251 | while (true) { 252 | switch (encoding) { 253 | case 'hex': 254 | return hexSlice(this, start, end) 255 | 256 | case 'utf8': 257 | case 'utf-8': 258 | return utf8Slice(this, start, end) 259 | 260 | case 'ascii': 261 | return asciiSlice(this, start, end) 262 | 263 | case 'binary': 264 | return binarySlice(this, start, end) 265 | 266 | case 'base64': 267 | return base64Slice(this, start, end) 268 | 269 | case 'ucs2': 270 | case 'ucs-2': 271 | case 'utf16le': 272 | case 'utf-16le': 273 | return utf16leSlice(this, start, end) 274 | 275 | default: 276 | if (loweredCase) 277 | throw new TypeError('Unknown encoding: ' + encoding) 278 | encoding = (encoding + '').toLowerCase() 279 | loweredCase = true 280 | } 281 | } 282 | } 283 | 284 | Buffer.prototype.equals = function (b) { 285 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') 286 | return Buffer.compare(this, b) === 0 287 | } 288 | 289 | Buffer.prototype.inspect = function () { 290 | var str = '' 291 | var max = exports.INSPECT_MAX_BYTES 292 | if (this.length > 0) { 293 | str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') 294 | if (this.length > max) 295 | str += ' ... ' 296 | } 297 | return '' 298 | } 299 | 300 | Buffer.prototype.compare = function (b) { 301 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') 302 | return Buffer.compare(this, b) 303 | } 304 | 305 | // `get` will be removed in Node 0.13+ 306 | Buffer.prototype.get = function (offset) { 307 | console.log('.get() is deprecated. Access using array indexes instead.') 308 | return this.readUInt8(offset) 309 | } 310 | 311 | // `set` will be removed in Node 0.13+ 312 | Buffer.prototype.set = function (v, offset) { 313 | console.log('.set() is deprecated. Access using array indexes instead.') 314 | return this.writeUInt8(v, offset) 315 | } 316 | 317 | function hexWrite (buf, string, offset, length) { 318 | offset = Number(offset) || 0 319 | var remaining = buf.length - offset 320 | if (!length) { 321 | length = remaining 322 | } else { 323 | length = Number(length) 324 | if (length > remaining) { 325 | length = remaining 326 | } 327 | } 328 | 329 | // must be an even number of digits 330 | var strLen = string.length 331 | if (strLen % 2 !== 0) throw new Error('Invalid hex string') 332 | 333 | if (length > strLen / 2) { 334 | length = strLen / 2 335 | } 336 | for (var i = 0; i < length; i++) { 337 | var byte = parseInt(string.substr(i * 2, 2), 16) 338 | if (isNaN(byte)) throw new Error('Invalid hex string') 339 | buf[offset + i] = byte 340 | } 341 | return i 342 | } 343 | 344 | function utf8Write (buf, string, offset, length) { 345 | var charsWritten = blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) 346 | return charsWritten 347 | } 348 | 349 | function asciiWrite (buf, string, offset, length) { 350 | var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length) 351 | return charsWritten 352 | } 353 | 354 | function binaryWrite (buf, string, offset, length) { 355 | return asciiWrite(buf, string, offset, length) 356 | } 357 | 358 | function base64Write (buf, string, offset, length) { 359 | var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length) 360 | return charsWritten 361 | } 362 | 363 | function utf16leWrite (buf, string, offset, length) { 364 | var charsWritten = blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length, 2) 365 | return charsWritten 366 | } 367 | 368 | Buffer.prototype.write = function (string, offset, length, encoding) { 369 | // Support both (string, offset, length, encoding) 370 | // and the legacy (string, encoding, offset, length) 371 | if (isFinite(offset)) { 372 | if (!isFinite(length)) { 373 | encoding = length 374 | length = undefined 375 | } 376 | } else { // legacy 377 | var swap = encoding 378 | encoding = offset 379 | offset = length 380 | length = swap 381 | } 382 | 383 | offset = Number(offset) || 0 384 | 385 | if (length < 0 || offset < 0 || offset > this.length) 386 | throw new RangeError('attempt to write outside buffer bounds'); 387 | 388 | var remaining = this.length - offset 389 | if (!length) { 390 | length = remaining 391 | } else { 392 | length = Number(length) 393 | if (length > remaining) { 394 | length = remaining 395 | } 396 | } 397 | encoding = String(encoding || 'utf8').toLowerCase() 398 | 399 | var ret 400 | switch (encoding) { 401 | case 'hex': 402 | ret = hexWrite(this, string, offset, length) 403 | break 404 | case 'utf8': 405 | case 'utf-8': 406 | ret = utf8Write(this, string, offset, length) 407 | break 408 | case 'ascii': 409 | ret = asciiWrite(this, string, offset, length) 410 | break 411 | case 'binary': 412 | ret = binaryWrite(this, string, offset, length) 413 | break 414 | case 'base64': 415 | ret = base64Write(this, string, offset, length) 416 | break 417 | case 'ucs2': 418 | case 'ucs-2': 419 | case 'utf16le': 420 | case 'utf-16le': 421 | ret = utf16leWrite(this, string, offset, length) 422 | break 423 | default: 424 | throw new TypeError('Unknown encoding: ' + encoding) 425 | } 426 | return ret 427 | } 428 | 429 | Buffer.prototype.toJSON = function () { 430 | return { 431 | type: 'Buffer', 432 | data: Array.prototype.slice.call(this._arr || this, 0) 433 | } 434 | } 435 | 436 | function base64Slice (buf, start, end) { 437 | if (start === 0 && end === buf.length) { 438 | return base64.fromByteArray(buf) 439 | } else { 440 | return base64.fromByteArray(buf.slice(start, end)) 441 | } 442 | } 443 | 444 | function utf8Slice (buf, start, end) { 445 | var res = '' 446 | var tmp = '' 447 | end = Math.min(buf.length, end) 448 | 449 | for (var i = start; i < end; i++) { 450 | if (buf[i] <= 0x7F) { 451 | res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) 452 | tmp = '' 453 | } else { 454 | tmp += '%' + buf[i].toString(16) 455 | } 456 | } 457 | 458 | return res + decodeUtf8Char(tmp) 459 | } 460 | 461 | function asciiSlice (buf, start, end) { 462 | var ret = '' 463 | end = Math.min(buf.length, end) 464 | 465 | for (var i = start; i < end; i++) { 466 | ret += String.fromCharCode(buf[i] & 0x7F) 467 | } 468 | return ret 469 | } 470 | 471 | function binarySlice (buf, start, end) { 472 | var ret = '' 473 | end = Math.min(buf.length, end) 474 | 475 | for (var i = start; i < end; i++) { 476 | ret += String.fromCharCode(buf[i]) 477 | } 478 | return ret 479 | } 480 | 481 | function hexSlice (buf, start, end) { 482 | var len = buf.length 483 | 484 | if (!start || start < 0) start = 0 485 | if (!end || end < 0 || end > len) end = len 486 | 487 | var out = '' 488 | for (var i = start; i < end; i++) { 489 | out += toHex(buf[i]) 490 | } 491 | return out 492 | } 493 | 494 | function utf16leSlice (buf, start, end) { 495 | var bytes = buf.slice(start, end) 496 | var res = '' 497 | for (var i = 0; i < bytes.length; i += 2) { 498 | res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) 499 | } 500 | return res 501 | } 502 | 503 | Buffer.prototype.slice = function (start, end) { 504 | var len = this.length 505 | start = ~~start 506 | end = end === undefined ? len : ~~end 507 | 508 | if (start < 0) { 509 | start += len; 510 | if (start < 0) 511 | start = 0 512 | } else if (start > len) { 513 | start = len 514 | } 515 | 516 | if (end < 0) { 517 | end += len 518 | if (end < 0) 519 | end = 0 520 | } else if (end > len) { 521 | end = len 522 | } 523 | 524 | if (end < start) 525 | end = start 526 | 527 | var newBuf 528 | if (Buffer.TYPED_ARRAY_SUPPORT) { 529 | newBuf = Buffer._augment(this.subarray(start, end)) 530 | } else { 531 | var sliceLen = end - start 532 | newBuf = new Buffer(sliceLen, undefined, true) 533 | for (var i = 0; i < sliceLen; i++) { 534 | newBuf[i] = this[i + start] 535 | } 536 | } 537 | 538 | if (newBuf.length) 539 | newBuf.parent = this.parent || this 540 | 541 | return newBuf 542 | } 543 | 544 | /* 545 | * Need to make sure that buffer isn't trying to write out of bounds. 546 | */ 547 | function checkOffset (offset, ext, length) { 548 | if ((offset % 1) !== 0 || offset < 0) 549 | throw new RangeError('offset is not uint') 550 | if (offset + ext > length) 551 | throw new RangeError('Trying to access beyond buffer length') 552 | } 553 | 554 | Buffer.prototype.readUIntLE = function (offset, byteLength, noAssert) { 555 | offset = offset >>> 0 556 | byteLength = byteLength >>> 0 557 | if (!noAssert) 558 | checkOffset(offset, byteLength, this.length) 559 | 560 | var val = this[offset] 561 | var mul = 1 562 | var i = 0 563 | while (++i < byteLength && (mul *= 0x100)) 564 | val += this[offset + i] * mul 565 | 566 | return val 567 | } 568 | 569 | Buffer.prototype.readUIntBE = function (offset, byteLength, noAssert) { 570 | offset = offset >>> 0 571 | byteLength = byteLength >>> 0 572 | if (!noAssert) 573 | checkOffset(offset, byteLength, this.length) 574 | 575 | var val = this[offset + --byteLength] 576 | var mul = 1 577 | while (byteLength > 0 && (mul *= 0x100)) 578 | val += this[offset + --byteLength] * mul; 579 | 580 | return val 581 | } 582 | 583 | Buffer.prototype.readUInt8 = function (offset, noAssert) { 584 | if (!noAssert) 585 | checkOffset(offset, 1, this.length) 586 | return this[offset] 587 | } 588 | 589 | Buffer.prototype.readUInt16LE = function (offset, noAssert) { 590 | if (!noAssert) 591 | checkOffset(offset, 2, this.length) 592 | return this[offset] | (this[offset + 1] << 8) 593 | } 594 | 595 | Buffer.prototype.readUInt16BE = function (offset, noAssert) { 596 | if (!noAssert) 597 | checkOffset(offset, 2, this.length) 598 | return (this[offset] << 8) | this[offset + 1] 599 | } 600 | 601 | Buffer.prototype.readUInt32LE = function (offset, noAssert) { 602 | if (!noAssert) 603 | checkOffset(offset, 4, this.length) 604 | 605 | return ((this[offset]) | 606 | (this[offset + 1] << 8) | 607 | (this[offset + 2] << 16)) + 608 | (this[offset + 3] * 0x1000000) 609 | } 610 | 611 | Buffer.prototype.readUInt32BE = function (offset, noAssert) { 612 | if (!noAssert) 613 | checkOffset(offset, 4, this.length) 614 | 615 | return (this[offset] * 0x1000000) + 616 | ((this[offset + 1] << 16) | 617 | (this[offset + 2] << 8) | 618 | this[offset + 3]) 619 | } 620 | 621 | Buffer.prototype.readIntLE = function (offset, byteLength, noAssert) { 622 | offset = offset >>> 0 623 | byteLength = byteLength >>> 0 624 | if (!noAssert) 625 | checkOffset(offset, byteLength, this.length) 626 | 627 | var val = this[offset] 628 | var mul = 1 629 | var i = 0 630 | while (++i < byteLength && (mul *= 0x100)) 631 | val += this[offset + i] * mul 632 | mul *= 0x80 633 | 634 | if (val >= mul) 635 | val -= Math.pow(2, 8 * byteLength) 636 | 637 | return val 638 | } 639 | 640 | Buffer.prototype.readIntBE = function (offset, byteLength, noAssert) { 641 | offset = offset >>> 0 642 | byteLength = byteLength >>> 0 643 | if (!noAssert) 644 | checkOffset(offset, byteLength, this.length) 645 | 646 | var i = byteLength 647 | var mul = 1 648 | var val = this[offset + --i] 649 | while (i > 0 && (mul *= 0x100)) 650 | val += this[offset + --i] * mul 651 | mul *= 0x80 652 | 653 | if (val >= mul) 654 | val -= Math.pow(2, 8 * byteLength) 655 | 656 | return val 657 | } 658 | 659 | Buffer.prototype.readInt8 = function (offset, noAssert) { 660 | if (!noAssert) 661 | checkOffset(offset, 1, this.length) 662 | if (!(this[offset] & 0x80)) 663 | return (this[offset]) 664 | return ((0xff - this[offset] + 1) * -1) 665 | } 666 | 667 | Buffer.prototype.readInt16LE = function (offset, noAssert) { 668 | if (!noAssert) 669 | checkOffset(offset, 2, this.length) 670 | var val = this[offset] | (this[offset + 1] << 8) 671 | return (val & 0x8000) ? val | 0xFFFF0000 : val 672 | } 673 | 674 | Buffer.prototype.readInt16BE = function (offset, noAssert) { 675 | if (!noAssert) 676 | checkOffset(offset, 2, this.length) 677 | var val = this[offset + 1] | (this[offset] << 8) 678 | return (val & 0x8000) ? val | 0xFFFF0000 : val 679 | } 680 | 681 | Buffer.prototype.readInt32LE = function (offset, noAssert) { 682 | if (!noAssert) 683 | checkOffset(offset, 4, this.length) 684 | 685 | return (this[offset]) | 686 | (this[offset + 1] << 8) | 687 | (this[offset + 2] << 16) | 688 | (this[offset + 3] << 24) 689 | } 690 | 691 | Buffer.prototype.readInt32BE = function (offset, noAssert) { 692 | if (!noAssert) 693 | checkOffset(offset, 4, this.length) 694 | 695 | return (this[offset] << 24) | 696 | (this[offset + 1] << 16) | 697 | (this[offset + 2] << 8) | 698 | (this[offset + 3]) 699 | } 700 | 701 | Buffer.prototype.readFloatLE = function (offset, noAssert) { 702 | if (!noAssert) 703 | checkOffset(offset, 4, this.length) 704 | return ieee754.read(this, offset, true, 23, 4) 705 | } 706 | 707 | Buffer.prototype.readFloatBE = function (offset, noAssert) { 708 | if (!noAssert) 709 | checkOffset(offset, 4, this.length) 710 | return ieee754.read(this, offset, false, 23, 4) 711 | } 712 | 713 | Buffer.prototype.readDoubleLE = function (offset, noAssert) { 714 | if (!noAssert) 715 | checkOffset(offset, 8, this.length) 716 | return ieee754.read(this, offset, true, 52, 8) 717 | } 718 | 719 | Buffer.prototype.readDoubleBE = function (offset, noAssert) { 720 | if (!noAssert) 721 | checkOffset(offset, 8, this.length) 722 | return ieee754.read(this, offset, false, 52, 8) 723 | } 724 | 725 | function checkInt (buf, value, offset, ext, max, min) { 726 | if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance') 727 | if (value > max || value < min) throw new RangeError('value is out of bounds') 728 | if (offset + ext > buf.length) throw new RangeError('index out of range') 729 | } 730 | 731 | Buffer.prototype.writeUIntLE = function (value, offset, byteLength, noAssert) { 732 | value = +value 733 | offset = offset >>> 0 734 | byteLength = byteLength >>> 0 735 | if (!noAssert) 736 | checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) 737 | 738 | var mul = 1 739 | var i = 0 740 | this[offset] = value & 0xFF 741 | while (++i < byteLength && (mul *= 0x100)) 742 | this[offset + i] = (value / mul) >>> 0 & 0xFF 743 | 744 | return offset + byteLength 745 | } 746 | 747 | Buffer.prototype.writeUIntBE = function (value, offset, byteLength, noAssert) { 748 | value = +value 749 | offset = offset >>> 0 750 | byteLength = byteLength >>> 0 751 | if (!noAssert) 752 | checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) 753 | 754 | var i = byteLength - 1 755 | var mul = 1 756 | this[offset + i] = value & 0xFF 757 | while (--i >= 0 && (mul *= 0x100)) 758 | this[offset + i] = (value / mul) >>> 0 & 0xFF 759 | 760 | return offset + byteLength 761 | } 762 | 763 | Buffer.prototype.writeUInt8 = function (value, offset, noAssert) { 764 | value = +value 765 | offset = offset >>> 0 766 | if (!noAssert) 767 | checkInt(this, value, offset, 1, 0xff, 0) 768 | if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) 769 | this[offset] = value 770 | return offset + 1 771 | } 772 | 773 | function objectWriteUInt16 (buf, value, offset, littleEndian) { 774 | if (value < 0) value = 0xffff + value + 1 775 | for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) { 776 | buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> 777 | (littleEndian ? i : 1 - i) * 8 778 | } 779 | } 780 | 781 | Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) { 782 | value = +value 783 | offset = offset >>> 0 784 | if (!noAssert) 785 | checkInt(this, value, offset, 2, 0xffff, 0) 786 | if (Buffer.TYPED_ARRAY_SUPPORT) { 787 | this[offset] = value 788 | this[offset + 1] = (value >>> 8) 789 | } else objectWriteUInt16(this, value, offset, true) 790 | return offset + 2 791 | } 792 | 793 | Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) { 794 | value = +value 795 | offset = offset >>> 0 796 | if (!noAssert) 797 | checkInt(this, value, offset, 2, 0xffff, 0) 798 | if (Buffer.TYPED_ARRAY_SUPPORT) { 799 | this[offset] = (value >>> 8) 800 | this[offset + 1] = value 801 | } else objectWriteUInt16(this, value, offset, false) 802 | return offset + 2 803 | } 804 | 805 | function objectWriteUInt32 (buf, value, offset, littleEndian) { 806 | if (value < 0) value = 0xffffffff + value + 1 807 | for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) { 808 | buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff 809 | } 810 | } 811 | 812 | Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) { 813 | value = +value 814 | offset = offset >>> 0 815 | if (!noAssert) 816 | checkInt(this, value, offset, 4, 0xffffffff, 0) 817 | if (Buffer.TYPED_ARRAY_SUPPORT) { 818 | this[offset + 3] = (value >>> 24) 819 | this[offset + 2] = (value >>> 16) 820 | this[offset + 1] = (value >>> 8) 821 | this[offset] = value 822 | } else objectWriteUInt32(this, value, offset, true) 823 | return offset + 4 824 | } 825 | 826 | Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) { 827 | value = +value 828 | offset = offset >>> 0 829 | if (!noAssert) 830 | checkInt(this, value, offset, 4, 0xffffffff, 0) 831 | if (Buffer.TYPED_ARRAY_SUPPORT) { 832 | this[offset] = (value >>> 24) 833 | this[offset + 1] = (value >>> 16) 834 | this[offset + 2] = (value >>> 8) 835 | this[offset + 3] = value 836 | } else objectWriteUInt32(this, value, offset, false) 837 | return offset + 4 838 | } 839 | 840 | Buffer.prototype.writeIntLE = function (value, offset, byteLength, noAssert) { 841 | value = +value 842 | offset = offset >>> 0 843 | if (!noAssert) { 844 | checkInt(this, 845 | value, 846 | offset, 847 | byteLength, 848 | Math.pow(2, 8 * byteLength - 1) - 1, 849 | -Math.pow(2, 8 * byteLength - 1)) 850 | } 851 | 852 | var i = 0 853 | var mul = 1 854 | var sub = value < 0 ? 1 : 0 855 | this[offset] = value & 0xFF 856 | while (++i < byteLength && (mul *= 0x100)) 857 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF 858 | 859 | return offset + byteLength 860 | } 861 | 862 | Buffer.prototype.writeIntBE = function (value, offset, byteLength, noAssert) { 863 | value = +value 864 | offset = offset >>> 0 865 | if (!noAssert) { 866 | checkInt(this, 867 | value, 868 | offset, 869 | byteLength, 870 | Math.pow(2, 8 * byteLength - 1) - 1, 871 | -Math.pow(2, 8 * byteLength - 1)) 872 | } 873 | 874 | var i = byteLength - 1 875 | var mul = 1 876 | var sub = value < 0 ? 1 : 0 877 | this[offset + i] = value & 0xFF 878 | while (--i >= 0 && (mul *= 0x100)) 879 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF 880 | 881 | return offset + byteLength 882 | } 883 | 884 | Buffer.prototype.writeInt8 = function (value, offset, noAssert) { 885 | value = +value 886 | offset = offset >>> 0 887 | if (!noAssert) 888 | checkInt(this, value, offset, 1, 0x7f, -0x80) 889 | if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) 890 | if (value < 0) value = 0xff + value + 1 891 | this[offset] = value 892 | return offset + 1 893 | } 894 | 895 | Buffer.prototype.writeInt16LE = function (value, offset, noAssert) { 896 | value = +value 897 | offset = offset >>> 0 898 | if (!noAssert) 899 | checkInt(this, value, offset, 2, 0x7fff, -0x8000) 900 | if (Buffer.TYPED_ARRAY_SUPPORT) { 901 | this[offset] = value 902 | this[offset + 1] = (value >>> 8) 903 | } else objectWriteUInt16(this, value, offset, true) 904 | return offset + 2 905 | } 906 | 907 | Buffer.prototype.writeInt16BE = function (value, offset, noAssert) { 908 | value = +value 909 | offset = offset >>> 0 910 | if (!noAssert) 911 | checkInt(this, value, offset, 2, 0x7fff, -0x8000) 912 | if (Buffer.TYPED_ARRAY_SUPPORT) { 913 | this[offset] = (value >>> 8) 914 | this[offset + 1] = value 915 | } else objectWriteUInt16(this, value, offset, false) 916 | return offset + 2 917 | } 918 | 919 | Buffer.prototype.writeInt32LE = function (value, offset, noAssert) { 920 | value = +value 921 | offset = offset >>> 0 922 | if (!noAssert) 923 | checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) 924 | if (Buffer.TYPED_ARRAY_SUPPORT) { 925 | this[offset] = value 926 | this[offset + 1] = (value >>> 8) 927 | this[offset + 2] = (value >>> 16) 928 | this[offset + 3] = (value >>> 24) 929 | } else objectWriteUInt32(this, value, offset, true) 930 | return offset + 4 931 | } 932 | 933 | Buffer.prototype.writeInt32BE = function (value, offset, noAssert) { 934 | value = +value 935 | offset = offset >>> 0 936 | if (!noAssert) 937 | checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) 938 | if (value < 0) value = 0xffffffff + value + 1 939 | if (Buffer.TYPED_ARRAY_SUPPORT) { 940 | this[offset] = (value >>> 24) 941 | this[offset + 1] = (value >>> 16) 942 | this[offset + 2] = (value >>> 8) 943 | this[offset + 3] = value 944 | } else objectWriteUInt32(this, value, offset, false) 945 | return offset + 4 946 | } 947 | 948 | function checkIEEE754 (buf, value, offset, ext, max, min) { 949 | if (value > max || value < min) throw new RangeError('value is out of bounds') 950 | if (offset + ext > buf.length) throw new RangeError('index out of range') 951 | if (offset < 0) throw new RangeError('index out of range') 952 | } 953 | 954 | function writeFloat (buf, value, offset, littleEndian, noAssert) { 955 | if (!noAssert) 956 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) 957 | ieee754.write(buf, value, offset, littleEndian, 23, 4) 958 | return offset + 4 959 | } 960 | 961 | Buffer.prototype.writeFloatLE = function (value, offset, noAssert) { 962 | return writeFloat(this, value, offset, true, noAssert) 963 | } 964 | 965 | Buffer.prototype.writeFloatBE = function (value, offset, noAssert) { 966 | return writeFloat(this, value, offset, false, noAssert) 967 | } 968 | 969 | function writeDouble (buf, value, offset, littleEndian, noAssert) { 970 | if (!noAssert) 971 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) 972 | ieee754.write(buf, value, offset, littleEndian, 52, 8) 973 | return offset + 8 974 | } 975 | 976 | Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) { 977 | return writeDouble(this, value, offset, true, noAssert) 978 | } 979 | 980 | Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) { 981 | return writeDouble(this, value, offset, false, noAssert) 982 | } 983 | 984 | // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) 985 | Buffer.prototype.copy = function (target, target_start, start, end) { 986 | var source = this 987 | 988 | if (!start) start = 0 989 | if (!end && end !== 0) end = this.length 990 | if (target_start >= target.length) target_start = target.length 991 | if (!target_start) target_start = 0 992 | if (end > 0 && end < start) end = start 993 | 994 | // Copy 0 bytes; we're done 995 | if (end === start) return 0 996 | if (target.length === 0 || source.length === 0) return 0 997 | 998 | // Fatal error conditions 999 | if (target_start < 0) 1000 | throw new RangeError('targetStart out of bounds') 1001 | if (start < 0 || start >= source.length) throw new RangeError('sourceStart out of bounds') 1002 | if (end < 0) throw new RangeError('sourceEnd out of bounds') 1003 | 1004 | // Are we oob? 1005 | if (end > this.length) 1006 | end = this.length 1007 | if (target.length - target_start < end - start) 1008 | end = target.length - target_start + start 1009 | 1010 | var len = end - start 1011 | 1012 | if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { 1013 | for (var i = 0; i < len; i++) { 1014 | target[i + target_start] = this[i + start] 1015 | } 1016 | } else { 1017 | target._set(this.subarray(start, start + len), target_start) 1018 | } 1019 | 1020 | return len 1021 | } 1022 | 1023 | // fill(value, start=0, end=buffer.length) 1024 | Buffer.prototype.fill = function (value, start, end) { 1025 | if (!value) value = 0 1026 | if (!start) start = 0 1027 | if (!end) end = this.length 1028 | 1029 | if (end < start) throw new RangeError('end < start') 1030 | 1031 | // Fill 0 bytes; we're done 1032 | if (end === start) return 1033 | if (this.length === 0) return 1034 | 1035 | if (start < 0 || start >= this.length) throw new RangeError('start out of bounds') 1036 | if (end < 0 || end > this.length) throw new RangeError('end out of bounds') 1037 | 1038 | var i 1039 | if (typeof value === 'number') { 1040 | for (i = start; i < end; i++) { 1041 | this[i] = value 1042 | } 1043 | } else { 1044 | var bytes = utf8ToBytes(value.toString()) 1045 | var len = bytes.length 1046 | for (i = start; i < end; i++) { 1047 | this[i] = bytes[i % len] 1048 | } 1049 | } 1050 | 1051 | return this 1052 | } 1053 | 1054 | /** 1055 | * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. 1056 | * Added in Node 0.12. Only available in browsers that support ArrayBuffer. 1057 | */ 1058 | Buffer.prototype.toArrayBuffer = function () { 1059 | if (typeof Uint8Array !== 'undefined') { 1060 | if (Buffer.TYPED_ARRAY_SUPPORT) { 1061 | return (new Buffer(this)).buffer 1062 | } else { 1063 | var buf = new Uint8Array(this.length) 1064 | for (var i = 0, len = buf.length; i < len; i += 1) { 1065 | buf[i] = this[i] 1066 | } 1067 | return buf.buffer 1068 | } 1069 | } else { 1070 | throw new TypeError('Buffer.toArrayBuffer not supported in this browser') 1071 | } 1072 | } 1073 | 1074 | // HELPER FUNCTIONS 1075 | // ================ 1076 | 1077 | var BP = Buffer.prototype 1078 | 1079 | /** 1080 | * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods 1081 | */ 1082 | Buffer._augment = function (arr) { 1083 | arr.constructor = Buffer 1084 | arr._isBuffer = true 1085 | 1086 | // save reference to original Uint8Array get/set methods before overwriting 1087 | arr._get = arr.get 1088 | arr._set = arr.set 1089 | 1090 | // deprecated, will be removed in node 0.13+ 1091 | arr.get = BP.get 1092 | arr.set = BP.set 1093 | 1094 | arr.write = BP.write 1095 | arr.toString = BP.toString 1096 | arr.toLocaleString = BP.toString 1097 | arr.toJSON = BP.toJSON 1098 | arr.equals = BP.equals 1099 | arr.compare = BP.compare 1100 | arr.copy = BP.copy 1101 | arr.slice = BP.slice 1102 | arr.readUIntLE = BP.readUIntLE 1103 | arr.readUIntBE = BP.readUIntBE 1104 | arr.readUInt8 = BP.readUInt8 1105 | arr.readUInt16LE = BP.readUInt16LE 1106 | arr.readUInt16BE = BP.readUInt16BE 1107 | arr.readUInt32LE = BP.readUInt32LE 1108 | arr.readUInt32BE = BP.readUInt32BE 1109 | arr.readIntLE = BP.readIntLE 1110 | arr.readIntBE = BP.readIntBE 1111 | arr.readInt8 = BP.readInt8 1112 | arr.readInt16LE = BP.readInt16LE 1113 | arr.readInt16BE = BP.readInt16BE 1114 | arr.readInt32LE = BP.readInt32LE 1115 | arr.readInt32BE = BP.readInt32BE 1116 | arr.readFloatLE = BP.readFloatLE 1117 | arr.readFloatBE = BP.readFloatBE 1118 | arr.readDoubleLE = BP.readDoubleLE 1119 | arr.readDoubleBE = BP.readDoubleBE 1120 | arr.writeUInt8 = BP.writeUInt8 1121 | arr.writeUIntLE = BP.writeUIntLE 1122 | arr.writeUIntBE = BP.writeUIntBE 1123 | arr.writeUInt16LE = BP.writeUInt16LE 1124 | arr.writeUInt16BE = BP.writeUInt16BE 1125 | arr.writeUInt32LE = BP.writeUInt32LE 1126 | arr.writeUInt32BE = BP.writeUInt32BE 1127 | arr.writeIntLE = BP.writeIntLE 1128 | arr.writeIntBE = BP.writeIntBE 1129 | arr.writeInt8 = BP.writeInt8 1130 | arr.writeInt16LE = BP.writeInt16LE 1131 | arr.writeInt16BE = BP.writeInt16BE 1132 | arr.writeInt32LE = BP.writeInt32LE 1133 | arr.writeInt32BE = BP.writeInt32BE 1134 | arr.writeFloatLE = BP.writeFloatLE 1135 | arr.writeFloatBE = BP.writeFloatBE 1136 | arr.writeDoubleLE = BP.writeDoubleLE 1137 | arr.writeDoubleBE = BP.writeDoubleBE 1138 | arr.fill = BP.fill 1139 | arr.inspect = BP.inspect 1140 | arr.toArrayBuffer = BP.toArrayBuffer 1141 | 1142 | return arr 1143 | } 1144 | 1145 | var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g 1146 | 1147 | function base64clean (str) { 1148 | // Node strips out invalid characters like \n and \t from the string, base64-js does not 1149 | str = stringtrim(str).replace(INVALID_BASE64_RE, '') 1150 | // Node converts strings with length < 2 to '' 1151 | if (str.length < 2) return '' 1152 | // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not 1153 | while (str.length % 4 !== 0) { 1154 | str = str + '=' 1155 | } 1156 | return str 1157 | } 1158 | 1159 | function stringtrim (str) { 1160 | if (str.trim) return str.trim() 1161 | return str.replace(/^\s+|\s+$/g, '') 1162 | } 1163 | 1164 | function isArrayish (subject) { 1165 | return isArray(subject) || Buffer.isBuffer(subject) || 1166 | subject && typeof subject === 'object' && 1167 | typeof subject.length === 'number' 1168 | } 1169 | 1170 | function toHex (n) { 1171 | if (n < 16) return '0' + n.toString(16) 1172 | return n.toString(16) 1173 | } 1174 | 1175 | function utf8ToBytes(string, units) { 1176 | var codePoint, length = string.length 1177 | var leadSurrogate = null 1178 | units = units || Infinity 1179 | var bytes = [] 1180 | var i = 0 1181 | 1182 | for (; i 0xD7FF && codePoint < 0xE000) { 1187 | 1188 | // last char was a lead 1189 | if (leadSurrogate) { 1190 | 1191 | // 2 leads in a row 1192 | if (codePoint < 0xDC00) { 1193 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 1194 | leadSurrogate = codePoint 1195 | continue 1196 | } 1197 | 1198 | // valid surrogate pair 1199 | else { 1200 | codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000 1201 | leadSurrogate = null 1202 | } 1203 | } 1204 | 1205 | // no lead yet 1206 | else { 1207 | 1208 | // unexpected trail 1209 | if (codePoint > 0xDBFF) { 1210 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 1211 | continue 1212 | } 1213 | 1214 | // unpaired lead 1215 | else if (i + 1 === length) { 1216 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 1217 | continue 1218 | } 1219 | 1220 | // valid lead 1221 | else { 1222 | leadSurrogate = codePoint 1223 | continue 1224 | } 1225 | } 1226 | } 1227 | 1228 | // valid bmp char, but last char was a lead 1229 | else if (leadSurrogate) { 1230 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 1231 | leadSurrogate = null 1232 | } 1233 | 1234 | // encode utf8 1235 | if (codePoint < 0x80) { 1236 | if ((units -= 1) < 0) break 1237 | bytes.push(codePoint) 1238 | } 1239 | else if (codePoint < 0x800) { 1240 | if ((units -= 2) < 0) break 1241 | bytes.push( 1242 | codePoint >> 0x6 | 0xC0, 1243 | codePoint & 0x3F | 0x80 1244 | ); 1245 | } 1246 | else if (codePoint < 0x10000) { 1247 | if ((units -= 3) < 0) break 1248 | bytes.push( 1249 | codePoint >> 0xC | 0xE0, 1250 | codePoint >> 0x6 & 0x3F | 0x80, 1251 | codePoint & 0x3F | 0x80 1252 | ); 1253 | } 1254 | else if (codePoint < 0x200000) { 1255 | if ((units -= 4) < 0) break 1256 | bytes.push( 1257 | codePoint >> 0x12 | 0xF0, 1258 | codePoint >> 0xC & 0x3F | 0x80, 1259 | codePoint >> 0x6 & 0x3F | 0x80, 1260 | codePoint & 0x3F | 0x80 1261 | ); 1262 | } 1263 | else { 1264 | throw new Error('Invalid code point') 1265 | } 1266 | } 1267 | 1268 | return bytes 1269 | } 1270 | 1271 | function asciiToBytes (str) { 1272 | var byteArray = [] 1273 | for (var i = 0; i < str.length; i++) { 1274 | // Node's code seems to be doing this and not & 0x7F.. 1275 | byteArray.push(str.charCodeAt(i) & 0xFF) 1276 | } 1277 | return byteArray 1278 | } 1279 | 1280 | function utf16leToBytes (str, units) { 1281 | var c, hi, lo 1282 | var byteArray = [] 1283 | for (var i = 0; i < str.length; i++) { 1284 | 1285 | if ((units -= 2) < 0) break 1286 | 1287 | c = str.charCodeAt(i) 1288 | hi = c >> 8 1289 | lo = c % 256 1290 | byteArray.push(lo) 1291 | byteArray.push(hi) 1292 | } 1293 | 1294 | return byteArray 1295 | } 1296 | 1297 | function base64ToBytes (str) { 1298 | return base64.toByteArray(base64clean(str)) 1299 | } 1300 | 1301 | function blitBuffer (src, dst, offset, length, unitSize) { 1302 | if (unitSize) length -= length % unitSize; 1303 | for (var i = 0; i < length; i++) { 1304 | if ((i + offset >= dst.length) || (i >= src.length)) 1305 | break 1306 | dst[i + offset] = src[i] 1307 | } 1308 | return i 1309 | } 1310 | 1311 | function decodeUtf8Char (str) { 1312 | try { 1313 | return decodeURIComponent(str) 1314 | } catch (err) { 1315 | return String.fromCharCode(0xFFFD) // UTF 8 invalid char 1316 | } 1317 | } 1318 | 1319 | },{"base64-js":2,"ieee754":3,"is-array":4}],2:[function(require,module,exports){ 1320 | var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; 1321 | 1322 | ;(function (exports) { 1323 | 'use strict'; 1324 | 1325 | var Arr = (typeof Uint8Array !== 'undefined') 1326 | ? Uint8Array 1327 | : Array 1328 | 1329 | var PLUS = '+'.charCodeAt(0) 1330 | var SLASH = '/'.charCodeAt(0) 1331 | var NUMBER = '0'.charCodeAt(0) 1332 | var LOWER = 'a'.charCodeAt(0) 1333 | var UPPER = 'A'.charCodeAt(0) 1334 | var PLUS_URL_SAFE = '-'.charCodeAt(0) 1335 | var SLASH_URL_SAFE = '_'.charCodeAt(0) 1336 | 1337 | function decode (elt) { 1338 | var code = elt.charCodeAt(0) 1339 | if (code === PLUS || 1340 | code === PLUS_URL_SAFE) 1341 | return 62 // '+' 1342 | if (code === SLASH || 1343 | code === SLASH_URL_SAFE) 1344 | return 63 // '/' 1345 | if (code < NUMBER) 1346 | return -1 //no match 1347 | if (code < NUMBER + 10) 1348 | return code - NUMBER + 26 + 26 1349 | if (code < UPPER + 26) 1350 | return code - UPPER 1351 | if (code < LOWER + 26) 1352 | return code - LOWER + 26 1353 | } 1354 | 1355 | function b64ToByteArray (b64) { 1356 | var i, j, l, tmp, placeHolders, arr 1357 | 1358 | if (b64.length % 4 > 0) { 1359 | throw new Error('Invalid string. Length must be a multiple of 4') 1360 | } 1361 | 1362 | // the number of equal signs (place holders) 1363 | // if there are two placeholders, than the two characters before it 1364 | // represent one byte 1365 | // if there is only one, then the three characters before it represent 2 bytes 1366 | // this is just a cheap hack to not do indexOf twice 1367 | var len = b64.length 1368 | placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 1369 | 1370 | // base64 is 4/3 + up to two characters of the original data 1371 | arr = new Arr(b64.length * 3 / 4 - placeHolders) 1372 | 1373 | // if there are placeholders, only get up to the last complete 4 chars 1374 | l = placeHolders > 0 ? b64.length - 4 : b64.length 1375 | 1376 | var L = 0 1377 | 1378 | function push (v) { 1379 | arr[L++] = v 1380 | } 1381 | 1382 | for (i = 0, j = 0; i < l; i += 4, j += 3) { 1383 | tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) 1384 | push((tmp & 0xFF0000) >> 16) 1385 | push((tmp & 0xFF00) >> 8) 1386 | push(tmp & 0xFF) 1387 | } 1388 | 1389 | if (placeHolders === 2) { 1390 | tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) 1391 | push(tmp & 0xFF) 1392 | } else if (placeHolders === 1) { 1393 | tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) 1394 | push((tmp >> 8) & 0xFF) 1395 | push(tmp & 0xFF) 1396 | } 1397 | 1398 | return arr 1399 | } 1400 | 1401 | function uint8ToBase64 (uint8) { 1402 | var i, 1403 | extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes 1404 | output = "", 1405 | temp, length 1406 | 1407 | function encode (num) { 1408 | return lookup.charAt(num) 1409 | } 1410 | 1411 | function tripletToBase64 (num) { 1412 | return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) 1413 | } 1414 | 1415 | // go through the array every three bytes, we'll deal with trailing stuff later 1416 | for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { 1417 | temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) 1418 | output += tripletToBase64(temp) 1419 | } 1420 | 1421 | // pad the end with zeros, but make sure to not forget the extra bytes 1422 | switch (extraBytes) { 1423 | case 1: 1424 | temp = uint8[uint8.length - 1] 1425 | output += encode(temp >> 2) 1426 | output += encode((temp << 4) & 0x3F) 1427 | output += '==' 1428 | break 1429 | case 2: 1430 | temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) 1431 | output += encode(temp >> 10) 1432 | output += encode((temp >> 4) & 0x3F) 1433 | output += encode((temp << 2) & 0x3F) 1434 | output += '=' 1435 | break 1436 | } 1437 | 1438 | return output 1439 | } 1440 | 1441 | exports.toByteArray = b64ToByteArray 1442 | exports.fromByteArray = uint8ToBase64 1443 | }(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) 1444 | 1445 | },{}],3:[function(require,module,exports){ 1446 | exports.read = function(buffer, offset, isLE, mLen, nBytes) { 1447 | var e, m, 1448 | eLen = nBytes * 8 - mLen - 1, 1449 | eMax = (1 << eLen) - 1, 1450 | eBias = eMax >> 1, 1451 | nBits = -7, 1452 | i = isLE ? (nBytes - 1) : 0, 1453 | d = isLE ? -1 : 1, 1454 | s = buffer[offset + i]; 1455 | 1456 | i += d; 1457 | 1458 | e = s & ((1 << (-nBits)) - 1); 1459 | s >>= (-nBits); 1460 | nBits += eLen; 1461 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); 1462 | 1463 | m = e & ((1 << (-nBits)) - 1); 1464 | e >>= (-nBits); 1465 | nBits += mLen; 1466 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); 1467 | 1468 | if (e === 0) { 1469 | e = 1 - eBias; 1470 | } else if (e === eMax) { 1471 | return m ? NaN : ((s ? -1 : 1) * Infinity); 1472 | } else { 1473 | m = m + Math.pow(2, mLen); 1474 | e = e - eBias; 1475 | } 1476 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen); 1477 | }; 1478 | 1479 | exports.write = function(buffer, value, offset, isLE, mLen, nBytes) { 1480 | var e, m, c, 1481 | eLen = nBytes * 8 - mLen - 1, 1482 | eMax = (1 << eLen) - 1, 1483 | eBias = eMax >> 1, 1484 | rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), 1485 | i = isLE ? 0 : (nBytes - 1), 1486 | d = isLE ? 1 : -1, 1487 | s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; 1488 | 1489 | value = Math.abs(value); 1490 | 1491 | if (isNaN(value) || value === Infinity) { 1492 | m = isNaN(value) ? 1 : 0; 1493 | e = eMax; 1494 | } else { 1495 | e = Math.floor(Math.log(value) / Math.LN2); 1496 | if (value * (c = Math.pow(2, -e)) < 1) { 1497 | e--; 1498 | c *= 2; 1499 | } 1500 | if (e + eBias >= 1) { 1501 | value += rt / c; 1502 | } else { 1503 | value += rt * Math.pow(2, 1 - eBias); 1504 | } 1505 | if (value * c >= 2) { 1506 | e++; 1507 | c /= 2; 1508 | } 1509 | 1510 | if (e + eBias >= eMax) { 1511 | m = 0; 1512 | e = eMax; 1513 | } else if (e + eBias >= 1) { 1514 | m = (value * c - 1) * Math.pow(2, mLen); 1515 | e = e + eBias; 1516 | } else { 1517 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); 1518 | e = 0; 1519 | } 1520 | } 1521 | 1522 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); 1523 | 1524 | e = (e << mLen) | m; 1525 | eLen += mLen; 1526 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); 1527 | 1528 | buffer[offset + i - d] |= s * 128; 1529 | }; 1530 | 1531 | },{}],4:[function(require,module,exports){ 1532 | 1533 | /** 1534 | * isArray 1535 | */ 1536 | 1537 | var isArray = Array.isArray; 1538 | 1539 | /** 1540 | * toString 1541 | */ 1542 | 1543 | var str = Object.prototype.toString; 1544 | 1545 | /** 1546 | * Whether or not the given `val` 1547 | * is an array. 1548 | * 1549 | * example: 1550 | * 1551 | * isArray([]); 1552 | * // > true 1553 | * isArray(arguments); 1554 | * // > false 1555 | * isArray(''); 1556 | * // > false 1557 | * 1558 | * @param {mixed} val 1559 | * @return {bool} 1560 | */ 1561 | 1562 | module.exports = isArray || function (val) { 1563 | return !! val && '[object Array]' == str.call(val); 1564 | }; 1565 | 1566 | },{}],5:[function(require,module,exports){ 1567 | var util = require('./util'); 1568 | 1569 | /** 1570 | * should AssertionError 1571 | * @param {Object} options 1572 | * @constructor 1573 | * @memberOf should 1574 | * @static 1575 | */ 1576 | var AssertionError = function AssertionError(options) { 1577 | this.name = 'AssertionError'; 1578 | this.actual = options.actual; 1579 | this.expected = options.expected; 1580 | this.operator = options.operator; 1581 | 1582 | this.message = options.message; 1583 | 1584 | var stackStartFunction = options.stackStartFunction; 1585 | 1586 | if(Error.captureStackTrace) { 1587 | Error.captureStackTrace(this, stackStartFunction); 1588 | } 1589 | else { 1590 | // non v8 browsers so we can have a stacktrace 1591 | var err = new Error(); 1592 | if(err.stack) { 1593 | var out = err.stack; 1594 | 1595 | if(stackStartFunction) { 1596 | // try to strip useless frames 1597 | var fn_name = util.functionName(stackStartFunction); 1598 | var idx = out.indexOf('\n' + fn_name); 1599 | if(idx >= 0) { 1600 | // once we have located the function frame 1601 | // we need to strip out everything before it (and its line) 1602 | var next_line = out.indexOf('\n', idx + 1); 1603 | out = out.substring(next_line + 1); 1604 | } 1605 | } 1606 | 1607 | this.stack = out; 1608 | } 1609 | } 1610 | }; 1611 | 1612 | // assert.AssertionError instanceof Error 1613 | AssertionError.prototype = Object.create(Error.prototype); 1614 | 1615 | module.exports = AssertionError; 1616 | },{"./util":23}],6:[function(require,module,exports){ 1617 | var AssertionError = require('./assertion-error'); 1618 | var util = require('./util'); 1619 | var format = require('should-format'); 1620 | 1621 | /** 1622 | * should Assertion 1623 | * @param {*} obj Given object for assertion 1624 | * @constructor 1625 | * @memberOf should 1626 | * @static 1627 | */ 1628 | function Assertion(obj) { 1629 | this.obj = obj; 1630 | this.anyOne = false; 1631 | this.negate = false; 1632 | this.nestedErrorMessage = null; 1633 | } 1634 | 1635 | /** 1636 | * Way to extend Assertion function. It uses some logic 1637 | * to define only positive assertions and itself rule with negative assertion. 1638 | * 1639 | * All actions happen in subcontext and this method take care about negation. 1640 | * Potentially we can add some more modifiers that does not depends from state of assertion. 1641 | * @memberOf Assertion 1642 | * @category assertion 1643 | * @static 1644 | * @param {String} name Name of assertion. It will be used for defining method or getter on Assertion.prototype 1645 | * @param {Function} func Function that will be called on executing assertion 1646 | * @param {Boolean} [isGetter] If this assertion is getter. By default it is false. 1647 | * @example 1648 | * 1649 | * Assertion.add('asset', function() { 1650 | * this.params = { operator: 'to be asset' }; 1651 | * 1652 | * this.obj.should.have.property('id').which.is.a.Number; 1653 | * this.obj.should.have.property('path'); 1654 | * }); 1655 | */ 1656 | Assertion.add = function(name, func, isGetter) { 1657 | var prop = {enumerable: true}; 1658 | if(typeof isGetter == 'undefined') isGetter = false; 1659 | prop[isGetter ? 'get' : 'value'] = function() { 1660 | var context = new Assertion(this.obj); 1661 | context.anyOne = this.anyOne; 1662 | 1663 | try { 1664 | func.apply(context, arguments); 1665 | } catch(e) { 1666 | //copy data from sub context to this 1667 | this.params = context.params; 1668 | 1669 | //check for fail 1670 | if(e instanceof AssertionError) { 1671 | //negative fail 1672 | if(this.negate) { 1673 | this.obj = context.obj; 1674 | this.negate = false; 1675 | return this.proxied(); 1676 | } 1677 | 1678 | this.nestedErrorMessage = e.message; 1679 | //positive fail 1680 | this.fail(); 1681 | } 1682 | // throw if it is another exception 1683 | throw e; 1684 | } 1685 | //copy data from sub context to this 1686 | this.params = context.params; 1687 | 1688 | //negative pass 1689 | if(this.negate) { 1690 | context.negate = true; 1691 | this.nestedErrorMessage = context.params.message ? context.params.message : context.getMessage(); 1692 | this.fail(); 1693 | } 1694 | 1695 | this.obj = context.obj; 1696 | this.negate = false; 1697 | 1698 | //positive pass 1699 | return this.proxied(); 1700 | }; 1701 | 1702 | Object.defineProperty(Assertion.prototype, name, prop); 1703 | }; 1704 | 1705 | Assertion.addChain = function(name, onCall){ 1706 | onCall = onCall || function() {}; 1707 | Object.defineProperty(Assertion.prototype, name, { 1708 | get: function() { 1709 | onCall(); 1710 | return this.proxied(); 1711 | }, 1712 | enumerable: true 1713 | }); 1714 | }; 1715 | 1716 | /** 1717 | * Create alias for some `Assertion` property 1718 | * 1719 | * @memberOf Assertion 1720 | * @category assertion 1721 | * @static 1722 | * @param {String} from Name of to map 1723 | * @param {String} to Name of alias 1724 | * @example 1725 | * 1726 | * Assertion.alias('true', 'True'); 1727 | */ 1728 | Assertion.alias = function(from, to) { 1729 | var desc = Object.getOwnPropertyDescriptor(Assertion.prototype, from); 1730 | if(!desc) throw new Error('Alias ' + from + ' -> ' + to + ' could not be created as ' + from + ' not defined'); 1731 | Object.defineProperty(Assertion.prototype, to, desc); 1732 | }; 1733 | 1734 | var indent = ' '; 1735 | function prependIndent(line) { 1736 | return indent + line; 1737 | } 1738 | 1739 | function indentLines(text) { 1740 | return text.split('\n').map(prependIndent).join('\n'); 1741 | } 1742 | 1743 | Assertion.prototype = { 1744 | constructor: Assertion, 1745 | 1746 | /** 1747 | * Base method for assertions. Before calling this method need to fill Assertion#params object. This method usually called from other assertion methods. 1748 | * `Assertion#params` can contain such properties: 1749 | * * `operator` - required string containing description of this assertion 1750 | * * `obj` - optional replacement for this.obj, it usefull if you prepare more clear object then given 1751 | * * `message` - if this property filled with string any others will be ignored and this one used as assertion message 1752 | * * `expected` - any object used when you need to assert relation between given object and expected. Like given == expected (== is a relation) 1753 | * * `details` - additional string with details to generated message 1754 | * 1755 | * @memberOf Assertion 1756 | * @category assertion 1757 | * @param {*} expr Any expression that will be used as a condition for asserting. 1758 | * @example 1759 | * 1760 | * var a = new should.Assertion(42); 1761 | * 1762 | * a.params = { 1763 | * operator: 'to be magic number', 1764 | * } 1765 | * 1766 | * a.assert(false); 1767 | * //throws AssertionError: expected 42 to be magic number 1768 | */ 1769 | assert: function(expr) { 1770 | if(expr) return this.proxied(); 1771 | 1772 | var params = this.params; 1773 | 1774 | var msg = params.message, generatedMessage = false; 1775 | if(!msg) { 1776 | msg = this.getMessage(); 1777 | generatedMessage = true; 1778 | } 1779 | 1780 | if(this.nestedErrorMessage && msg != this.nestedErrorMessage) { 1781 | msg = msg + '\n' +indentLines(this.nestedErrorMessage); 1782 | } 1783 | 1784 | var err = new AssertionError({ 1785 | message: msg, 1786 | actual: this.obj, 1787 | expected: params.expected, 1788 | stackStartFunction: params.stackStartFunction || this.assert 1789 | }); 1790 | 1791 | err.showDiff = params.showDiff; 1792 | err.operator = params.operator; 1793 | err.generatedMessage = generatedMessage; 1794 | 1795 | throw err; 1796 | }, 1797 | 1798 | /** 1799 | * Shortcut for `Assertion#assert(false)`. 1800 | * 1801 | * @memberOf Assertion 1802 | * @category assertion 1803 | * @example 1804 | * 1805 | * var a = new should.Assertion(42); 1806 | * 1807 | * a.params = { 1808 | * operator: 'to be magic number', 1809 | * } 1810 | * 1811 | * a.fail(); 1812 | * //throws AssertionError: expected 42 to be magic number 1813 | */ 1814 | fail: function() { 1815 | return this.assert(false); 1816 | }, 1817 | 1818 | getMessage: function() { 1819 | var actual = 'obj' in this.params ? format(this.params.obj) : format(this.obj); 1820 | var expected = 'expected' in this.params ? ' ' + format(this.params.expected) : ''; 1821 | var details = 'details' in this.params && this.params.details ? ' (' + this.params.details + ')': ''; 1822 | 1823 | return 'expected ' + actual + (this.negate ? ' not ' : ' ') + this.params.operator + expected + details; 1824 | }, 1825 | 1826 | 1827 | /** 1828 | * Negation modifier. Current assertion chain become negated. Each call invert negation on current assertion. 1829 | * 1830 | * @memberOf Assertion 1831 | * @category assertion 1832 | */ 1833 | get not() { 1834 | this.negate = !this.negate; 1835 | return this.proxied(); 1836 | }, 1837 | 1838 | /** 1839 | * Any modifier - it affect on execution of sequenced assertion to do not `check all`, but `check any of`. 1840 | * 1841 | * @memberOf Assertion 1842 | * @category assertion 1843 | */ 1844 | get any() { 1845 | this.anyOne = true; 1846 | return this.proxied(); 1847 | }, 1848 | 1849 | proxied: function() { 1850 | if(typeof Proxy == 'function') { 1851 | return new Proxy(this, { 1852 | get: function(target, name) { 1853 | if(name in target) { 1854 | return target[name]; 1855 | } else { 1856 | throw new Error('Assertion has no property ' + util.formatProp(name)); 1857 | } 1858 | } 1859 | }) 1860 | } 1861 | return this; 1862 | } 1863 | }; 1864 | 1865 | module.exports = Assertion; 1866 | },{"./assertion-error":5,"./util":23,"should-format":26}],7:[function(require,module,exports){ 1867 | var config = { 1868 | checkProtoEql: false, 1869 | 1870 | useOldDeepEqual: false 1871 | }; 1872 | 1873 | module.exports = config; 1874 | },{}],8:[function(require,module,exports){ 1875 | var config = require('./config'); 1876 | 1877 | var nodeEqual = require('./node-equal'); 1878 | var shouldEqual = require('should-equal'); 1879 | 1880 | module.exports = function() { 1881 | return config.useOldDeepEqual ? nodeEqual: shouldEqual; 1882 | }; 1883 | },{"./config":7,"./node-equal":21,"should-equal":24}],9:[function(require,module,exports){ 1884 | // implement assert interface using already written peaces of should.js 1885 | 1886 | // http://wiki.commonjs.org/wiki/Unit_Testing/1.0 1887 | // 1888 | // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! 1889 | // 1890 | // Originally from narwhal.js (http://narwhaljs.org) 1891 | // Copyright (c) 2009 Thomas Robinson <280north.com> 1892 | // 1893 | // Permission is hereby granted, free of charge, to any person obtaining a copy 1894 | // of this software and associated documentation files (the 'Software'), to 1895 | // deal in the Software without restriction, including without limitation the 1896 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1897 | // sell copies of the Software, and to permit persons to whom the Software is 1898 | // furnished to do so, subject to the following conditions: 1899 | // 1900 | // The above copyright notice and this permission notice shall be included in 1901 | // all copies or substantial portions of the Software. 1902 | // 1903 | // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1904 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1905 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1906 | // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 1907 | // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 1908 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 1909 | 1910 | // when used in node, this will actually load the util module we depend on 1911 | // versus loading the builtin util module as happens otherwise 1912 | // this is a bug in node module loading as far as I am concerned 1913 | var util = require('./../util'); 1914 | var Assertion = require('./../assertion'); 1915 | 1916 | var _deepEqual = require('should-equal'); 1917 | 1918 | var pSlice = Array.prototype.slice; 1919 | 1920 | // 1. The assert module provides functions that throw 1921 | // AssertionError's when particular conditions are not met. The 1922 | // assert module must conform to the following interface. 1923 | 1924 | var assert = module.exports = ok; 1925 | 1926 | // 3. All of the following functions must throw an AssertionError 1927 | // when a corresponding condition is not met, with a message that 1928 | // may be undefined if not provided. All assertion methods provide 1929 | // both the actual and expected values to the assertion error for 1930 | // display purposes. 1931 | /** 1932 | * Node.js standard [`assert.fail`](http://nodejs.org/api/assert.html#assert_assert_fail_actual_expected_message_operator). 1933 | * @static 1934 | * @memberOf should 1935 | * @category assertion assert 1936 | * @param {*} actual Actual object 1937 | * @param {*} expected Expected object 1938 | * @param {string} message Message for assertion 1939 | * @param {string} operator Operator text 1940 | */ 1941 | function fail(actual, expected, message, operator, stackStartFunction) { 1942 | var a = new Assertion(actual); 1943 | a.params = { 1944 | operator: operator, 1945 | expected: expected, 1946 | message: message, 1947 | stackStartFunction: stackStartFunction || fail 1948 | }; 1949 | 1950 | a.fail(); 1951 | } 1952 | 1953 | // EXTENSION! allows for well behaved errors defined elsewhere. 1954 | assert.fail = fail; 1955 | 1956 | // 4. Pure assertion tests whether a value is truthy, as determined 1957 | // by !!guard. 1958 | // assert.ok(guard, message_opt); 1959 | // This statement is equivalent to assert.equal(true, !!guard, 1960 | // message_opt);. To test strictly for the value true, use 1961 | // assert.strictEqual(true, guard, message_opt);. 1962 | /** 1963 | * Node.js standard [`assert.ok`](http://nodejs.org/api/assert.html#assert_assert_value_message_assert_ok_value_message). 1964 | * @static 1965 | * @memberOf should 1966 | * @category assertion assert 1967 | * @param {*} value 1968 | * @param {string} [message] 1969 | */ 1970 | function ok(value, message) { 1971 | if(!value) fail(value, true, message, '==', assert.ok); 1972 | } 1973 | assert.ok = ok; 1974 | 1975 | // 5. The equality assertion tests shallow, coercive equality with 1976 | // ==. 1977 | // assert.equal(actual, expected, message_opt); 1978 | 1979 | /** 1980 | * Node.js standard [`assert.equal`](http://nodejs.org/api/assert.html#assert_assert_equal_actual_expected_message). 1981 | * @static 1982 | * @memberOf should 1983 | * @category assertion assert 1984 | * @param {*} actual 1985 | * @param {*} expected 1986 | * @param {string} [message] 1987 | */ 1988 | assert.equal = function equal(actual, expected, message) { 1989 | if(actual != expected) fail(actual, expected, message, '==', assert.equal); 1990 | }; 1991 | 1992 | // 6. The non-equality assertion tests for whether two objects are not equal 1993 | // with != assert.notEqual(actual, expected, message_opt); 1994 | /** 1995 | * Node.js standard [`assert.notEqual`](http://nodejs.org/api/assert.html#assert_assert_notequal_actual_expected_message). 1996 | * @static 1997 | * @memberOf should 1998 | * @category assertion assert 1999 | * @param {*} actual 2000 | * @param {*} expected 2001 | * @param {string} [message] 2002 | */ 2003 | assert.notEqual = function notEqual(actual, expected, message) { 2004 | if(actual == expected) { 2005 | fail(actual, expected, message, '!=', assert.notEqual); 2006 | } 2007 | }; 2008 | 2009 | // 7. The equivalence assertion tests a deep equality relation. 2010 | // assert.deepEqual(actual, expected, message_opt); 2011 | /** 2012 | * Node.js standard [`assert.deepEqual`](http://nodejs.org/api/assert.html#assert_assert_deepequal_actual_expected_message). 2013 | * @static 2014 | * @memberOf should 2015 | * @category assertion assert 2016 | * @param {*} actual 2017 | * @param {*} expected 2018 | * @param {string} [message] 2019 | */ 2020 | assert.deepEqual = function deepEqual(actual, expected, message) { 2021 | if(!_deepEqual(actual, expected).result) { 2022 | fail(actual, expected, message, 'deepEqual', assert.deepEqual); 2023 | } 2024 | }; 2025 | 2026 | 2027 | // 8. The non-equivalence assertion tests for any deep inequality. 2028 | // assert.notDeepEqual(actual, expected, message_opt); 2029 | /** 2030 | * Node.js standard [`assert.notDeepEqual`](http://nodejs.org/api/assert.html#assert_assert_notdeepequal_actual_expected_message). 2031 | * @static 2032 | * @memberOf should 2033 | * @category assertion assert 2034 | * @param {*} actual 2035 | * @param {*} expected 2036 | * @param {string} [message] 2037 | */ 2038 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) { 2039 | if(_deepEqual(actual, expected).result) { 2040 | fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); 2041 | } 2042 | }; 2043 | 2044 | // 9. The strict equality assertion tests strict equality, as determined by ===. 2045 | // assert.strictEqual(actual, expected, message_opt); 2046 | /** 2047 | * Node.js standard [`assert.strictEqual`](http://nodejs.org/api/assert.html#assert_assert_strictequal_actual_expected_message). 2048 | * @static 2049 | * @memberOf should 2050 | * @category assertion assert 2051 | * @param {*} actual 2052 | * @param {*} expected 2053 | * @param {string} [message] 2054 | */ 2055 | assert.strictEqual = function strictEqual(actual, expected, message) { 2056 | if(actual !== expected) { 2057 | fail(actual, expected, message, '===', assert.strictEqual); 2058 | } 2059 | }; 2060 | 2061 | // 10. The strict non-equality assertion tests for strict inequality, as 2062 | // determined by !==. assert.notStrictEqual(actual, expected, message_opt); 2063 | /** 2064 | * Node.js standard [`assert.notStrictEqual`](http://nodejs.org/api/assert.html#assert_assert_notstrictequal_actual_expected_message). 2065 | * @static 2066 | * @memberOf should 2067 | * @category assertion assert 2068 | * @param {*} actual 2069 | * @param {*} expected 2070 | * @param {string} [message] 2071 | */ 2072 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) { 2073 | if(actual === expected) { 2074 | fail(actual, expected, message, '!==', assert.notStrictEqual); 2075 | } 2076 | }; 2077 | 2078 | function expectedException(actual, expected) { 2079 | if(!actual || !expected) { 2080 | return false; 2081 | } 2082 | 2083 | if(Object.prototype.toString.call(expected) == '[object RegExp]') { 2084 | return expected.test(actual); 2085 | } else if(actual instanceof expected) { 2086 | return true; 2087 | } else if(expected.call({}, actual) === true) { 2088 | return true; 2089 | } 2090 | 2091 | return false; 2092 | } 2093 | 2094 | function _throws(shouldThrow, block, expected, message) { 2095 | var actual; 2096 | 2097 | if(util.isString(expected)) { 2098 | message = expected; 2099 | expected = null; 2100 | } 2101 | 2102 | try { 2103 | block(); 2104 | } catch(e) { 2105 | actual = e; 2106 | } 2107 | 2108 | message = (expected && expected.name ? ' (' + expected.name + ')' : '.') + 2109 | (message ? ' ' + message : '.'); 2110 | 2111 | if(shouldThrow && !actual) { 2112 | fail(actual, expected, 'Missing expected exception' + message); 2113 | } 2114 | 2115 | if(!shouldThrow && expectedException(actual, expected)) { 2116 | fail(actual, expected, 'Got unwanted exception' + message); 2117 | } 2118 | 2119 | if((shouldThrow && actual && expected && !expectedException(actual, expected)) || (!shouldThrow && actual)) { 2120 | throw actual; 2121 | } 2122 | } 2123 | 2124 | // 11. Expected to throw an error: 2125 | // assert.throws(block, Error_opt, message_opt); 2126 | /** 2127 | * Node.js standard [`assert.throws`](http://nodejs.org/api/assert.html#assert_assert_throws_block_error_message). 2128 | * @static 2129 | * @memberOf should 2130 | * @category assertion assert 2131 | * @param {Function} block 2132 | * @param {Function} [error] 2133 | * @param {String} [message] 2134 | */ 2135 | assert.throws = function(block, /*optional*/error, /*optional*/message) { 2136 | _throws.apply(this, [true].concat(pSlice.call(arguments))); 2137 | }; 2138 | 2139 | // EXTENSION! This is annoying to write outside this module. 2140 | /** 2141 | * Node.js standard [`assert.doesNotThrow`](http://nodejs.org/api/assert.html#assert_assert_doesnotthrow_block_message). 2142 | * @static 2143 | * @memberOf should 2144 | * @category assertion assert 2145 | * @param {Function} block 2146 | * @param {String} [message] 2147 | */ 2148 | assert.doesNotThrow = function(block, /*optional*/message) { 2149 | _throws.apply(this, [false].concat(pSlice.call(arguments))); 2150 | }; 2151 | 2152 | /** 2153 | * Node.js standard [`assert.ifError`](http://nodejs.org/api/assert.html#assert_assert_iferror_value). 2154 | * @static 2155 | * @memberOf should 2156 | * @category assertion assert 2157 | * @param {Error} err 2158 | */ 2159 | assert.ifError = function(err) { 2160 | if(err) { 2161 | throw err; 2162 | } 2163 | }; 2164 | 2165 | },{"./../assertion":6,"./../util":23,"should-equal":24}],10:[function(require,module,exports){ 2166 | /*! 2167 | * Should 2168 | * Copyright(c) 2010-2014 TJ Holowaychuk 2169 | * MIT Licensed 2170 | */ 2171 | 2172 | var util = require('../util') 2173 | , assert = require('./_assert') 2174 | , AssertionError = require('../assertion-error'); 2175 | 2176 | module.exports = function(should) { 2177 | var i = should.format; 2178 | 2179 | /* 2180 | * Expose assert to should 2181 | * 2182 | * This allows you to do things like below 2183 | * without require()ing the assert module. 2184 | * 2185 | * should.equal(foo.bar, undefined); 2186 | * 2187 | */ 2188 | util.merge(should, assert); 2189 | 2190 | /** 2191 | * Assert _obj_ exists, with optional message. 2192 | * 2193 | * @static 2194 | * @memberOf should 2195 | * @category assertion assert 2196 | * @alias should.exists 2197 | * @param {*} obj 2198 | * @param {String} [msg] 2199 | * @example 2200 | * 2201 | * should.exist(1); 2202 | * should.exist(new Date()); 2203 | */ 2204 | should.exist = should.exists = function(obj, msg) { 2205 | if(null == obj) { 2206 | throw new AssertionError({ 2207 | message: msg || ('expected ' + i(obj) + ' to exist'), stackStartFunction: should.exist 2208 | }); 2209 | } 2210 | }; 2211 | 2212 | should.not = {}; 2213 | /** 2214 | * Asserts _obj_ does not exist, with optional message. 2215 | * 2216 | * @name not.exist 2217 | * @static 2218 | * @memberOf should 2219 | * @category assertion assert 2220 | * @alias should.not.exists 2221 | * @param {*} obj 2222 | * @param {String} [msg] 2223 | * @example 2224 | * 2225 | * should.not.exist(null); 2226 | * should.not.exist(void 0); 2227 | */ 2228 | should.not.exist = should.not.exists = function(obj, msg) { 2229 | if(null != obj) { 2230 | throw new AssertionError({ 2231 | message: msg || ('expected ' + i(obj) + ' to not exist'), stackStartFunction: should.not.exist 2232 | }); 2233 | } 2234 | }; 2235 | }; 2236 | },{"../assertion-error":5,"../util":23,"./_assert":9}],11:[function(require,module,exports){ 2237 | /*! 2238 | * Should 2239 | * Copyright(c) 2010-2014 TJ Holowaychuk 2240 | * MIT Licensed 2241 | */ 2242 | 2243 | module.exports = function(should, Assertion) { 2244 | /** 2245 | * Assert given object is exactly `true`. 2246 | * 2247 | * @name true 2248 | * @memberOf Assertion 2249 | * @category assertion bool 2250 | * @alias Assertion#True 2251 | * @example 2252 | * 2253 | * (true).should.be.true; 2254 | * false.should.not.be.True; 2255 | * 2256 | * ({ a: 10}).should.not.be.true; 2257 | */ 2258 | Assertion.add('true', function() { 2259 | this.is.exactly(true); 2260 | }, true); 2261 | 2262 | Assertion.alias('true', 'True'); 2263 | 2264 | /** 2265 | * Assert given object is exactly `false`. 2266 | * 2267 | * @name false 2268 | * @memberOf Assertion 2269 | * @category assertion bool 2270 | * @alias Assertion#False 2271 | * @example 2272 | * 2273 | * (true).should.not.be.false; 2274 | * false.should.be.False; 2275 | */ 2276 | Assertion.add('false', function() { 2277 | this.is.exactly(false); 2278 | }, true); 2279 | 2280 | Assertion.alias('false', 'False'); 2281 | 2282 | /** 2283 | * Assert given object is thuthy according javascript type conversions. 2284 | * 2285 | * @name ok 2286 | * @memberOf Assertion 2287 | * @category assertion bool 2288 | * @example 2289 | * 2290 | * (true).should.be.ok; 2291 | * ''.should.not.be.ok; 2292 | * should(null).not.be.ok; 2293 | * should(void 0).not.be.ok; 2294 | * 2295 | * (10).should.be.ok; 2296 | * (0).should.not.be.ok; 2297 | */ 2298 | Assertion.add('ok', function() { 2299 | this.params = { operator: 'to be truthy' }; 2300 | 2301 | this.assert(this.obj); 2302 | }, true); 2303 | }; 2304 | },{}],12:[function(require,module,exports){ 2305 | /*! 2306 | * Should 2307 | * Copyright(c) 2010-2014 TJ Holowaychuk 2308 | * MIT Licensed 2309 | */ 2310 | 2311 | module.exports = function(should, Assertion) { 2312 | /** 2313 | * Simple chaining. It actually do nothing. 2314 | * 2315 | * @memberOf Assertion 2316 | * @name be 2317 | * @alias Assertion#an 2318 | * @alias Assertion#of 2319 | * @alias Assertion#a 2320 | * @alias Assertion#and 2321 | * @alias Assertion#have 2322 | * @alias Assertion#with 2323 | * @alias Assertion#is 2324 | * @alias Assertion#which 2325 | * @alias Assertion#the 2326 | * @category assertion chaining 2327 | */ 2328 | ['an', 'of', 'a', 'and', 'be', 'have', 'with', 'is', 'which', 'the'].forEach(function(name) { 2329 | Assertion.addChain(name); 2330 | }); 2331 | }; 2332 | },{}],13:[function(require,module,exports){ 2333 | /*! 2334 | * Should 2335 | * Copyright(c) 2010-2014 TJ Holowaychuk 2336 | * MIT Licensed 2337 | */ 2338 | 2339 | var util = require('../util'), 2340 | _eql = require('../eql'); 2341 | 2342 | module.exports = function(should, Assertion) { 2343 | var i = should.format; 2344 | 2345 | /** 2346 | * Assert that given object contain something that equal to `other`. It uses `should-equal` for equality checks. 2347 | * If given object is array it search that one of elements was equal to `other`. 2348 | * If given object is string it checks if `other` is a substring - expected that `other` is a string. 2349 | * If given object is Object it checks that `other` is a subobject - expected that `other` is a object. 2350 | * 2351 | * @name containEql 2352 | * @memberOf Assertion 2353 | * @category assertion contain 2354 | * @param {*} other Nested object 2355 | * @example 2356 | * 2357 | * [1, 2, 3].should.containEql(1); 2358 | * [{ a: 1 }, 'a', 10].should.containEql({ a: 1 }); 2359 | * 2360 | * 'abc'.should.containEql('b'); 2361 | * 'ab1c'.should.containEql(1); 2362 | * 2363 | * ({ a: 10, c: { d: 10 }}).should.containEql({ a: 10 }); 2364 | * ({ a: 10, c: { d: 10 }}).should.containEql({ c: { d: 10 }}); 2365 | * ({ a: 10, c: { d: 10 }}).should.containEql({ b: 10 }); 2366 | * // throws AssertionError: expected { a: 10, c: { d: 10 } } to contain { b: 10 } 2367 | * // expected { a: 10, c: { d: 10 } } to have property b 2368 | */ 2369 | Assertion.add('containEql', function(other) { 2370 | var eql = _eql(); 2371 | this.params = { operator: 'to contain ' + i(other) }; 2372 | var obj = this.obj; 2373 | if(util.isArray(obj)) { 2374 | this.assert(obj.some(function(item) { 2375 | return eql(item, other).result; 2376 | })); 2377 | } else if(util.isString(obj)) { 2378 | // expect obj to be string 2379 | this.assert(obj.indexOf(String(other)) >= 0); 2380 | } else if(util.isObject(obj)) { 2381 | // object contains object case 2382 | util.forOwn(other, function(value, key) { 2383 | obj.should.have.property(key, value); 2384 | }); 2385 | } else { 2386 | //other uncovered cases 2387 | this.assert(false); 2388 | } 2389 | }); 2390 | 2391 | /** 2392 | * Assert that given object is contain equally structured object on the same depth level. 2393 | * If given object is an array and `other` is an array it checks that the eql elements is going in the same sequence in given array (recursive) 2394 | * For string it is working as `Assertion#containEql 2395 | * If given object is an object it checks that the same keys contain deep equal values (recursive) 2396 | * On other cases it try to check with `.eql` 2397 | * 2398 | * @name containDeepOrdered 2399 | * @memberOf Assertion 2400 | * @category assertion contain 2401 | * @param {*} other Nested object 2402 | * @example 2403 | * 2404 | * [ 1, 2, 3].should.containDeepOrdered([1, 2]); 2405 | * [ 1, 2, [ 1, 2, 3 ]].should.containDeepOrdered([ 1, [ 2, 3 ]]); 2406 | * 2407 | * '123'.should.containDeepOrdered('1') 2408 | * 2409 | * ({ a: 10, b: { c: 10, d: [1, 2, 3] }}).should.containDeepOrdered({a: 10}); 2410 | * ({ a: 10, b: { c: 10, d: [1, 2, 3] }}).should.containDeepOrdered({b: {c: 10}}); 2411 | * ({ a: 10, b: { c: 10, d: [1, 2, 3] }}).should.containDeepOrdered({b: {d: [1, 3]}}); 2412 | */ 2413 | Assertion.add('containDeepOrdered', function(other) { 2414 | var eql = _eql(); 2415 | this.params = { operator: 'to contain ' + i(other) }; 2416 | 2417 | var obj = this.obj; 2418 | if(util.isArray(obj)) { 2419 | if(util.isArray(other)) { 2420 | var otherIdx = 0; 2421 | obj.forEach(function(item) { 2422 | try { 2423 | should(item).containDeepOrdered(other[otherIdx]); 2424 | otherIdx++; 2425 | } catch(e) { 2426 | if(e instanceof should.AssertionError) { 2427 | return; 2428 | } 2429 | throw e; 2430 | } 2431 | }, this); 2432 | 2433 | this.assert(otherIdx == other.length); 2434 | //search array contain other as sub sequence 2435 | } else { 2436 | this.assert(false); 2437 | } 2438 | } else if(util.isString(obj)) {// expect other to be string 2439 | this.assert(obj.indexOf(String(other)) >= 0); 2440 | } else if(util.isObject(obj)) {// object contains object case 2441 | if(util.isObject(other)) { 2442 | util.forOwn(other, function(value, key) { 2443 | should(obj[key]).containDeepOrdered(value); 2444 | }); 2445 | } else {//one of the properties contain value 2446 | this.assert(false); 2447 | } 2448 | } else { 2449 | this.eql(other); 2450 | } 2451 | }); 2452 | 2453 | /** 2454 | * The same like `Assertion#containDeepOrdered` but all checks on arrays without order. 2455 | * 2456 | * @name containDeep 2457 | * @memberOf Assertion 2458 | * @category assertion contain 2459 | * @param {*} other Nested object 2460 | * @example 2461 | * 2462 | * [ 1, 2, 3].should.containDeep([2, 1]); 2463 | * [ 1, 2, [ 1, 2, 3 ]].should.containDeep([ 1, [ 3, 1 ]]); 2464 | */ 2465 | Assertion.add('containDeep', function(other) { 2466 | var eql = _eql(); 2467 | this.params = { operator: 'to contain ' + i(other) }; 2468 | 2469 | var obj = this.obj; 2470 | if(util.isArray(obj)) { 2471 | if(util.isArray(other)) { 2472 | var usedKeys = {}; 2473 | other.forEach(function(otherItem) { 2474 | this.assert(obj.some(function(item, index) { 2475 | if(index in usedKeys) return false; 2476 | 2477 | try { 2478 | should(item).containDeep(otherItem); 2479 | usedKeys[index] = true; 2480 | return true; 2481 | } catch(e) { 2482 | if(e instanceof should.AssertionError) { 2483 | return false; 2484 | } 2485 | throw e; 2486 | } 2487 | })); 2488 | }, this); 2489 | 2490 | } else { 2491 | this.assert(false); 2492 | } 2493 | } else if(util.isString(obj)) {// expect other to be string 2494 | this.assert(obj.indexOf(String(other)) >= 0); 2495 | } else if(util.isObject(obj)) {// object contains object case 2496 | if(util.isObject(other)) { 2497 | util.forOwn(other, function(value, key) { 2498 | should(obj[key]).containDeep(value); 2499 | }); 2500 | } else {//one of the properties contain value 2501 | this.assert(false); 2502 | } 2503 | } else { 2504 | this.eql(other); 2505 | } 2506 | }); 2507 | 2508 | }; 2509 | 2510 | },{"../eql":8,"../util":23}],14:[function(require,module,exports){ 2511 | /*! 2512 | * Should 2513 | * Copyright(c) 2010-2014 TJ Holowaychuk 2514 | * MIT Licensed 2515 | */ 2516 | 2517 | var _eql = require('../eql'); 2518 | 2519 | var config = require('../config'); 2520 | 2521 | var util = require('../util'); 2522 | 2523 | module.exports = function(should, Assertion) { 2524 | 2525 | /** 2526 | * Deep object equality comparison. For full spec see [`should-equal tests`](https://github.com/shouldjs/equal/blob/master/test.js). 2527 | * 2528 | * @name eql 2529 | * @memberOf Assertion 2530 | * @category assertion equality 2531 | * @param {*} val Expected value 2532 | * @param {string} [description] Optional message 2533 | * @example 2534 | * 2535 | * (10).should.be.eql(10); 2536 | * ('10').should.not.be.eql(10); 2537 | * (-0).should.not.be.eql(+0); 2538 | * 2539 | * NaN.should.be.eql(NaN); 2540 | * 2541 | * ({ a: 10}).should.be.eql({ a: 10 }); 2542 | * [ 'a' ].should.not.be.eql({ '0': 'a' }); 2543 | */ 2544 | Assertion.add('eql', function(val, description) { 2545 | var eql = _eql(); 2546 | this.params = {operator: 'to equal', expected: val, showDiff: true, message: description}; 2547 | 2548 | var strictResult = eql(this.obj, val, should.config); 2549 | 2550 | var result = config.useOldDeepEqual ? strictResult: strictResult.result; 2551 | 2552 | if(!config.useOldDeepEqual && !strictResult.result) { 2553 | this.params.details = util.formatEqlResult(strictResult, this.obj, val, should.format); 2554 | } 2555 | 2556 | this.assert(result); 2557 | }); 2558 | 2559 | /** 2560 | * Exact comparison using ===. 2561 | * 2562 | * @name equal 2563 | * @memberOf Assertion 2564 | * @category assertion equality 2565 | * @alias Assertion#exactly 2566 | * @param {*} val Expected value 2567 | * @param {string} [description] Optional message 2568 | * @example 2569 | * 2570 | * 10.should.be.equal(10); 2571 | * 'a'.should.be.exactly('a'); 2572 | * 2573 | * should(null).be.exactly(null); 2574 | */ 2575 | Assertion.add('equal', function(val, description) { 2576 | this.params = {operator: 'to be', expected: val, showDiff: true, message: description}; 2577 | 2578 | this.assert(val === this.obj); 2579 | }); 2580 | 2581 | Assertion.alias('equal', 'exactly'); 2582 | }; 2583 | },{"../config":7,"../eql":8,"../util":23}],15:[function(require,module,exports){ 2584 | /*! 2585 | * Should 2586 | * Copyright(c) 2010-2014 TJ Holowaychuk 2587 | * MIT Licensed 2588 | */ 2589 | var util = require('../util'); 2590 | 2591 | module.exports = function(should, Assertion) { 2592 | var i = should.format; 2593 | 2594 | /** 2595 | * Assert given function throws error with such message. 2596 | * 2597 | * @name throw 2598 | * @memberOf Assertion 2599 | * @category assertion errors 2600 | * @alias Assertion#throwError 2601 | * @param {string|RegExp|Function|Object} [message] Message to match or properties 2602 | * @param {Object} [properties] Optional properties that will be matched to thrown error 2603 | * @example 2604 | * 2605 | * (function(){ throw new Error('fail') }).should.throw(); 2606 | * (function(){ throw new Error('fail') }).should.throw('fail'); 2607 | * (function(){ throw new Error('fail') }).should.throw(/fail/); 2608 | * 2609 | * (function(){ throw new Error('fail') }).should.throw(Error); 2610 | * var error = new Error(); 2611 | * error.a = 10; 2612 | * (function(){ throw error; }).should.throw(Error, { a: 10 }); 2613 | * (function(){ throw error; }).should.throw({ a: 10 }); 2614 | */ 2615 | Assertion.add('throw', function(message, properties) { 2616 | var fn = this.obj 2617 | , err = {} 2618 | , errorInfo = '' 2619 | , thrown = false; 2620 | 2621 | this.is.a.Function; 2622 | 2623 | var errorMatched = true; 2624 | 2625 | try { 2626 | fn(); 2627 | } catch(e) { 2628 | thrown = true; 2629 | err = e; 2630 | } 2631 | 2632 | if(thrown) { 2633 | if(message) { 2634 | if('string' == typeof message) { 2635 | errorMatched = message == err.message; 2636 | } else if(message instanceof RegExp) { 2637 | errorMatched = message.test(err.message); 2638 | } else if('function' == typeof message) { 2639 | errorMatched = err instanceof message; 2640 | } else if(util.isObject(message)) { 2641 | try { 2642 | err.should.match(message); 2643 | } catch(e) { 2644 | if(e instanceof should.AssertionError) { 2645 | errorInfo = ": " + e.message; 2646 | errorMatched = false; 2647 | } else { 2648 | throw e; 2649 | } 2650 | } 2651 | } 2652 | 2653 | if(!errorMatched) { 2654 | if('string' == typeof message || message instanceof RegExp) { 2655 | errorInfo = " with a message matching " + i(message) + ", but got '" + err.message + "'"; 2656 | } else if('function' == typeof message) { 2657 | errorInfo = " of type " + util.functionName(message) + ", but got " + util.functionName(err.constructor); 2658 | } 2659 | } else if('function' == typeof message && properties) { 2660 | try { 2661 | err.should.match(properties); 2662 | } catch(e) { 2663 | if(e instanceof should.AssertionError) { 2664 | errorInfo = ": " + e.message; 2665 | errorMatched = false; 2666 | } else { 2667 | throw e; 2668 | } 2669 | } 2670 | } 2671 | } else { 2672 | errorInfo = " (got " + i(err) + ")"; 2673 | } 2674 | } 2675 | 2676 | this.params = { operator: 'to throw exception' + errorInfo }; 2677 | 2678 | this.assert(thrown); 2679 | this.assert(errorMatched); 2680 | }); 2681 | 2682 | Assertion.alias('throw', 'throwError'); 2683 | }; 2684 | },{"../util":23}],16:[function(require,module,exports){ 2685 | /*! 2686 | * Should 2687 | * Copyright(c) 2010-2014 TJ Holowaychuk 2688 | * MIT Licensed 2689 | */ 2690 | 2691 | var util = require('../util'), 2692 | _eql = require('../eql'); 2693 | 2694 | module.exports = function(should, Assertion) { 2695 | var i = should.format; 2696 | 2697 | /** 2698 | * Asserts if given object match `other` object, using some assumptions: 2699 | * First object matched if they are equal, 2700 | * If `other` is a regexp and given object is a string check on matching with regexp 2701 | * If `other` is a regexp and given object is an array check if all elements matched regexp 2702 | * If `other` is a regexp and given object is an object check values on matching regexp 2703 | * If `other` is a function check if this function throws AssertionError on given object or return false - it will be assumed as not matched 2704 | * If `other` is an object check if the same keys matched with above rules 2705 | * All other cases failed 2706 | * 2707 | * @name match 2708 | * @memberOf Assertion 2709 | * @category assertion matching 2710 | * @param {*} other Object to match 2711 | * @param {string} [description] Optional message 2712 | * @example 2713 | * 'foobar'.should.match(/^foo/); 2714 | * 'foobar'.should.not.match(/^bar/); 2715 | * 2716 | * ({ a: 'foo', c: 'barfoo' }).should.match(/foo$/); 2717 | * 2718 | * ['a', 'b', 'c'].should.match(/[a-z]/); 2719 | * 2720 | * (5).should.not.match(function(n) { 2721 | * return n < 0; 2722 | * }); 2723 | * (5).should.not.match(function(it) { 2724 | * it.should.be.an.Array; 2725 | * }); 2726 | * ({ a: 10, b: 'abc', c: { d: 10 }, d: 0 }).should 2727 | * .match({ a: 10, b: /c$/, c: function(it) { 2728 | * return it.should.have.property('d', 10); 2729 | * }}); 2730 | * 2731 | * [10, 'abc', { d: 10 }, 0].should 2732 | * .match({ '0': 10, '1': /c$/, '2': function(it) { 2733 | * return it.should.have.property('d', 10); 2734 | * }}); 2735 | */ 2736 | Assertion.add('match', function(other, description) { 2737 | var eql = _eql(); 2738 | this.params = {operator: 'to match ' + i(other), message: description}; 2739 | 2740 | if(!eql(this.obj, other).result) { 2741 | if(util.isRegExp(other)) { // something - regex 2742 | 2743 | if(util.isString(this.obj)) { 2744 | 2745 | this.assert(other.exec(this.obj)); 2746 | } else if(util.isArray(this.obj)) { 2747 | 2748 | this.obj.forEach(function(item) { 2749 | this.assert(other.exec(item));// should we try to convert to String and exec? 2750 | }, this); 2751 | } else if(util.isObject(this.obj)) { 2752 | 2753 | var notMatchedProps = [], matchedProps = []; 2754 | util.forOwn(this.obj, function(value, name) { 2755 | if(other.exec(value)) matchedProps.push(util.formatProp(name)); 2756 | else notMatchedProps.push(util.formatProp(name) + ' (' + i(value) + ')'); 2757 | }, this); 2758 | 2759 | if(notMatchedProps.length) 2760 | this.params.operator += '\n not matched properties: ' + notMatchedProps.join(', '); 2761 | if(matchedProps.length) 2762 | this.params.operator += '\n matched properties: ' + matchedProps.join(', '); 2763 | 2764 | this.assert(notMatchedProps.length == 0); 2765 | } // should we try to convert to String and exec? 2766 | } else if(util.isFunction(other)) { 2767 | var res; 2768 | 2769 | res = other(this.obj); 2770 | 2771 | if(res instanceof Assertion) { 2772 | this.params.operator += '\n ' + res.getMessage(); 2773 | } 2774 | 2775 | //if we throw exception ok - it is used .should inside 2776 | if(util.isBoolean(res)) { 2777 | this.assert(res); // if it is just boolean function assert on it 2778 | } 2779 | } else if(util.isObject(other)) { // try to match properties (for Object and Array) 2780 | notMatchedProps = []; 2781 | matchedProps = []; 2782 | 2783 | util.forOwn(other, function(value, key) { 2784 | try { 2785 | should(this.obj[key]).match(value); 2786 | matchedProps.push(util.formatProp(key)); 2787 | } catch(e) { 2788 | if(e instanceof should.AssertionError) { 2789 | notMatchedProps.push(util.formatProp(key) + ' (' + i(this.obj[key]) + ')'); 2790 | } else { 2791 | throw e; 2792 | } 2793 | } 2794 | }, this); 2795 | 2796 | if(notMatchedProps.length) 2797 | this.params.operator += '\n not matched properties: ' + notMatchedProps.join(', '); 2798 | if(matchedProps.length) 2799 | this.params.operator += '\n matched properties: ' + matchedProps.join(', '); 2800 | 2801 | this.assert(notMatchedProps.length == 0); 2802 | } else { 2803 | this.assert(false); 2804 | } 2805 | } 2806 | }); 2807 | 2808 | /** 2809 | * Asserts if given object values or array elements all match `other` object, using some assumptions: 2810 | * First object matched if they are equal, 2811 | * If `other` is a regexp - matching with regexp 2812 | * If `other` is a function check if this function throws AssertionError on given object or return false - it will be assumed as not matched 2813 | * All other cases check if this `other` equal to each element 2814 | * 2815 | * @name matchEach 2816 | * @memberOf Assertion 2817 | * @category assertion matching 2818 | * @param {*} other Object to match 2819 | * @param {string} [description] Optional message 2820 | * @example 2821 | * [ 'a', 'b', 'c'].should.matchEach(/\w+/); 2822 | * [ 'a', 'a', 'a'].should.matchEach('a'); 2823 | * 2824 | * [ 'a', 'a', 'a'].should.matchEach(function(value) { value.should.be.eql('a') }); 2825 | * 2826 | * { a: 'a', b: 'a', c: 'a' }.should.matchEach(function(value) { value.should.be.eql('a') }); 2827 | */ 2828 | Assertion.add('matchEach', function(other, description) { 2829 | var eql = _eql(); 2830 | this.params = {operator: 'to match each ' + i(other), message: description}; 2831 | 2832 | var f = other; 2833 | 2834 | if(util.isRegExp(other)) 2835 | f = function(it) { 2836 | return !!other.exec(it); 2837 | }; 2838 | else if(!util.isFunction(other)) 2839 | f = function(it) { 2840 | return eql(it, other).result; 2841 | }; 2842 | 2843 | util.forOwn(this.obj, function(value, key) { 2844 | var res = f(value, key); 2845 | 2846 | //if we throw exception ok - it is used .should inside 2847 | if(util.isBoolean(res)) { 2848 | this.assert(res); // if it is just boolean function assert on it 2849 | } 2850 | }, this); 2851 | }); 2852 | }; 2853 | },{"../eql":8,"../util":23}],17:[function(require,module,exports){ 2854 | /*! 2855 | * Should 2856 | * Copyright(c) 2010-2014 TJ Holowaychuk 2857 | * MIT Licensed 2858 | */ 2859 | 2860 | module.exports = function(should, Assertion) { 2861 | 2862 | /** 2863 | * Assert given object is NaN 2864 | * @name NaN 2865 | * @memberOf Assertion 2866 | * @category assertion numbers 2867 | * @example 2868 | * 2869 | * (10).should.not.be.NaN; 2870 | * NaN.should.be.NaN; 2871 | */ 2872 | Assertion.add('NaN', function() { 2873 | this.params = { operator: 'to be NaN' }; 2874 | 2875 | this.assert(this.obj !== this.obj); 2876 | }, true); 2877 | 2878 | /** 2879 | * Assert given object is not finite (positive or negative) 2880 | * 2881 | * @name Infinity 2882 | * @memberOf Assertion 2883 | * @category assertion numbers 2884 | * @example 2885 | * 2886 | * (10).should.not.be.Infinity; 2887 | * NaN.should.not.be.Infinity; 2888 | */ 2889 | Assertion.add('Infinity', function() { 2890 | this.params = { operator: 'to be Infinity' }; 2891 | 2892 | this.obj.should.be.a.Number 2893 | .and.not.a.NaN 2894 | .and.assert(!isFinite(this.obj)); 2895 | }, true); 2896 | 2897 | /** 2898 | * Assert given number between `start` and `finish` or equal one of them. 2899 | * 2900 | * @name within 2901 | * @memberOf Assertion 2902 | * @category assertion numbers 2903 | * @param {number} start Start number 2904 | * @param {number} finish Finish number 2905 | * @param {string} [description] Optional message 2906 | * @example 2907 | * 2908 | * (10).should.be.within(0, 20); 2909 | */ 2910 | Assertion.add('within', function(start, finish, description) { 2911 | this.params = { operator: 'to be within ' + start + '..' + finish, message: description }; 2912 | 2913 | this.assert(this.obj >= start && this.obj <= finish); 2914 | }); 2915 | 2916 | /** 2917 | * Assert given number near some other `value` within `delta` 2918 | * 2919 | * @name approximately 2920 | * @memberOf Assertion 2921 | * @category assertion numbers 2922 | * @param {number} value Center number 2923 | * @param {number} delta Radius 2924 | * @param {string} [description] Optional message 2925 | * @example 2926 | * 2927 | * (9.99).should.be.approximately(10, 0.1); 2928 | */ 2929 | Assertion.add('approximately', function(value, delta, description) { 2930 | this.params = { operator: 'to be approximately ' + value + " ±" + delta, message: description }; 2931 | 2932 | this.assert(Math.abs(this.obj - value) <= delta); 2933 | }); 2934 | 2935 | /** 2936 | * Assert given number above `n`. 2937 | * 2938 | * @name above 2939 | * @alias Assertion#greaterThan 2940 | * @memberOf Assertion 2941 | * @category assertion numbers 2942 | * @param {number} n Margin number 2943 | * @param {string} [description] Optional message 2944 | * @example 2945 | * 2946 | * (10).should.be.above(0); 2947 | */ 2948 | Assertion.add('above', function(n, description) { 2949 | this.params = { operator: 'to be above ' + n, message: description }; 2950 | 2951 | this.assert(this.obj > n); 2952 | }); 2953 | 2954 | /** 2955 | * Assert given number below `n`. 2956 | * 2957 | * @name below 2958 | * @alias Assertion#lessThan 2959 | * @memberOf Assertion 2960 | * @category assertion numbers 2961 | * @param {number} n Margin number 2962 | * @param {string} [description] Optional message 2963 | * @example 2964 | * 2965 | * (0).should.be.above(10); 2966 | */ 2967 | Assertion.add('below', function(n, description) { 2968 | this.params = { operator: 'to be below ' + n, message: description }; 2969 | 2970 | this.assert(this.obj < n); 2971 | }); 2972 | 2973 | Assertion.alias('above', 'greaterThan'); 2974 | Assertion.alias('below', 'lessThan'); 2975 | 2976 | }; 2977 | 2978 | },{}],18:[function(require,module,exports){ 2979 | /*! 2980 | * Should 2981 | * Copyright(c) 2010-2014 TJ Holowaychuk 2982 | * MIT Licensed 2983 | */ 2984 | 2985 | var util = require('../util'), 2986 | _eql = require('../eql'); 2987 | 2988 | var aSlice = Array.prototype.slice; 2989 | 2990 | module.exports = function(should, Assertion) { 2991 | var i = should.format; 2992 | 2993 | /** 2994 | * Asserts given object has enumerable property with optionally value 2995 | * 2996 | * @name enumerable 2997 | * @memberOf Assertion 2998 | * @category assertion property 2999 | * @param {string} name Name of property 3000 | * @param {*} [val] Optional property value to check 3001 | * @example 3002 | * 3003 | * ({ a: 10 }).should.have.enumerable('a'); 3004 | */ 3005 | Assertion.add('enumerable', function(name, val) { 3006 | name = String(name); 3007 | 3008 | var eql = _eql(); 3009 | 3010 | this.params = { 3011 | operator: "to have enumerable property " + util.formatProp(name) 3012 | }; 3013 | 3014 | this.assert(this.obj.propertyIsEnumerable(name)); 3015 | 3016 | if(arguments.length > 1) { 3017 | this.params.operator += " equal to " + i(val); 3018 | this.assert(eql(val, this.obj[name]).result); 3019 | } 3020 | }); 3021 | 3022 | /** 3023 | * Asserts given object has enumerable properties 3024 | * 3025 | * @name enumerables 3026 | * @memberOf Assertion 3027 | * @category assertion property 3028 | * @param {Array|...string|Object} names Names of property 3029 | * @example 3030 | * 3031 | * ({ a: 10, b: 10 }).should.have.enumerables('a'); 3032 | */ 3033 | Assertion.add('enumerables', function(names) { 3034 | if(arguments.length > 1) { 3035 | names = aSlice.call(arguments); 3036 | } else if(!util.isArray(names)) { 3037 | if(util.isString(names)) { 3038 | names = [names]; 3039 | } else { 3040 | values = names; 3041 | names = Object.keys(names); 3042 | } 3043 | } 3044 | 3045 | this.params = { 3046 | operator: "to have enumerables " + names.map(util.formatProp) 3047 | }; 3048 | 3049 | names.forEach(function(name) { 3050 | this.assert(this.obj.propertyIsEnumerable(name)); 3051 | }, this); 3052 | }); 3053 | 3054 | /** 3055 | * Asserts given object has property with optionally value. **On success it change given object to be value of property**. 3056 | * 3057 | * @name property 3058 | * @memberOf Assertion 3059 | * @category assertion property 3060 | * @param {string} name Name of property 3061 | * @param {*} [val] Optional property value to check 3062 | * @example 3063 | * 3064 | * ({ a: 10 }).should.have.property('a'); 3065 | */ 3066 | Assertion.add('property', function(name, val) { 3067 | name = String(name); 3068 | if(arguments.length > 1) { 3069 | var p = {}; 3070 | p[name] = val; 3071 | this.have.properties(p); 3072 | } else { 3073 | this.have.properties(name); 3074 | } 3075 | this.obj = this.obj[name]; 3076 | }); 3077 | 3078 | /** 3079 | * Asserts given object has properties. On this method affect .any modifier, which allow to check not all properties. 3080 | * 3081 | * @name properties 3082 | * @memberOf Assertion 3083 | * @category assertion property 3084 | * @param {Array|...string|Object} names Names of property 3085 | * @example 3086 | * 3087 | * ({ a: 10 }).should.have.properties('a'); 3088 | */ 3089 | Assertion.add('properties', function(names) { 3090 | var values = {}; 3091 | var eql = _eql(); 3092 | if(arguments.length > 1) { 3093 | names = aSlice.call(arguments); 3094 | } else if(!util.isArray(names)) { 3095 | if(util.isString(names)) { 3096 | names = [names]; 3097 | } else { 3098 | values = names; 3099 | names = Object.keys(names); 3100 | } 3101 | } 3102 | 3103 | var obj = Object(this.obj), missingProperties = []; 3104 | 3105 | //just enumerate properties and check if they all present 3106 | names.forEach(function(name) { 3107 | if(!(name in obj)) missingProperties.push(util.formatProp(name)); 3108 | }); 3109 | 3110 | var props = missingProperties; 3111 | if(props.length === 0) { 3112 | props = names.map(util.formatProp); 3113 | } else if(this.anyOne) { 3114 | props = names.filter(function(name) { 3115 | return missingProperties.indexOf(util.formatProp(name)) < 0; 3116 | }).map(util.formatProp); 3117 | } 3118 | 3119 | var operator = (props.length === 1 ? 3120 | 'to have property ' : 'to have ' + (this.anyOne ? 'any of ' : '') + 'properties ') + props.join(', '); 3121 | 3122 | this.params = {obj: this.obj, operator: operator}; 3123 | 3124 | //check that all properties presented 3125 | //or if we request one of them that at least one them presented 3126 | this.assert(missingProperties.length === 0 || (this.anyOne && missingProperties.length != names.length)); 3127 | 3128 | // check if values in object matched expected 3129 | var valueCheckNames = Object.keys(values); 3130 | if(valueCheckNames.length) { 3131 | var wrongValues = []; 3132 | props = []; 3133 | 3134 | // now check values, as there we have all properties 3135 | valueCheckNames.forEach(function(name) { 3136 | var value = values[name]; 3137 | if(!eql(obj[name], value).result) { 3138 | wrongValues.push(util.formatProp(name) + ' of ' + i(value) + ' (got ' + i(obj[name]) + ')'); 3139 | } else { 3140 | props.push(util.formatProp(name) + ' of ' + i(value)); 3141 | } 3142 | }); 3143 | 3144 | if((wrongValues.length !== 0 && !this.anyOne) || (this.anyOne && props.length === 0)) { 3145 | props = wrongValues; 3146 | } 3147 | 3148 | operator = (props.length === 1 ? 3149 | 'to have property ' : 'to have ' + (this.anyOne ? 'any of ' : '') + 'properties ') + props.join(', '); 3150 | 3151 | this.params = {obj: this.obj, operator: operator}; 3152 | 3153 | //if there is no not matched values 3154 | //or there is at least one matched 3155 | this.assert(wrongValues.length === 0 || (this.anyOne && wrongValues.length != valueCheckNames.length)); 3156 | } 3157 | }); 3158 | 3159 | /** 3160 | * Asserts given object has property `length` with given value `n` 3161 | * 3162 | * @name length 3163 | * @alias Assertion#lengthOf 3164 | * @memberOf Assertion 3165 | * @category assertion property 3166 | * @param {number} n Expected length 3167 | * @param {string} [description] Optional message 3168 | * @example 3169 | * 3170 | * [1, 2].should.have.length(2); 3171 | */ 3172 | Assertion.add('length', function(n, description) { 3173 | this.have.property('length', n, description); 3174 | }); 3175 | 3176 | Assertion.alias('length', 'lengthOf'); 3177 | 3178 | var hasOwnProperty = Object.prototype.hasOwnProperty; 3179 | 3180 | /** 3181 | * Asserts given object has own property. **On success it change given object to be value of property**. 3182 | * 3183 | * @name ownProperty 3184 | * @alias Assertion#hasOwnProperty 3185 | * @memberOf Assertion 3186 | * @category assertion property 3187 | * @param {string} name Name of property 3188 | * @param {string} [description] Optional message 3189 | * @example 3190 | * 3191 | * ({ a: 10 }).should.have.ownProperty('a'); 3192 | */ 3193 | Assertion.add('ownProperty', function(name, description) { 3194 | name = String(name); 3195 | this.params = { 3196 | obj: this.obj, 3197 | operator: 'to have own property ' + util.formatProp(name), 3198 | message: description 3199 | }; 3200 | 3201 | this.assert(hasOwnProperty.call(this.obj, name)); 3202 | 3203 | this.obj = this.obj[name]; 3204 | }); 3205 | 3206 | Assertion.alias('ownProperty', 'hasOwnProperty'); 3207 | 3208 | /** 3209 | * Asserts given object is empty. For strings, arrays and arguments it checks .length property, for objects it checks keys. 3210 | * 3211 | * @name empty 3212 | * @memberOf Assertion 3213 | * @category assertion property 3214 | * @example 3215 | * 3216 | * ''.should.be.empty; 3217 | * [].should.be.empty; 3218 | * ({}).should.be.empty; 3219 | */ 3220 | Assertion.add('empty', function() { 3221 | this.params = {operator: 'to be empty'}; 3222 | 3223 | if(util.isString(this.obj) || util.isArray(this.obj) || util.isArguments(this.obj)) { 3224 | this.obj.should.have.property('length', 0); 3225 | } else { 3226 | var obj = Object(this.obj); // wrap to reference for booleans and numbers 3227 | for(var prop in obj) { 3228 | this.obj.should.not.have.ownProperty(prop); 3229 | } 3230 | } 3231 | }, true); 3232 | 3233 | /** 3234 | * Asserts given object has exact keys. 3235 | * 3236 | * @name keys 3237 | * @alias Assertion#key 3238 | * @memberOf Assertion 3239 | * @category assertion property 3240 | * @param {Array|...string|Object} [keys] Keys to check 3241 | * @example 3242 | * 3243 | * ({ a: 10}).should.have.keys('a'); 3244 | * ({}).should.have.keys(); 3245 | */ 3246 | Assertion.add('keys', function(keys) { 3247 | if(arguments.length > 1) keys = aSlice.call(arguments); 3248 | else if(arguments.length === 1 && util.isString(keys)) keys = [keys]; 3249 | else if(arguments.length === 0) keys = []; 3250 | 3251 | keys = keys.map(String); 3252 | 3253 | var obj = Object(this.obj); 3254 | 3255 | // first check if some keys are missing 3256 | var missingKeys = []; 3257 | keys.forEach(function(key) { 3258 | if(!hasOwnProperty.call(this.obj, key)) 3259 | missingKeys.push(util.formatProp(key)); 3260 | }, this); 3261 | 3262 | // second check for extra keys 3263 | var extraKeys = []; 3264 | Object.keys(obj).forEach(function(key) { 3265 | if(keys.indexOf(key) < 0) { 3266 | extraKeys.push(util.formatProp(key)); 3267 | } 3268 | }); 3269 | 3270 | var verb = keys.length === 0 ? 'to be empty' : 3271 | 'to have ' + (keys.length === 1 ? 'key ' : 'keys '); 3272 | 3273 | this.params = {operator: verb + keys.map(util.formatProp).join(', ')}; 3274 | 3275 | if(missingKeys.length > 0) 3276 | this.params.operator += '\n\tmissing keys: ' + missingKeys.join(', '); 3277 | 3278 | if(extraKeys.length > 0) 3279 | this.params.operator += '\n\textra keys: ' + extraKeys.join(', '); 3280 | 3281 | this.assert(missingKeys.length === 0 && extraKeys.length === 0); 3282 | }); 3283 | 3284 | Assertion.alias("keys", "key"); 3285 | 3286 | /** 3287 | * Asserts given object has nested property in depth by path. **On success it change given object to be value of final property**. 3288 | * 3289 | * @name propertyByPath 3290 | * @memberOf Assertion 3291 | * @category assertion property 3292 | * @param {Array|...string} properties Properties path to search 3293 | * @example 3294 | * 3295 | * ({ a: {b: 10}}).should.have.propertyByPath('a', 'b').eql(10); 3296 | */ 3297 | Assertion.add('propertyByPath', function(properties) { 3298 | if(arguments.length > 1) properties = aSlice.call(arguments); 3299 | else if(arguments.length === 1 && util.isString(properties)) properties = [properties]; 3300 | else if(arguments.length === 0) properties = []; 3301 | 3302 | var allProps = properties.map(util.formatProp); 3303 | 3304 | properties = properties.map(String); 3305 | 3306 | var obj = should(Object(this.obj)); 3307 | 3308 | var foundProperties = []; 3309 | 3310 | var currentProperty; 3311 | while(currentProperty = properties.shift()) { 3312 | this.params = {operator: 'to have property by path ' + allProps.join(', ') + ' - failed on ' + util.formatProp(currentProperty)}; 3313 | obj = obj.have.property(currentProperty); 3314 | foundProperties.push(currentProperty); 3315 | } 3316 | 3317 | this.params = {obj: this.obj, operator: 'to have property by path ' + allProps.join(', ')}; 3318 | 3319 | this.obj = obj.obj; 3320 | }); 3321 | }; 3322 | 3323 | },{"../eql":8,"../util":23}],19:[function(require,module,exports){ 3324 | /*! 3325 | * Should 3326 | * Copyright(c) 2010-2014 TJ Holowaychuk 3327 | * MIT Licensed 3328 | */ 3329 | 3330 | module.exports = function(should, Assertion) { 3331 | /** 3332 | * Assert given string starts with prefix 3333 | * @name startWith 3334 | * @memberOf Assertion 3335 | * @category assertion strings 3336 | * @param {string} str Prefix 3337 | * @param {string} [description] Optional message 3338 | * @example 3339 | * 3340 | * 'abc'.should.startWith('a'); 3341 | */ 3342 | Assertion.add('startWith', function(str, description) { 3343 | this.params = { operator: 'to start with ' + should.format(str), message: description }; 3344 | 3345 | this.assert(0 === this.obj.indexOf(str)); 3346 | }); 3347 | 3348 | /** 3349 | * Assert given string starts with prefix 3350 | * @name endWith 3351 | * @memberOf Assertion 3352 | * @category assertion strings 3353 | * @param {string} str Prefix 3354 | * @param {string} [description] Optional message 3355 | * @example 3356 | * 3357 | * 'abca'.should.endWith('a'); 3358 | */ 3359 | Assertion.add('endWith', function(str, description) { 3360 | this.params = { operator: 'to end with ' + should.format(str), message: description }; 3361 | 3362 | this.assert(this.obj.indexOf(str, this.obj.length - str.length) >= 0); 3363 | }); 3364 | }; 3365 | },{}],20:[function(require,module,exports){ 3366 | /*! 3367 | * Should 3368 | * Copyright(c) 2010-2014 TJ Holowaychuk 3369 | * MIT Licensed 3370 | */ 3371 | 3372 | var util = require('../util'); 3373 | 3374 | module.exports = function(should, Assertion) { 3375 | /** 3376 | * Assert given object is number 3377 | * @name Number 3378 | * @memberOf Assertion 3379 | * @category assertion types 3380 | */ 3381 | Assertion.add('Number', function() { 3382 | this.params = { operator: 'to be a number' }; 3383 | 3384 | this.assert(util.isNumber(this.obj)); 3385 | }, true); 3386 | 3387 | /** 3388 | * Assert given object is arguments 3389 | * @name arguments 3390 | * @alias Assertion#Arguments 3391 | * @memberOf Assertion 3392 | * @category assertion types 3393 | */ 3394 | Assertion.add('arguments', function() { 3395 | this.params = { operator: 'to be arguments' }; 3396 | 3397 | this.assert(util.isArguments(this.obj)); 3398 | }, true); 3399 | 3400 | Assertion.alias('arguments', 'Arguments'); 3401 | 3402 | /** 3403 | * Assert given object has some type using `typeof` 3404 | * @name type 3405 | * @memberOf Assertion 3406 | * @param {string} type Type name 3407 | * @param {string} [description] Optional message 3408 | * @category assertion types 3409 | */ 3410 | Assertion.add('type', function(type, description) { 3411 | this.params = { operator: 'to have type ' + type, message: description }; 3412 | 3413 | (typeof this.obj).should.be.exactly(type, description); 3414 | }); 3415 | 3416 | /** 3417 | * Assert given object is instance of `constructor` 3418 | * @name instanceof 3419 | * @alias Assertion#instanceOf 3420 | * @memberOf Assertion 3421 | * @param {Function} constructor Constructor function 3422 | * @param {string} [description] Optional message 3423 | * @category assertion types 3424 | */ 3425 | Assertion.add('instanceof', function(constructor, description) { 3426 | this.params = { operator: 'to be an instance of ' + util.functionName(constructor), message: description }; 3427 | 3428 | this.assert(Object(this.obj) instanceof constructor); 3429 | }); 3430 | 3431 | Assertion.alias('instanceof', 'instanceOf'); 3432 | 3433 | /** 3434 | * Assert given object is function 3435 | * @name Function 3436 | * @memberOf Assertion 3437 | * @category assertion types 3438 | */ 3439 | Assertion.add('Function', function() { 3440 | this.params = { operator: 'to be a function' }; 3441 | 3442 | this.assert(util.isFunction(this.obj)); 3443 | }, true); 3444 | 3445 | /** 3446 | * Assert given object is object 3447 | * @name Object 3448 | * @memberOf Assertion 3449 | * @category assertion types 3450 | */ 3451 | Assertion.add('Object', function() { 3452 | this.params = { operator: 'to be an object' }; 3453 | 3454 | this.assert(util.isObject(this.obj)); 3455 | }, true); 3456 | 3457 | /** 3458 | * Assert given object is string 3459 | * @name String 3460 | * @memberOf Assertion 3461 | * @category assertion types 3462 | */ 3463 | Assertion.add('String', function() { 3464 | this.params = { operator: 'to be a string' }; 3465 | 3466 | this.assert(util.isString(this.obj)); 3467 | }, true); 3468 | 3469 | /** 3470 | * Assert given object is array 3471 | * @name Array 3472 | * @memberOf Assertion 3473 | * @category assertion types 3474 | */ 3475 | Assertion.add('Array', function() { 3476 | this.params = { operator: 'to be an array' }; 3477 | 3478 | this.assert(util.isArray(this.obj)); 3479 | }, true); 3480 | 3481 | /** 3482 | * Assert given object is boolean 3483 | * @name Boolean 3484 | * @memberOf Assertion 3485 | * @category assertion types 3486 | */ 3487 | Assertion.add('Boolean', function() { 3488 | this.params = { operator: 'to be a boolean' }; 3489 | 3490 | this.assert(util.isBoolean(this.obj)); 3491 | }, true); 3492 | 3493 | /** 3494 | * Assert given object is error 3495 | * @name Error 3496 | * @memberOf Assertion 3497 | * @category assertion types 3498 | */ 3499 | Assertion.add('Error', function() { 3500 | this.params = { operator: 'to be an error' }; 3501 | 3502 | this.assert(util.isError(this.obj)); 3503 | }, true); 3504 | 3505 | /** 3506 | * Assert given object is null 3507 | * @name null 3508 | * @alias Assertion#Null 3509 | * @memberOf Assertion 3510 | * @category assertion types 3511 | */ 3512 | Assertion.add('null', function() { 3513 | this.params = { operator: 'to be null' }; 3514 | 3515 | this.assert(this.obj === null); 3516 | }, true); 3517 | 3518 | Assertion.alias('null', 'Null'); 3519 | 3520 | 3521 | }; 3522 | 3523 | },{"../util":23}],21:[function(require,module,exports){ 3524 | /*! 3525 | * Should 3526 | * Copyright(c) 2010-2014 TJ Holowaychuk 3527 | * MIT Licensed 3528 | */ 3529 | 3530 | // Taken from node's assert module, because it sucks 3531 | // and exposes next to nothing useful. 3532 | var util = require('./util'); 3533 | 3534 | module.exports = _deepEqual; 3535 | 3536 | var pSlice = Array.prototype.slice; 3537 | 3538 | function _deepEqual(actual, expected) { 3539 | // 7.1. All identical values are equivalent, as determined by ===. 3540 | if (actual === expected) { 3541 | return true; 3542 | 3543 | } else if (util.isBuffer(actual) && util.isBuffer(expected)) { 3544 | if (actual.length != expected.length) return false; 3545 | 3546 | for (var i = 0; i < actual.length; i++) { 3547 | if (actual[i] !== expected[i]) return false; 3548 | } 3549 | 3550 | return true; 3551 | 3552 | // 7.2. If the expected value is a Date object, the actual value is 3553 | // equivalent if it is also a Date object that refers to the same time. 3554 | } else if (util.isDate(actual) && util.isDate(expected)) { 3555 | return actual.getTime() === expected.getTime(); 3556 | 3557 | // 7.3 If the expected value is a RegExp object, the actual value is 3558 | // equivalent if it is also a RegExp object with the same source and 3559 | // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). 3560 | } else if (util.isRegExp(actual) && util.isRegExp(expected)) { 3561 | return actual.source === expected.source && 3562 | actual.global === expected.global && 3563 | actual.multiline === expected.multiline && 3564 | actual.lastIndex === expected.lastIndex && 3565 | actual.ignoreCase === expected.ignoreCase; 3566 | 3567 | // 7.4. Other pairs that do not both pass typeof value == 'object', 3568 | // equivalence is determined by ==. 3569 | } else if (!util.isObject(actual) && !util.isObject(expected)) { 3570 | return actual == expected; 3571 | 3572 | // 7.5 For all other Object pairs, including Array objects, equivalence is 3573 | // determined by having the same number of owned properties (as verified 3574 | // with Object.prototype.hasOwnProperty.call), the same set of keys 3575 | // (although not necessarily the same order), equivalent values for every 3576 | // corresponding key, and an identical 'prototype' property. Note: this 3577 | // accounts for both named and indexed properties on Arrays. 3578 | } else { 3579 | return objEquiv(actual, expected); 3580 | } 3581 | } 3582 | 3583 | 3584 | function objEquiv (a, b) { 3585 | if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b)) 3586 | return false; 3587 | // an identical 'prototype' property. 3588 | if (a.prototype !== b.prototype) return false; 3589 | //~~~I've managed to break Object.keys through screwy arguments passing. 3590 | // Converting to array solves the problem. 3591 | if (util.isArguments(a)) { 3592 | if (!util.isArguments(b)) { 3593 | return false; 3594 | } 3595 | a = pSlice.call(a); 3596 | b = pSlice.call(b); 3597 | return _deepEqual(a, b); 3598 | } 3599 | try{ 3600 | var ka = Object.keys(a), 3601 | kb = Object.keys(b), 3602 | key, i; 3603 | } catch (e) {//happens when one is a string literal and the other isn't 3604 | return false; 3605 | } 3606 | // having the same number of owned properties (keys incorporates 3607 | // hasOwnProperty) 3608 | if (ka.length != kb.length) 3609 | return false; 3610 | //the same set of keys (although not necessarily the same order), 3611 | ka.sort(); 3612 | kb.sort(); 3613 | //~~~cheap key test 3614 | for (i = ka.length - 1; i >= 0; i--) { 3615 | if (ka[i] != kb[i]) 3616 | return false; 3617 | } 3618 | //equivalent values for every corresponding key, and 3619 | //~~~possibly expensive deep test 3620 | for (i = ka.length - 1; i >= 0; i--) { 3621 | key = ka[i]; 3622 | if (!_deepEqual(a[key], b[key])) return false; 3623 | } 3624 | return true; 3625 | } 3626 | },{"./util":23}],22:[function(require,module,exports){ 3627 | /*! 3628 | * Should 3629 | * Copyright(c) 2010-2014 TJ Holowaychuk 3630 | * MIT Licensed 3631 | */ 3632 | 3633 | 3634 | var util = require('./util'); 3635 | var inspect = require('should-format'); 3636 | 3637 | /** 3638 | * Our function should 3639 | * 3640 | * @param {*} obj Object to assert 3641 | * @returns {should.Assertion} Returns new Assertion for beginning assertion chain 3642 | * @example 3643 | * 3644 | * var should = require('should'); 3645 | * should('abc').be.a.string; 3646 | */ 3647 | var should = function should(obj) { 3648 | return (new should.Assertion(obj)).proxied(); 3649 | }; 3650 | 3651 | should.AssertionError = require('./assertion-error'); 3652 | should.Assertion = require('./assertion'); 3653 | 3654 | should.format = inspect; 3655 | 3656 | /** 3657 | * Object with configuration. 3658 | * It contains such properties: 3659 | * * `checkProtoEql` boolean - Affect if `.eql` will check objects prototypes 3660 | * * `useOldDeepEqual` boolean - Use old deepEqual implementation, that was copied from node's assert.deepEqual (will be removed in 5.x) 3661 | * 3662 | * @type {Object} 3663 | * @memberOf should 3664 | * @static 3665 | * @example 3666 | * 3667 | * var a = { a: 10 }, b = Object.create(null); 3668 | * b.a = 10; 3669 | * 3670 | * a.should.be.eql(b); 3671 | * //not throws 3672 | * 3673 | * should.config.checkProtoEql = true; 3674 | * a.should.be.eql(b); 3675 | * //throws AssertionError: expected { a: 10 } to equal { a: 10 } (because A and B have different prototypes) 3676 | */ 3677 | should.config = require('./config'); 3678 | 3679 | //Expose should to external world. 3680 | exports = module.exports = should; 3681 | 3682 | /** 3683 | * Allow to extend given prototype with should property using given name. This getter will **unwrap** all standard wrappers like `Number`, `Boolean`, `String`. 3684 | * Using `should(obj)` is the equivalent of using `obj.should` with known issues (like nulls and method calls etc). 3685 | * 3686 | * @param {string} [propertyName] Name of property to add. Default is `'should'`. 3687 | * @param {Object} [proto] Prototype to extend with. Default is `Object.prototype`. 3688 | * @memberOf should 3689 | * @returns {{ name: string, descriptor: Object, proto: Object }} Descriptor enough to return all back 3690 | * @static 3691 | * @example 3692 | * 3693 | * var prev = should.extend('must', Object.prototype); 3694 | * 3695 | * 'abc'.must.startWith('a'); 3696 | * 3697 | * var should = should.noConflict(prev); 3698 | * should.not.exist(Object.prototype.must); 3699 | */ 3700 | should.extend = function(propertyName, proto) { 3701 | propertyName = propertyName || 'should'; 3702 | proto = proto || Object.prototype; 3703 | 3704 | var prevDescriptor = Object.getOwnPropertyDescriptor(proto, propertyName); 3705 | 3706 | Object.defineProperty(proto, propertyName, { 3707 | set: function() { 3708 | }, 3709 | get: function() { 3710 | return should(util.isWrapperType(this) ? this.valueOf() : this); 3711 | }, 3712 | configurable: true 3713 | }); 3714 | 3715 | return { name: propertyName, descriptor: prevDescriptor, proto: proto }; 3716 | }; 3717 | 3718 | var defaultProto = Object.prototype; 3719 | var defaultProperty = 'should'; 3720 | 3721 | //Expose api via `Object#should`. 3722 | var prevShould = should.extend(defaultProperty, defaultProto); 3723 | 3724 | /** 3725 | * Delete previous extension. If `desc` missing it will remove default extension. 3726 | * 3727 | * @param {{ name: string, descriptor: Object, proto: Object }} [desc] Returned from `should.extend` object 3728 | * @memberOf should 3729 | * @returns {Function} Returns should function 3730 | * @static 3731 | * @example 3732 | * 3733 | * var should = require('should').noConflict(); 3734 | * 3735 | * should(Object.prototype).not.have.property('should'); 3736 | * 3737 | * var prev = should.extend('must', Object.prototype); 3738 | * 'abc'.must.startWith('a'); 3739 | * should.noConflict(prev); 3740 | * 3741 | * should(Object.prototype).not.have.property('must'); 3742 | */ 3743 | should.noConflict = function(desc) { 3744 | desc = desc || prevShould; 3745 | 3746 | delete desc.proto[desc.name]; 3747 | 3748 | if(desc.descriptor) { 3749 | Object.defineProperty(desc.proto, desc.name, desc.descriptor); 3750 | } 3751 | return should; 3752 | }; 3753 | 3754 | /** 3755 | * Simple utility function for a bit more easier should assertion extension 3756 | * @param {Function} f So called plugin function. It should accept 2 arguments: `should` function and `Assertion` constructor 3757 | * @memberOf should 3758 | * @returns {Function} Returns `should` function 3759 | * @static 3760 | * @example 3761 | * 3762 | * should.use(function(should, Assertion) { 3763 | * Assertion.add('asset', function() { 3764 | * this.params = { operator: 'to be asset' }; 3765 | * 3766 | * this.obj.should.have.property('id').which.is.a.Number; 3767 | * this.obj.should.have.property('path'); 3768 | * }) 3769 | * }) 3770 | */ 3771 | should.use = function(f) { 3772 | f(this, this.Assertion); 3773 | return this; 3774 | }; 3775 | 3776 | should 3777 | .use(require('./ext/assert')) 3778 | .use(require('./ext/chain')) 3779 | .use(require('./ext/bool')) 3780 | .use(require('./ext/number')) 3781 | .use(require('./ext/eql')) 3782 | .use(require('./ext/type')) 3783 | .use(require('./ext/string')) 3784 | .use(require('./ext/property')) 3785 | .use(require('./ext/error')) 3786 | .use(require('./ext/match')) 3787 | .use(require('./ext/contain')); 3788 | 3789 | },{"./assertion":6,"./assertion-error":5,"./config":7,"./ext/assert":10,"./ext/bool":11,"./ext/chain":12,"./ext/contain":13,"./ext/eql":14,"./ext/error":15,"./ext/match":16,"./ext/number":17,"./ext/property":18,"./ext/string":19,"./ext/type":20,"./util":23,"should-format":26}],23:[function(require,module,exports){ 3790 | (function (Buffer){ 3791 | /*! 3792 | * Should 3793 | * Copyright(c) 2010-2014 TJ Holowaychuk 3794 | * MIT Licensed 3795 | */ 3796 | 3797 | /** 3798 | * Check if given obj just a primitive type wrapper 3799 | * @param {Object} obj 3800 | * @returns {boolean} 3801 | * @private 3802 | */ 3803 | exports.isWrapperType = function(obj) { 3804 | return obj instanceof Number || obj instanceof String || obj instanceof Boolean; 3805 | }; 3806 | 3807 | /** 3808 | * Merge object b with object a. 3809 | * 3810 | * var a = { foo: 'bar' } 3811 | * , b = { bar: 'baz' }; 3812 | * 3813 | * utils.merge(a, b); 3814 | * // => { foo: 'bar', bar: 'baz' } 3815 | * 3816 | * @param {Object} a 3817 | * @param {Object} b 3818 | * @return {Object} 3819 | * @private 3820 | */ 3821 | 3822 | exports.merge = function(a, b) { 3823 | if(a && b) { 3824 | for(var key in b) { 3825 | a[key] = b[key]; 3826 | } 3827 | } 3828 | return a; 3829 | }; 3830 | 3831 | function isArray(arr) { 3832 | return isObject(arr) && (arr.__ArrayLike || Array.isArray(arr)); 3833 | } 3834 | 3835 | exports.isArray = isArray; 3836 | 3837 | function isNumber(arg) { 3838 | return typeof arg === 'number'; 3839 | } 3840 | 3841 | exports.isNumber = isNumber; 3842 | 3843 | function isString(arg) { 3844 | return typeof arg === 'string'; 3845 | } 3846 | 3847 | function isBoolean(arg) { 3848 | return typeof arg === 'boolean'; 3849 | } 3850 | exports.isBoolean = isBoolean; 3851 | 3852 | exports.isString = isString; 3853 | 3854 | function isBuffer(arg) { 3855 | return typeof Buffer !== 'undefined' && arg instanceof Buffer; 3856 | } 3857 | 3858 | exports.isBuffer = isBuffer; 3859 | 3860 | function isDate(d) { 3861 | return isObject(d) && objectToString(d) === '[object Date]'; 3862 | } 3863 | 3864 | exports.isDate = isDate; 3865 | 3866 | function objectToString(o) { 3867 | return Object.prototype.toString.call(o); 3868 | } 3869 | 3870 | function isObject(arg) { 3871 | return typeof arg === 'object' && arg !== null; 3872 | } 3873 | 3874 | exports.isObject = isObject; 3875 | 3876 | function isRegExp(re) { 3877 | return isObject(re) && objectToString(re) === '[object RegExp]'; 3878 | } 3879 | 3880 | exports.isRegExp = isRegExp; 3881 | 3882 | function isNullOrUndefined(arg) { 3883 | return arg == null; 3884 | } 3885 | 3886 | exports.isNullOrUndefined = isNullOrUndefined; 3887 | 3888 | function isNull(arg) { 3889 | return arg === null; 3890 | } 3891 | exports.isNull = isNull; 3892 | 3893 | function isArguments(object) { 3894 | return objectToString(object) === '[object Arguments]'; 3895 | } 3896 | 3897 | exports.isArguments = isArguments; 3898 | 3899 | exports.isFunction = function(arg) { 3900 | return typeof arg === 'function' || arg instanceof Function; 3901 | }; 3902 | 3903 | function isError(e) { 3904 | return (isObject(e) && objectToString(e) === '[object Error]') || (e instanceof Error); 3905 | } 3906 | exports.isError = isError; 3907 | 3908 | function isUndefined(arg) { 3909 | return arg === void 0; 3910 | } 3911 | 3912 | exports.isUndefined = isUndefined; 3913 | 3914 | var hasOwnProperty = Object.prototype.hasOwnProperty; 3915 | 3916 | exports.forOwn = function(obj, f, context) { 3917 | for(var prop in obj) { 3918 | if(hasOwnProperty.call(obj, prop)) { 3919 | f.call(context, obj[prop], prop); 3920 | } 3921 | } 3922 | }; 3923 | 3924 | var functionNameRE = /^\s*function\s*(\S*)\s*\(/; 3925 | 3926 | exports.functionName = function(f) { 3927 | if(f.name) { 3928 | return f.name; 3929 | } 3930 | var name = f.toString().match(functionNameRE)[1]; 3931 | return name; 3932 | }; 3933 | 3934 | var formatPropertyName = require('should-format').formatPropertyName; 3935 | 3936 | exports.formatProp = function(value) { 3937 | return formatPropertyName(String(value)); 3938 | }; 3939 | 3940 | exports.formatEqlResult = function(r, a, b, format) { 3941 | return ((r.path.length > 0 ? 'at ' + r.path.map(exports.formatProp).join(' -> ') : '') + 3942 | (r.a === a ? '' : ', A has ' + format(r.a)) + 3943 | (r.b === b ? '' : ' and B has ' + format(r.b)) + 3944 | (r.showReason ? ' because ' + r.reason: '')).trim(); 3945 | }; 3946 | }).call(this,require("buffer").Buffer) 3947 | },{"buffer":1,"should-format":26}],24:[function(require,module,exports){ 3948 | var getType = require('should-type'); 3949 | var hasOwnProperty = Object.prototype.hasOwnProperty; 3950 | 3951 | function makeResult(r, path, reason, a, b, showReason) { 3952 | var o = {result: r}; 3953 | if(!r) { 3954 | o.path = path; 3955 | o.reason = reason; 3956 | o.a = a; 3957 | o.b = b; 3958 | o.showReason = showReason; 3959 | } 3960 | return o; 3961 | } 3962 | 3963 | var EQUALS = makeResult(true); 3964 | 3965 | function format(msg) { 3966 | var args = arguments; 3967 | for(var i = 1, l = args.length; i < l; i++) { 3968 | msg = msg.replace(/%s/, args[i]); 3969 | } 3970 | return msg; 3971 | } 3972 | 3973 | var REASON = { 3974 | PLUS_0_AND_MINUS_0: '+0 is not equal to -0', 3975 | DIFFERENT_TYPES: 'A has type %s and B has type %s', 3976 | NAN_NUMBER: 'NaN is not equal to any number', 3977 | EQUALITY: 'A is not equal to B', 3978 | EQUALITY_PROTOTYPE: 'A and B have different prototypes', 3979 | WRAPPED_VALUE: 'A wrapped value is not equal to B wrapped value', 3980 | FUNCTION_SOURCES: 'function A is not equal to B by source code value (via .toString call)', 3981 | MISSING_KEY: '%s does not have key %s', 3982 | CIRCULAR_VALUES: 'A has circular reference that was visited not in the same time as B' 3983 | }; 3984 | 3985 | var LENGTH = ['length']; 3986 | var NAME = ['name']; 3987 | var MESSAGE = ['message']; 3988 | var BYTE_LENGTH = ['byteLength']; 3989 | var PROTOTYPE = ['prototype']; 3990 | 3991 | function eq(a, b, opts, stackA, stackB, path) { 3992 | path = path || []; 3993 | opts = opts || { checkProtoEql: true }; 3994 | 3995 | // equal a and b exit early 3996 | if(a === b) { 3997 | // check for +0 !== -0; 3998 | return makeResult(a !== 0 || (1 / a == 1 / b), path, REASON.PLUS_0_AND_MINUS_0, a, b); 3999 | } 4000 | 4001 | var l, isValueEqual; 4002 | 4003 | var typeA = getType(a), 4004 | typeB = getType(b); 4005 | 4006 | // if objects has different types they are not equals 4007 | if(typeA !== typeB) return makeResult(false, path, format(REASON.DIFFERENT_TYPES, typeA, typeB), a, b); 4008 | 4009 | switch(typeA) { 4010 | case 'number': 4011 | return (a !== a) ? makeResult(b !== b, path, REASON.NAN_NUMBER, a, b) 4012 | // but treat `+0` vs. `-0` as not equal 4013 | : (a === 0 ? makeResult((1 / a === 1 / b), path, REASON.PLUS_0_AND_MINUS_0, a, b) : makeResult(a === b, path, REASON.EQUALITY, a, b)); 4014 | 4015 | case 'regexp': 4016 | isValueEqual = a.source === b.source && 4017 | a.global === b.global && 4018 | a.multiline === b.multiline && 4019 | a.lastIndex === b.lastIndex && 4020 | a.ignoreCase === b.ignoreCase; 4021 | if(isValueEqual) break; 4022 | return makeResult(false, path, REASON.EQUALITY, a, b); 4023 | 4024 | case 'boolean': 4025 | case 'string': 4026 | return makeResult(a === b, path, REASON.EQUALITY, a, b); 4027 | 4028 | case 'date': 4029 | isValueEqual = +a === +b; 4030 | if(isValueEqual) break; 4031 | return makeResult(false, path, REASON.EQUALITY, a, b); 4032 | 4033 | case 'object-number': 4034 | case 'object-boolean': 4035 | case 'object-string': 4036 | isValueEqual = a.valueOf() === b.valueOf(); 4037 | if(isValueEqual) break; 4038 | return makeResult(false, path, REASON.WRAPPED_VALUE, a.valueOf(), b.valueOf()); 4039 | 4040 | case 'buffer': 4041 | if(a.length !== b.length) return makeResult(false, path.concat(LENGTH), REASON.EQUALITY, a.length, b.length); 4042 | 4043 | l = a.length; 4044 | while(l--) if(a[l] !== b[l]) return makeResult(false, path.concat([l]), REASON.EQUALITY, a[l], b[l]); 4045 | 4046 | return EQUALS; 4047 | 4048 | case 'error': 4049 | //only check not enumerable properties, and check arrays later 4050 | if(a.name !== b.name) return makeResult(false, path.concat(NAME), REASON.EQUALITY, a.name, b.name); 4051 | if(a.message !== b.message) return makeResult(false, path.concat(MESSAGE), REASON.EQUALITY, a.message, b.message); 4052 | 4053 | break; 4054 | 4055 | //XXX check more in browsers 4056 | case 'array-buffer': 4057 | if(a.byteLength !== b.byteLength) return makeResult(false, path.concat(BYTE_LENGTH), REASON.EQUALITY, a.byteLength, b.byteLength); 4058 | 4059 | l = a.byteLength; 4060 | while(l--) if(a[l] !== b[l]) return makeResult(false, path.concat([l]), REASON.EQUALITY, a[l], b[l]); 4061 | 4062 | return EQUALS; 4063 | 4064 | } 4065 | 4066 | // compare deep objects and arrays 4067 | // stacks contain references only 4068 | stackA || (stackA = []); 4069 | stackB || (stackB = []); 4070 | 4071 | l = stackA.length; 4072 | while(l--) { 4073 | if(stackA[l] == a) { 4074 | return makeResult(stackB[l] == b, path, REASON.CIRCULAR_VALUES, a, b); 4075 | } 4076 | } 4077 | 4078 | // add `a` and `b` to the stack of traversed objects 4079 | stackA.push(a); 4080 | stackB.push(b); 4081 | 4082 | var hasProperty, 4083 | keysComparison, 4084 | key; 4085 | 4086 | if(typeA === 'array' || typeA === 'arguments') { 4087 | if(a.length !== b.length) return makeResult(false, path.concat(LENGTH), REASON.EQUALITY, a.length, b.length); 4088 | } 4089 | 4090 | if(typeB === 'function') { 4091 | var fA = a.toString(), fB = b.toString(); 4092 | if(fA !== fB) return makeResult(false, path, REASON.FUNCTION_SOURCES, fA, fB); 4093 | } 4094 | 4095 | for(key in b) { 4096 | if(hasOwnProperty.call(b, key)) { 4097 | hasProperty = hasOwnProperty.call(a, key); 4098 | if(!hasProperty) return makeResult(false, path, format(REASON.MISSING_KEY, 'A', key), a, b); 4099 | 4100 | keysComparison = eq(a[key], b[key], opts, stackA, stackB, path.concat([key])); 4101 | if(!keysComparison.result) return keysComparison; 4102 | } 4103 | } 4104 | 4105 | // ensure both objects have the same number of properties 4106 | for(key in a) { 4107 | if(hasOwnProperty.call(a, key)) { 4108 | hasProperty = hasOwnProperty.call(b, key); 4109 | if(!hasProperty) return makeResult(false, path, format(REASON.MISSING_KEY, 'B', key), a, b); 4110 | } 4111 | } 4112 | 4113 | var prototypesEquals = false, canComparePrototypes = false; 4114 | 4115 | if(opts.checkProtoEql) { 4116 | 4117 | if(Object.getPrototypeOf) { 4118 | prototypesEquals = Object.getPrototypeOf(a) === Object.getPrototypeOf(b); 4119 | canComparePrototypes = true; 4120 | } else if(a.__proto__ && b.__proto__) { 4121 | prototypesEquals = a.__proto__ === b.__proto__; 4122 | canComparePrototypes = true; 4123 | } 4124 | 4125 | if(canComparePrototypes && !prototypesEquals) { 4126 | return makeResult(false, path, REASON.EQUALITY_PROTOTYPE, a, b, true); 4127 | } 4128 | } 4129 | 4130 | stackA.pop(); 4131 | stackB.pop(); 4132 | 4133 | if(typeB === 'function') { 4134 | keysComparison = eq(a.prototype, b.prototype, opts, stackA, stackB, path.concat(PROTOTYPE)); 4135 | if(!keysComparison.result) return keysComparison; 4136 | } 4137 | 4138 | return EQUALS; 4139 | } 4140 | 4141 | 4142 | module.exports = eq; 4143 | 4144 | },{"should-type":25}],25:[function(require,module,exports){ 4145 | (function (Buffer){ 4146 | var toString = Object.prototype.toString; 4147 | 4148 | var types = { 4149 | NUMBER: 'number', 4150 | UNDEFINED: 'undefined', 4151 | STRING: 'string', 4152 | BOOLEAN: 'boolean', 4153 | OBJECT: 'object', 4154 | FUNCTION: 'function', 4155 | NULL: 'null', 4156 | ARRAY: 'array', 4157 | REGEXP: 'regexp', 4158 | DATE: 'date', 4159 | ERROR: 'error', 4160 | ARGUMENTS: 'arguments', 4161 | SYMBOL: 'symbol', 4162 | ARRAY_BUFFER: 'array-buffer', 4163 | TYPED_ARRAY: 'typed-array', 4164 | DATA_VIEW: 'data-view', 4165 | MAP: 'map', 4166 | SET: 'set', 4167 | WEAK_SET: 'weak-set', 4168 | WEAK_MAP: 'weak-map', 4169 | PROMISE: 'promise', 4170 | 4171 | WRAPPER_NUMBER: 'object-number', 4172 | WRAPPER_BOOLEAN: 'object-boolean', 4173 | WRAPPER_STRING: 'object-string', 4174 | 4175 | // node buffer 4176 | BUFFER: 'buffer', 4177 | 4178 | // dom html element 4179 | HTML_ELEMENT: 'html-element', 4180 | HTML_ELEMENT_TEXT: 'html-element-text', 4181 | DOCUMENT: 'document', 4182 | WINDOW: 'window', 4183 | FILE: 'file', 4184 | FILE_LIST: 'file-list', 4185 | BLOB: 'blob', 4186 | 4187 | XHR: 'xhr' 4188 | }; 4189 | 4190 | module.exports = function getType(instance) { 4191 | var type = typeof instance; 4192 | 4193 | switch(type) { 4194 | case types.NUMBER: 4195 | return types.NUMBER; 4196 | case types.UNDEFINED: 4197 | return types.UNDEFINED; 4198 | case types.STRING: 4199 | return types.STRING; 4200 | case types.BOOLEAN: 4201 | return types.BOOLEAN; 4202 | case types.FUNCTION: 4203 | return types.FUNCTION; 4204 | case types.SYMBOL: 4205 | return types.SYMBOL; 4206 | case types.OBJECT: 4207 | if(instance === null) return types.NULL; 4208 | 4209 | var clazz = toString.call(instance); 4210 | 4211 | switch(clazz) { 4212 | case '[object String]': 4213 | return types.WRAPPER_STRING; 4214 | case '[object Boolean]': 4215 | return types.WRAPPER_BOOLEAN; 4216 | case '[object Number]': 4217 | return types.WRAPPER_NUMBER; 4218 | case '[object Array]': 4219 | return types.ARRAY; 4220 | case '[object RegExp]': 4221 | return types.REGEXP; 4222 | case '[object Error]': 4223 | return types.ERROR; 4224 | case '[object Date]': 4225 | return types.DATE; 4226 | case '[object Arguments]': 4227 | return types.ARGUMENTS; 4228 | case '[object Math]': 4229 | return types.OBJECT; 4230 | case '[object JSON]': 4231 | return types.OBJECT; 4232 | case '[object ArrayBuffer]': 4233 | return types.ARRAY_BUFFER; 4234 | case '[object Int8Array]': 4235 | return types.TYPED_ARRAY; 4236 | case '[object Uint8Array]': 4237 | return types.TYPED_ARRAY; 4238 | case '[object Uint8ClampedArray]': 4239 | return types.TYPED_ARRAY; 4240 | case '[object Int16Array]': 4241 | return types.TYPED_ARRAY; 4242 | case '[object Uint16Array]': 4243 | return types.TYPED_ARRAY; 4244 | case '[object Int32Array]': 4245 | return types.TYPED_ARRAY; 4246 | case '[object Uint32Array]': 4247 | return types.TYPED_ARRAY; 4248 | case '[object Float32Array]': 4249 | return types.TYPED_ARRAY; 4250 | case '[object Float64Array]': 4251 | return types.TYPED_ARRAY; 4252 | case '[object DataView]': 4253 | return types.DATA_VIEW; 4254 | case '[object Map]': 4255 | return types.MAP; 4256 | case '[object WeakMap]': 4257 | return types.WEAK_MAP; 4258 | case '[object Set]': 4259 | return types.SET; 4260 | case '[object WeakSet]': 4261 | return types.WEAK_SET; 4262 | case '[object Promise]': 4263 | return types.PROMISE; 4264 | case '[object Window]': 4265 | return types.WINDOW; 4266 | case '[object HTMLDocument]': 4267 | return types.DOCUMENT; 4268 | case '[object Blob]': 4269 | return types.BLOB; 4270 | case '[object File]': 4271 | return types.FILE; 4272 | case '[object FileList]': 4273 | return types.FILE_LIST; 4274 | case '[object XMLHttpRequest]': 4275 | return types.XHR; 4276 | case '[object Text]': 4277 | return types.HTML_ELEMENT_TEXT; 4278 | default: 4279 | if((typeof Promise === types.FUNCTION && instance instanceof Promise) || (getType(instance.then) === types.FUNCTION && instance.then.length >= 2)) { 4280 | return types.PROMISE; 4281 | } 4282 | 4283 | if(typeof Buffer !== 'undefined' && instance instanceof Buffer) { 4284 | return types.BUFFER; 4285 | } 4286 | 4287 | if(/^\[object HTML\w+Element\]$/.test(clazz)) { 4288 | return types.HTML_ELEMENT; 4289 | } 4290 | 4291 | if(clazz === '[object Object]') { 4292 | return types.OBJECT; 4293 | } 4294 | } 4295 | } 4296 | }; 4297 | 4298 | Object.keys(types).forEach(function(typeName) { 4299 | module.exports[typeName] = types[typeName]; 4300 | }); 4301 | 4302 | }).call(this,require("buffer").Buffer) 4303 | },{"buffer":1}],26:[function(require,module,exports){ 4304 | var getType = require('should-type'); 4305 | 4306 | function genKeysFunc(f) { 4307 | return function(value) { 4308 | var k = f(value); 4309 | k.sort(); 4310 | return k; 4311 | } 4312 | } 4313 | 4314 | //XXX add ability to only inspect some paths 4315 | var format = function(value, opts) { 4316 | opts = opts || {}; 4317 | 4318 | if(!('seen' in opts)) opts.seen = []; 4319 | opts.keys = genKeysFunc('keys' in opts && opts.keys === false ? Object.getOwnPropertyNames : Object.keys); 4320 | 4321 | if(!('maxLineLength' in opts)) opts.maxLineLength = 60; 4322 | if(!('propSep' in opts)) opts.propSep = ','; 4323 | 4324 | var type = getType(value); 4325 | return (format.formats[type] || format.formats['object'])(value, opts); 4326 | }; 4327 | 4328 | module.exports = format; 4329 | 4330 | format.formats = {}; 4331 | 4332 | function add(t, f) { 4333 | format.formats[t] = f; 4334 | } 4335 | 4336 | [ 'undefined', 'boolean', 'null'].forEach(function(name) { 4337 | add(name, String); 4338 | }); 4339 | 4340 | ['number', 'boolean'].forEach(function(name) { 4341 | var capName = name.substring(0, 1).toUpperCase() + name.substring(1); 4342 | add('object-' + name, formatObjectWithPrefix(function(value) { 4343 | return '[' + capName + ': ' + format(value.valueOf()) + ']'; 4344 | })); 4345 | }); 4346 | 4347 | add('object-string', function(value, opts) { 4348 | var realValue = value.valueOf(); 4349 | var prefix = '[String: ' + format(realValue) + ']'; 4350 | var props = opts.keys(value); 4351 | props = props.filter(function(p) { 4352 | return !(p.match(/\d+/) && parseInt(p, 10) < realValue.length); 4353 | }); 4354 | 4355 | if(props.length == 0) return prefix; 4356 | else return formatObject(value, opts, prefix, props); 4357 | }); 4358 | 4359 | add('regexp', formatObjectWithPrefix(String)); 4360 | 4361 | add('number', function(value) { 4362 | if(value === 0 && 1 / value < 0) return '-0'; 4363 | return String(value); 4364 | }); 4365 | 4366 | add('string', function(value) { 4367 | return '\'' + JSON.stringify(value).replace(/^"|"$/g, '') 4368 | .replace(/'/g, "\\'") 4369 | .replace(/\\"/g, '"') + '\''; 4370 | }); 4371 | 4372 | add('object', formatObject); 4373 | 4374 | add('array', function(value, opts) { 4375 | var keys = opts.keys(value); 4376 | var len = 0; 4377 | 4378 | opts.seen.push(value); 4379 | 4380 | var props = keys.map(function(prop) { 4381 | var desc; 4382 | try { 4383 | desc = Object.getOwnPropertyDescriptor(value, prop) || {value: value[prop]}; 4384 | } catch(e) { 4385 | desc = {value: e}; 4386 | } 4387 | 4388 | var f; 4389 | if(prop.match(/\d+/)) { 4390 | f = format(desc.value, opts); 4391 | } else { 4392 | f = formatProperty(desc.value, opts, prop) 4393 | } 4394 | len += f.length; 4395 | return f; 4396 | }); 4397 | 4398 | opts.seen.pop(); 4399 | 4400 | if(props.length === 0) return '[]'; 4401 | 4402 | if(len <= opts.maxLineLength) { 4403 | return '[ ' + props.join(opts.propSep + ' ') + ' ]'; 4404 | } else { 4405 | return '[' + '\n' + props.map(addSpaces).join(opts.propSep + '\n') + '\n' + ']'; 4406 | } 4407 | }); 4408 | 4409 | function addSpaces(v) { 4410 | return ' ' + v; 4411 | } 4412 | 4413 | function formatObject(value, opts, prefix, props) { 4414 | props = props || opts.keys(value); 4415 | 4416 | var len = 0; 4417 | 4418 | opts.seen.push(value); 4419 | props = props.map(function(prop) { 4420 | var f = formatProperty(value, opts, prop); 4421 | len += f.length; 4422 | return f; 4423 | }); 4424 | opts.seen.pop(); 4425 | 4426 | if(props.length === 0) return '{}'; 4427 | 4428 | if(len <= opts.maxLineLength) { 4429 | return '{ ' + (prefix ? prefix + ' ' : '') + props.join(opts.propSep + ' ') + ' }'; 4430 | } else { 4431 | return '{' + '\n' + (prefix ? prefix + '\n' : '') + props.map(addSpaces).join(opts.propSep + '\n') + '\n' + '}'; 4432 | } 4433 | } 4434 | 4435 | format.formatPropertyName = function(name, opts) { 4436 | return name.match(/^[a-zA-Z_$][a-zA-Z_$0-9]*$/) ? name : format(name, opts) 4437 | }; 4438 | 4439 | 4440 | function formatProperty(value, opts, prop) { 4441 | var desc; 4442 | try { 4443 | desc = Object.getOwnPropertyDescriptor(value, prop) || {value: value[prop]}; 4444 | } catch(e) { 4445 | desc = {value: e}; 4446 | } 4447 | 4448 | var propName = format.formatPropertyName(prop, opts); 4449 | 4450 | var propValue = desc.get && desc.set ? 4451 | '[Getter/Setter]' : desc.get ? 4452 | '[Getter]' : desc.set ? 4453 | '[Setter]' : opts.seen.indexOf(desc.value) >= 0 ? 4454 | '[Circular]' : 4455 | format(desc.value, opts); 4456 | 4457 | return propName + ': ' + propValue; 4458 | } 4459 | 4460 | 4461 | function pad2Zero(n) { 4462 | return n < 10 ? '0' + n : '' + n; 4463 | } 4464 | 4465 | function pad3Zero(n) { 4466 | return n < 100 ? '0' + pad2Zero(n) : '' + n; 4467 | } 4468 | 4469 | function formatDate(value) { 4470 | var to = value.getTimezoneOffset(); 4471 | var absTo = Math.abs(to); 4472 | var hours = Math.floor(absTo / 60); 4473 | var minutes = absTo - hours * 60; 4474 | var tzFormat = 'GMT' + (to < 0 ? '+' : '-') + pad2Zero(hours) + pad2Zero(minutes); 4475 | return value.toLocaleDateString() + ' ' + value.toLocaleTimeString() + '.' + pad3Zero(value.getMilliseconds()) + ' ' + tzFormat; 4476 | } 4477 | 4478 | function formatObjectWithPrefix(f) { 4479 | return function(value, opts) { 4480 | var prefix = f(value); 4481 | var props = opts.keys(value); 4482 | if(props.length == 0) return prefix; 4483 | else return formatObject(value, opts, prefix, props); 4484 | } 4485 | } 4486 | 4487 | add('date', formatObjectWithPrefix(formatDate)); 4488 | 4489 | var functionNameRE = /^\s*function\s*(\S*)\s*\(/; 4490 | 4491 | function functionName(f) { 4492 | if(f.name) { 4493 | return f.name; 4494 | } 4495 | var name = f.toString().match(functionNameRE)[1]; 4496 | return name; 4497 | } 4498 | 4499 | add('function', formatObjectWithPrefix(function(value) { 4500 | var name = functionName(value); 4501 | return '[Function' + (name ? ': ' + name : '') + ']'; 4502 | })); 4503 | 4504 | add('error', formatObjectWithPrefix(function(value) { 4505 | var name = value.name; 4506 | var message = value.message; 4507 | return '[' + name + (message ? ': ' + message : '') + ']'; 4508 | })); 4509 | 4510 | function generateFunctionForIndexedArray(lengthProp, name) { 4511 | return function(value) { 4512 | var str = ''; 4513 | var max = 50; 4514 | var len = value[lengthProp]; 4515 | if(len > 0) { 4516 | for(var i = 0; i < max && i < len; i++) { 4517 | var b = value[i] || 0; 4518 | str += ' ' + pad2Zero(b.toString(16)); 4519 | } 4520 | if(len > max) 4521 | str += ' ... '; 4522 | } 4523 | return '[' + (value.constructor.name || name) + (str ? ':' + str : '') + ']'; 4524 | } 4525 | } 4526 | 4527 | add('buffer', generateFunctionForIndexedArray('length', 'Buffer')); 4528 | 4529 | add('array-buffer', generateFunctionForIndexedArray('byteLength')); 4530 | 4531 | add('typed-array', generateFunctionForIndexedArray('byteLength')); 4532 | 4533 | add('promise', function(value) { 4534 | return '[Promise]'; 4535 | }); 4536 | 4537 | add('xhr', function(value) { 4538 | return '[XMLHttpRequest]'; 4539 | }); 4540 | 4541 | add('html-element', function(value) { 4542 | return value.outerHTML; 4543 | }); 4544 | 4545 | add('html-element-text', function(value) { 4546 | return value.nodeValue; 4547 | }); 4548 | 4549 | add('document', function(value) { 4550 | return value.documentElement.outerHTML; 4551 | }); 4552 | 4553 | add('window', function(value) { 4554 | return '[Window]'; 4555 | }); 4556 | },{"should-type":27}],27:[function(require,module,exports){ 4557 | arguments[4][25][0].apply(exports,arguments) 4558 | },{"buffer":1,"dup":25}],28:[function(require,module,exports){ 4559 | var should = require('should'); 4560 | var return42 = require('../my_code'); 4561 | 4562 | it('should work with build script', function() { 4563 | return42.should.be.a.Function; 4564 | }); 4565 | },{"../my_code":29,"should":22}],29:[function(require,module,exports){ 4566 | function return42(fail) { 4567 | if(fail) throw new Error('boom'); 4568 | 4569 | return 42; 4570 | } 4571 | 4572 | if(typeof module != 'undefined') { 4573 | module.exports = return42; 4574 | } 4575 | 4576 | },{}]},{},[28]); 4577 | -------------------------------------------------------------------------------- /browserify-mocha-should/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mocha 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /browserify-mocha-should/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 50px; 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 | -------------------------------------------------------------------------------- /browserify-mocha-should/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "browserify-mocha-should", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "browserify tests.js > _tests.js" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "browserify": "^8.1.1", 13 | "mocha": "^2.1.0", 14 | "should": "^4.6.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /browserify-mocha-should/tests.js: -------------------------------------------------------------------------------- 1 | var should = require('should'); 2 | var return42 = require('../my_code'); 3 | 4 | it('should work with build script', function() { 5 | return42.should.be.a.Function; 6 | }); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 |
mocha, should
10 |
Link
11 | 12 |
mocha, should, requirejs
13 |
Link
14 | 15 |
mocha, should, browserify (you should build tests first)
16 |
Link
17 |
18 | 19 | -------------------------------------------------------------------------------- /karma-browserify-mocha-should/karma.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function(config) { 2 | config.set({ 3 | 4 | frameworks: ['mocha', 'browserify'], 5 | 6 | files: [ 7 | './test.js' 8 | ], 9 | 10 | preprocessors: { 11 | './test.js': 'browserify' 12 | }, 13 | 14 | reporters: ['progress'], 15 | 16 | port: 9876, 17 | 18 | colors: true, 19 | 20 | logLevel: config.LOG_INFO, 21 | 22 | autoWatch: true, 23 | 24 | browsers: ['Chrome'], 25 | 26 | singleRun: false 27 | }); 28 | }; 29 | -------------------------------------------------------------------------------- /karma-browserify-mocha-should/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "karma-browserify-mocha-should", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "./node_modules/karma/bin/karma start" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "karma": "^0.12.31", 13 | "karma-browserify": "^2.0.0", 14 | "karma-chrome-launcher": "^0.1.7", 15 | "karma-mocha": "^0.1.10", 16 | "mocha": "^2.1.0", 17 | "should": "^4.6.1" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /karma-browserify-mocha-should/test.js: -------------------------------------------------------------------------------- 1 | var should = require('should'); 2 | var return42 = require('../my_code'); 3 | 4 | it('should work', function() { 5 | return42.should.be.a.Function; 6 | }); -------------------------------------------------------------------------------- /karma-requirejs-mocha-should/karma.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function(config) { 2 | config.set({ 3 | 4 | frameworks: ['requirejs', 'mocha'], 5 | 6 | files: [ 7 | {pattern: './lib/**/*.js', included: false}, 8 | {pattern: './test/**/*.js', included: false}, 9 | 10 | {pattern: './node_modules/should/should.js', included: false}, 11 | './main.js' 12 | ], 13 | 14 | reporters: ['progress'], 15 | 16 | port: 9876, 17 | 18 | colors: true, 19 | 20 | logLevel: config.LOG_DEBUG, 21 | 22 | autoWatch: true, 23 | 24 | browsers: ['Chrome'], 25 | 26 | singleRun: false 27 | }); 28 | }; 29 | -------------------------------------------------------------------------------- /karma-requirejs-mocha-should/lib/my_code.js: -------------------------------------------------------------------------------- 1 | function return42(fail) { 2 | if(fail) throw new Error('boom'); 3 | 4 | return 42; 5 | } 6 | 7 | if(typeof module != 'undefined') { 8 | module.exports = return42; 9 | } 10 | -------------------------------------------------------------------------------- /karma-requirejs-mocha-should/main.js: -------------------------------------------------------------------------------- 1 | var tests = []; 2 | for (var file in window.__karma__.files) { 3 | if (window.__karma__.files.hasOwnProperty(file)) { 4 | if (/test\.js/.test(file)) { 5 | tests.push(file); 6 | } 7 | } 8 | } 9 | 10 | requirejs.config({ 11 | // Karma serves files from '/base' 12 | baseUrl: '/base/lib', 13 | 14 | paths: { 15 | 'should': '../node_modules/should/should', 16 | 'my_code': './my_code' 17 | }, 18 | 19 | shim: { 20 | 'my_code': { 21 | exports: 'return42' 22 | } 23 | }, 24 | 25 | // ask Require.js to load these files (all our tests) 26 | deps: tests, 27 | 28 | // start test run, once Require.js is done 29 | callback: window.__karma__.start 30 | }); -------------------------------------------------------------------------------- /karma-requirejs-mocha-should/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "karma-requirejs-mocha-should", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "./node_modules/karma/bin/karma start" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "karma": "^0.12.31", 13 | "karma-chrome-launcher": "^0.1.7", 14 | "karma-mocha": "^0.1.10", 15 | "karma-requirejs": "^0.2.2", 16 | "mocha": "^2.1.0", 17 | "requirejs": "^2.1.15", 18 | "should": "^4.6.1" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /karma-requirejs-mocha-should/test/test.js: -------------------------------------------------------------------------------- 1 | 2 | define(['should', 'my_code'], function() { 3 | it('should work', function() { 4 | return42.should.be.a.Function; 5 | }); 6 | 7 | it('should work really', function() { 8 | return42.should.not.throw(); 9 | }); 10 | }); -------------------------------------------------------------------------------- /my_code.js: -------------------------------------------------------------------------------- 1 | function return42(fail) { 2 | if(fail) throw new Error('boom'); 3 | 4 | return 42; 5 | } 6 | 7 | if(typeof module != 'undefined') { 8 | module.exports = return42; 9 | } 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examples", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "my_code.js", 6 | "scripts": { 7 | "browser": "http-server -p 8080" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "http-server": "^0.7.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /simple-mocha-should-requirejs/README.md: -------------------------------------------------------------------------------- 1 | In this example we load should.js and test function with requirejs. 2 | 3 | You can inspect index.html to see what is loaded first. 4 | 5 | Also run 6 | ``` 7 | npm i 8 | ``` 9 | To have all dependencies. -------------------------------------------------------------------------------- /simple-mocha-should-requirejs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mocha 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /simple-mocha-should-requirejs/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 50px; 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 | -------------------------------------------------------------------------------- /simple-mocha-should-requirejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple-mocha-should-requirejs", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "browser": "http-server" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "http-server": "^0.7.4", 13 | "mocha": "^2.1.0", 14 | "requirejs": "^2.1.15", 15 | "should": "^4.6.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /simple-mocha-should-requirejs/tests-main.js: -------------------------------------------------------------------------------- 1 | requirejs.config({ 2 | shim: { 3 | my_code: { 4 | exports: 'return42' 5 | } 6 | }, 7 | paths: { 8 | my_code: '../my_code', 9 | should: './node_modules/should/should' 10 | } 11 | }); 12 | 13 | requirejs(['./tests'], function() { 14 | mocha.run(); 15 | }); -------------------------------------------------------------------------------- /simple-mocha-should-requirejs/tests.js: -------------------------------------------------------------------------------- 1 | define(['my_code', 'should'], function(return42, should){ 2 | it('should work even with requirejs', function() { 3 | return42.should.be.a.Function; 4 | }); 5 | }); -------------------------------------------------------------------------------- /simple-mocha-should/README.md: -------------------------------------------------------------------------------- 1 | In this example mocha and should.js used as is, without any additional tools. 2 | 3 | To make it work, do in this folder: 4 | ``` 5 | npm i 6 | ``` 7 | Open in browser `index.html`. You will see executed test. This test now in `tests.js`. 8 | 9 | Mocha will create such empty files with command `mocha init .`. 10 | 11 | Should.js added to `index.html` before `tests.js`. -------------------------------------------------------------------------------- /simple-mocha-should/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mocha 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /simple-mocha-should/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 50px; 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 | -------------------------------------------------------------------------------- /simple-mocha-should/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple", 3 | "version": "1.0.0", 4 | "description": "Simple example", 5 | "main": "index.js", 6 | 7 | "author": "", 8 | "license": "ISC", 9 | "devDependencies": { 10 | "mocha": "^2.1.0", 11 | "should": "^4.6.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /simple-mocha-should/tests.js: -------------------------------------------------------------------------------- 1 | it('should work', function() { 2 | return42().should.be.Number.and.equal(42); 3 | 4 | return42.should.not.throw(); 5 | }); -------------------------------------------------------------------------------- /zuul-mocha-should/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zuul-mocha-should", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "browser": "zuul --local 8090 --ui mocha-bdd -- tests.js" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "should": "^4.6.0", 13 | "zuul": "^1.16.4" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /zuul-mocha-should/tests.js: -------------------------------------------------------------------------------- 1 | var should = require('should'); 2 | var return42 = require('../my_code'); 3 | 4 | it('should work with build script', function() { 5 | return42.should.be.a.Function; 6 | }); --------------------------------------------------------------------------------