UNPKG

93 kBJavaScriptView Raw
1"use strict";
2
3function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
4
5function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
6
7function _possibleConstructorReturn(self, call) { if (call && (_typeof2(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
8
9function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
11function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
12
13function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
14
15function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
17function _templateObject17() {
18 var data = _taggedTemplateLiteral(["'", "' is greater than ", ""]);
19
20 _templateObject17 = function _templateObject17() {
21 return data;
22 };
23
24 return data;
25}
26
27function _templateObject16() {
28 var data = _taggedTemplateLiteral(["'", "' is less than ", ""]);
29
30 _templateObject16 = function _templateObject16() {
31 return data;
32 };
33
34 return data;
35}
36
37function _templateObject15() {
38 var data = _taggedTemplateLiteral(["'", "' is not less than ", ""]);
39
40 _templateObject15 = function _templateObject15() {
41 return data;
42 };
43
44 return data;
45}
46
47function _templateObject14() {
48 var data = _taggedTemplateLiteral(["'", "' is not greater than ", ""]);
49
50 _templateObject14 = function _templateObject14() {
51 return data;
52 };
53
54 return data;
55}
56
57function _templateObject13() {
58 var data = _taggedTemplateLiteral(["'", "' is not of type '", "'"]);
59
60 _templateObject13 = function _templateObject13() {
61 return data;
62 };
63
64 return data;
65}
66
67function _templateObject12() {
68 var data = _taggedTemplateLiteral(["'", "' does not resolve to '", "'"]);
69
70 _templateObject12 = function _templateObject12() {
71 return data;
72 };
73
74 return data;
75}
76
77function _templateObject11() {
78 var data = _taggedTemplateLiteral(["", " is not a promise"]);
79
80 _templateObject11 = function _templateObject11() {
81 return data;
82 };
83
84 return data;
85}
86
87function _templateObject10() {
88 var data = _taggedTemplateLiteral(["", " does not exist in ", ""]);
89
90 _templateObject10 = function _templateObject10() {
91 return data;
92 };
93
94 return data;
95}
96
97function _templateObject9() {
98 var data = _taggedTemplateLiteral(["", " does not have property '", "'"]);
99
100 _templateObject9 = function _templateObject9() {
101 return data;
102 };
103
104 return data;
105}
106
107function _templateObject8() {
108 var data = _taggedTemplateLiteral(["", " is not false"]);
109
110 _templateObject8 = function _templateObject8() {
111 return data;
112 };
113
114 return data;
115}
116
117function _templateObject7() {
118 var data = _taggedTemplateLiteral(["", " is not true"]);
119
120 _templateObject7 = function _templateObject7() {
121 return data;
122 };
123
124 return data;
125}
126
127function _templateObject6() {
128 var data = _taggedTemplateLiteral(["", " does not contain ", ""]);
129
130 _templateObject6 = function _templateObject6() {
131 return data;
132 };
133
134 return data;
135}
136
137function _templateObject5() {
138 var data = _taggedTemplateLiteral(["", " is not deeply equal to ", ""]);
139
140 _templateObject5 = function _templateObject5() {
141 return data;
142 };
143
144 return data;
145}
146
147function _templateObject4() {
148 var data = _taggedTemplateLiteral(["", " is not equal to ", ""]);
149
150 _templateObject4 = function _templateObject4() {
151 return data;
152 };
153
154 return data;
155}
156
157function _templateObject3() {
158 var data = _taggedTemplateLiteral(["", " doesn't have length ", ""]);
159
160 _templateObject3 = function _templateObject3() {
161 return data;
162 };
163
164 return data;
165}
166
167function _templateObject2() {
168 var data = _taggedTemplateLiteral(["", " is not an object"]);
169
170 _templateObject2 = function _templateObject2() {
171 return data;
172 };
173
174 return data;
175}
176
177function _templateObject() {
178 var data = _taggedTemplateLiteral(["", " is not an array"]);
179
180 _templateObject = function _templateObject() {
181 return data;
182 };
183
184 return data;
185}
186
187function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
188
189function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }
190
191function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
192
193function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
194
195function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
196
197function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
198
199function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
200
201function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty2(target, key, source[key]); }); } return target; }
202
203function _defineProperty2(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
204
205function _toConsumableArray2(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
206
207function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
208
209function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
210
211function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
212
213function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
214
215(function (f) {
216 if ((typeof exports === "undefined" ? "undefined" : _typeof2(exports)) === "object" && typeof module !== "undefined") {
217 module.exports = f();
218 } else if (typeof define === "function" && define.amd) {
219 define([], f);
220 } else {
221 var g;
222
223 if (typeof window !== "undefined") {
224 g = window;
225 } else if (typeof global !== "undefined") {
226 g = global;
227 } else if (typeof self !== "undefined") {
228 g = self;
229 } else {
230 g = this;
231 }
232
233 g.Gunner = f();
234 }
235})(function () {
236 var define, module, exports;
237 return function () {
238 function r(e, n, t) {
239 function o(i, f) {
240 if (!n[i]) {
241 if (!e[i]) {
242 var c = "function" == typeof require && require;
243 if (!f && c) return c(i, !0);
244 if (u) return u(i, !0);
245 var a = new Error("Cannot find module '" + i + "'");
246 throw a.code = "MODULE_NOT_FOUND", a;
247 }
248
249 var p = n[i] = {
250 exports: {}
251 };
252 e[i][0].call(p.exports, function (r) {
253 var n = e[i][1][r];
254 return o(n || r);
255 }, p, p.exports, r, e, n, t);
256 }
257
258 return n[i].exports;
259 }
260
261 for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
262 o(t[i]);
263 }
264
265 return o;
266 }
267
268 return r;
269 }()({
270 1: [function (require, module, exports) {
271 module.exports = require('./src/Gunner');
272 }, {
273 "./src/Gunner": 10
274 }],
275 2: [function (require, module, exports) {
276 (function (global) {
277 (function (f) {
278 if (_typeof2(exports) === "object" && typeof module !== "undefined") {
279 module.exports = f();
280 } else if (typeof define === "function" && define.amd) {
281 define([], f);
282 } else {
283 var g;
284
285 if (typeof window !== "undefined") {
286 g = window;
287 } else if (typeof global !== "undefined") {
288 g = global;
289 } else if (typeof self !== "undefined") {
290 g = self;
291 } else {
292 g = this;
293 }
294
295 g.isEq = f();
296 }
297 })(function () {
298 var define, module, exports;
299 return function () {
300 function e(t, n, r) {
301 function s(o, u) {
302 if (!n[o]) {
303 if (!t[o]) {
304 var a = typeof require == "function" && require;
305 if (!u && a) return a(o, !0);
306 if (i) return i(o, !0);
307 var f = new Error("Cannot find module '" + o + "'");
308 throw f.code = "MODULE_NOT_FOUND", f;
309 }
310
311 var l = n[o] = {
312 exports: {}
313 };
314 t[o][0].call(l.exports, function (e) {
315 var n = t[o][1][e];
316 return s(n ? n : e);
317 }, l, l.exports, e, t, n, r);
318 }
319
320 return n[o].exports;
321 }
322
323 var i = typeof require == "function" && require;
324
325 for (var o = 0; o < r.length; o++) {
326 s(r[o]);
327 }
328
329 return s;
330 }
331
332 return e;
333 }()({
334 1: [function (require, module, exports) {
335 "use strict";
336
337 var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
338 return _typeof2(obj);
339 } : function (obj) {
340 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
341 };
342
343 var isEq = function isEq(item1, item2, compareKeys) {
344 if (item1 === item2) return true;
345 if ((typeof item1 === "undefined" ? "undefined" : _typeof(item1)) !== (typeof item2 === "undefined" ? "undefined" : _typeof(item2))) return false;
346 if (Array.isArray(item1) && !Array.isArray(item2) || Array.isArray(item2) && !Array.isArray(item1)) return false;
347
348 if (typeof item1 === "number") {
349 if (isNaN(item1) && isNaN(item2)) return false;else return item1 === item2;
350 }
351
352 if (typeof item1 === "string" || typeof item1 === "boolean" || item1 === null || item1 === undefined) {
353 return item1 === item2;
354 }
355
356 if (item1 instanceof RegExp) return String(item1) === String(item2);
357 if ((typeof item1 === "undefined" ? "undefined" : _typeof(item1)) !== "object" || (typeof item2 === "undefined" ? "undefined" : _typeof(item2)) !== "object") return item1 === item2;
358 var item1Keys = Object.keys(item1);
359 var item2Keys = Object.keys(item2);
360
361 if (!compareKeys) {
362 compareKeys = item1Keys;
363
364 if (item1Keys.length !== item2Keys.length) {
365 return false;
366 }
367 }
368
369 if (!Array.isArray(compareKeys)) throw new Error("[isEq] third parameter should be an array of keys!");
370 if (compareKeys.length === 0) return true;
371
372 for (var KeyIndex in compareKeys) {
373 var Key = compareKeys[KeyIndex];
374
375 if (Array.isArray(item1[Key]) && Array.isArray(item2[Key])) {
376 Key = KeyIndex;
377 }
378
379 if (item1[Key] !== item2[Key]) {
380 if (_typeof(item1[Key] === "object") && _typeof(item2[Key] === "object") || Array.isArray(item1[Key]) && Array.isArray(item2[Key])) {
381 if (!isEq(item1[Key], item2[Key])) {
382 return false;
383 }
384 } else {
385 return false;
386 }
387 }
388 }
389
390 return true;
391 };
392
393 module.exports = isEq;
394 }, {}]
395 }, {}, [1])(1);
396 });
397 }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
398 }, {}],
399 3: [function (require, module, exports) {
400 (function (global) {
401 "use strict";
402
403 var _extends = Object.assign || function (target) {
404 for (var i = 1; i < arguments.length; i++) {
405 var source = arguments[i];
406
407 for (var key in source) {
408 if (Object.prototype.hasOwnProperty.call(source, key)) {
409 target[key] = source[key];
410 }
411 }
412 }
413
414 return target;
415 };
416
417 var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
418 return _typeof2(obj);
419 } : function (obj) {
420 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
421 };
422
423 function _defineProperty(obj, key, value) {
424 if (key in obj) {
425 Object.defineProperty(obj, key, {
426 value: value,
427 enumerable: true,
428 configurable: true,
429 writable: true
430 });
431 } else {
432 obj[key] = value;
433 }
434
435 return obj;
436 }
437
438 function _toConsumableArray(arr) {
439 if (Array.isArray(arr)) {
440 for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
441 arr2[i] = arr[i];
442 }
443
444 return arr2;
445 } else {
446 return Array.from(arr);
447 }
448 }
449
450 (function (f) {
451 if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined") {
452 module.exports = f();
453 } else if (typeof define === "function" && define.amd) {
454 define([], f);
455 } else {
456 var g;
457
458 if (typeof window !== "undefined") {
459 g = window;
460 } else if (typeof global !== "undefined") {
461 g = global;
462 } else if (typeof self !== "undefined") {
463 g = self;
464 } else {
465 g = this;
466 }
467
468 g.promiseObject = f();
469 }
470 })(function () {
471 var define, module, exports;
472 return function () {
473 function r(e, n, t) {
474 function o(i, f) {
475 if (!n[i]) {
476 if (!e[i]) {
477 var c = "function" == typeof require && require;
478 if (!f && c) return c(i, !0);
479 if (u) return u(i, !0);
480 var a = new Error("Cannot find module '" + i + "'");
481 throw a.code = "MODULE_NOT_FOUND", a;
482 }
483
484 var p = n[i] = {
485 exports: {}
486 };
487 e[i][0].call(p.exports, function (r) {
488 var n = e[i][1][r];
489 return o(n || r);
490 }, p, p.exports, r, e, n, t);
491 }
492
493 return n[i].exports;
494 }
495
496 for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
497 o(t[i]);
498 }
499
500 return o;
501 }
502
503 return r;
504 }()({
505 1: [function (require, module, exports) {
506 module.exports = require("../index.js");
507 }, {
508 "../index.js": 2
509 }],
510 2: [function (require, module, exports) {
511 "use strict";
512
513 var isObject = function isObject(x) {
514 return x && (typeof x === "undefined" ? "undefined" : _typeof(x)) === "object" && x.constructor === Object;
515 };
516
517 var $SELF = typeof Symbol !== "undefined" ? Symbol("SELF") : "[~~//-- SELF --//~~]";
518
519 var makeCyclic = function makeCyclic(object, query) {
520 var start = function start(obj) {
521 return Object.keys(obj).reduce(function (acc, key) {
522 var value = obj[key];
523
524 if (value === query) {
525 obj[key] = object;
526 return [].concat(_toConsumableArray(acc), [key]);
527 }
528
529 if (isObject(value)) return [].concat(_toConsumableArray(acc), _toConsumableArray(start(value, query)));else return acc;
530 }, []);
531 };
532
533 return start(object);
534 };
535
536 var PromiseMap = function PromiseMap(arr, functor) {
537 return Promise.all(arr.map(function (x) {
538 return Promise.resolve(x).then(functor);
539 }));
540 };
541
542 var ResolveObject = function ResolveObject(obj) {
543 return Promise.all(Object.keys(obj).map(function (key) {
544 return Promise.resolve(obj[key]).then(function (val) {
545 return obj[key] = val;
546 });
547 })).then(function (_) {
548 return obj;
549 });
550 };
551
552 var PromiseObject = function PromiseObject(object) {
553 var shouldReplaceSelf = false;
554
555 var ResolveDeepObject = function ResolveDeepObject(obj) {
556 return Promise.resolve(obj).then(function (resolvedObject) {
557 if (Array.isArray(resolvedObject)) {
558 return PromiseMap(resolvedObject, function (obj) {
559 return ResolveDeepObject(obj);
560 });
561 } else if (isObject(resolvedObject)) {
562 return ResolveObject(Object.keys(resolvedObject).reduce(function (acc, key) {
563 if (resolvedObject[key] === object) {
564 shouldReplaceSelf = true;
565 return _extends({}, acc, _defineProperty({}, key, $SELF));
566 }
567
568 return _extends({}, acc, _defineProperty({}, key, ResolveDeepObject(resolvedObject[key])));
569 }, {}));
570 }
571
572 return resolvedObject;
573 });
574 };
575
576 return ResolveDeepObject(object).then(function (obj) {
577 if (shouldReplaceSelf) makeCyclic(obj, $SELF);
578 return obj;
579 });
580 };
581
582 module.exports = PromiseObject;
583 }, {}]
584 }, {}, [1])(1);
585 });
586 }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
587 }, {
588 "../index.js": 4
589 }],
590 4: [function (require, module, exports) {
591 "use strict";
592 /**
593 * Returns true if x is an object, false otherwise.
594 * @param {any} x
595 * @returns {Boolean}
596 */
597
598 var isObject = function isObject(x) {
599 return x && _typeof2(x) === 'object' && x.constructor === Object;
600 };
601 /* A well known Symbol. */
602
603
604 var $SELF = typeof Symbol !== 'undefined' ? Symbol('SELF') : '[~~//-- SELF --//~~]';
605 /**
606 * Replaces values that match the query parameter
607 * with a reference to the parent parameter.
608 * @param {Object} object Object to make cyclic.
609 * @param {any} query Query to match against.
610 * @returns {Object}
611 */
612
613 var makeCyclic = function makeCyclic(object, query) {
614 var start = function start(obj) {
615 return Object.keys(obj).reduce(function (acc, key) {
616 var value = obj[key];
617
618 if (value === query) {
619 obj[key] = object;
620 return _toConsumableArray2(acc).concat([key]);
621 }
622
623 ;
624 if (isObject(value)) return _toConsumableArray2(acc).concat(_toConsumableArray2(start(value, query)));else return acc;
625 }, []);
626 };
627
628 return start(object);
629 };
630 /**
631 * Promise.map polyfill.
632 * @param {Array.<any>} arr Array of Promises.
633 * @param {Function} functor Function to call resolved values.
634 */
635
636
637 var PromiseMap = function PromiseMap(arr, functor) {
638 return Promise.all(arr.map(function (x) {
639 return Promise.resolve(x).then(functor);
640 }));
641 };
642 /**
643 * Resolve a flat object's promises.
644 * @param {Object}
645 * @returns {Object}
646 */
647
648
649 var ResolveObject = function ResolveObject(obj) {
650 return Promise.all(Object.keys(obj).map(function (key) {
651 return Promise.resolve(obj[key]).then(function (val) {
652 return obj[key] = val;
653 });
654 })).then(function (_) {
655 return obj;
656 });
657 };
658 /**
659 * Recursively resolves deep objects with nested promises.
660 * @param {Object} object Object or value to resolve.
661 * @returns {Object} Resolved object.
662 */
663
664
665 var PromiseObject = function PromiseObject(object) {
666 var shouldReplaceSelf = false;
667
668 var ResolveDeepObject = function ResolveDeepObject(obj) {
669 return Promise.resolve(obj).then(function (resolvedObject) {
670 if (Array.isArray(resolvedObject)) {
671 // Promise and map every item to recursively deep resolve.
672 return PromiseMap(resolvedObject, function (obj) {
673 return ResolveDeepObject(obj);
674 });
675 } else if (isObject(resolvedObject)) {
676 return ResolveObject(Object.keys(resolvedObject).reduce(function (acc, key) {
677 if (resolvedObject[key] === object) {
678 shouldReplaceSelf = true;
679 return _objectSpread({}, acc, _defineProperty2({}, key, $SELF));
680 }
681
682 return _objectSpread({}, acc, _defineProperty2({}, key, ResolveDeepObject(resolvedObject[key])));
683 }, {}));
684 }
685
686 return resolvedObject;
687 });
688 };
689
690 return ResolveDeepObject(object).then(function (obj) {
691 // Replace $SELF with reference to obj
692 if (shouldReplaceSelf) makeCyclic(obj, $SELF);
693 return obj;
694 });
695 };
696
697 module.exports = PromiseObject;
698 }, {}],
699 5: [function (require, module, exports) {
700 // Copyright Joyent, Inc. and other Node contributors.
701 //
702 // Permission is hereby granted, free of charge, to any person obtaining a
703 // copy of this software and associated documentation files (the
704 // "Software"), to deal in the Software without restriction, including
705 // without limitation the rights to use, copy, modify, merge, publish,
706 // distribute, sublicense, and/or sell copies of the Software, and to permit
707 // persons to whom the Software is furnished to do so, subject to the
708 // following conditions:
709 //
710 // The above copyright notice and this permission notice shall be included
711 // in all copies or substantial portions of the Software.
712 //
713 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
714 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
715 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
716 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
717 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
718 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
719 // USE OR OTHER DEALINGS IN THE SOFTWARE.
720 var objectCreate = Object.create || objectCreatePolyfill;
721 var objectKeys = Object.keys || objectKeysPolyfill;
722 var bind = Function.prototype.bind || functionBindPolyfill;
723
724 function EventEmitter() {
725 if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
726 this._events = objectCreate(null);
727 this._eventsCount = 0;
728 }
729
730 this._maxListeners = this._maxListeners || undefined;
731 }
732
733 module.exports = EventEmitter; // Backwards-compat with node 0.10.x
734
735 EventEmitter.EventEmitter = EventEmitter;
736 EventEmitter.prototype._events = undefined;
737 EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are
738 // added to it. This is a useful default which helps finding memory leaks.
739
740 var defaultMaxListeners = 10;
741 var hasDefineProperty;
742
743 try {
744 var o = {};
745 if (Object.defineProperty) Object.defineProperty(o, 'x', {
746 value: 0
747 });
748 hasDefineProperty = o.x === 0;
749 } catch (err) {
750 hasDefineProperty = false;
751 }
752
753 if (hasDefineProperty) {
754 Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
755 enumerable: true,
756 get: function get() {
757 return defaultMaxListeners;
758 },
759 set: function set(arg) {
760 // check whether the input is a positive number (whose value is zero or
761 // greater and not a NaN).
762 if (typeof arg !== 'number' || arg < 0 || arg !== arg) throw new TypeError('"defaultMaxListeners" must be a positive number');
763 defaultMaxListeners = arg;
764 }
765 });
766 } else {
767 EventEmitter.defaultMaxListeners = defaultMaxListeners;
768 } // Obviously not all Emitters should be limited to 10. This function allows
769 // that to be increased. Set to zero for unlimited.
770
771
772 EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
773 if (typeof n !== 'number' || n < 0 || isNaN(n)) throw new TypeError('"n" argument must be a positive number');
774 this._maxListeners = n;
775 return this;
776 };
777
778 function $getMaxListeners(that) {
779 if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners;
780 return that._maxListeners;
781 }
782
783 EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
784 return $getMaxListeners(this);
785 }; // These standalone emit* functions are used to optimize calling of event
786 // handlers for fast cases because emit() itself often has a variable number of
787 // arguments and can be deoptimized because of that. These functions always have
788 // the same number of arguments and thus do not get deoptimized, so the code
789 // inside them can execute faster.
790
791
792 function emitNone(handler, isFn, self) {
793 if (isFn) handler.call(self);else {
794 var len = handler.length;
795 var listeners = arrayClone(handler, len);
796
797 for (var i = 0; i < len; ++i) {
798 listeners[i].call(self);
799 }
800 }
801 }
802
803 function emitOne(handler, isFn, self, arg1) {
804 if (isFn) handler.call(self, arg1);else {
805 var len = handler.length;
806 var listeners = arrayClone(handler, len);
807
808 for (var i = 0; i < len; ++i) {
809 listeners[i].call(self, arg1);
810 }
811 }
812 }
813
814 function emitTwo(handler, isFn, self, arg1, arg2) {
815 if (isFn) handler.call(self, arg1, arg2);else {
816 var len = handler.length;
817 var listeners = arrayClone(handler, len);
818
819 for (var i = 0; i < len; ++i) {
820 listeners[i].call(self, arg1, arg2);
821 }
822 }
823 }
824
825 function emitThree(handler, isFn, self, arg1, arg2, arg3) {
826 if (isFn) handler.call(self, arg1, arg2, arg3);else {
827 var len = handler.length;
828 var listeners = arrayClone(handler, len);
829
830 for (var i = 0; i < len; ++i) {
831 listeners[i].call(self, arg1, arg2, arg3);
832 }
833 }
834 }
835
836 function emitMany(handler, isFn, self, args) {
837 if (isFn) handler.apply(self, args);else {
838 var len = handler.length;
839 var listeners = arrayClone(handler, len);
840
841 for (var i = 0; i < len; ++i) {
842 listeners[i].apply(self, args);
843 }
844 }
845 }
846
847 EventEmitter.prototype.emit = function emit(type) {
848 var er, handler, len, args, i, events;
849 var doError = type === 'error';
850 events = this._events;
851 if (events) doError = doError && events.error == null;else if (!doError) return false; // If there is no 'error' event listener then throw.
852
853 if (doError) {
854 if (arguments.length > 1) er = arguments[1];
855
856 if (er instanceof Error) {
857 throw er; // Unhandled 'error' event
858 } else {
859 // At least give some kind of context to the user
860 var err = new Error('Unhandled "error" event. (' + er + ')');
861 err.context = er;
862 throw err;
863 }
864
865 return false;
866 }
867
868 handler = events[type];
869 if (!handler) return false;
870 var isFn = typeof handler === 'function';
871 len = arguments.length;
872
873 switch (len) {
874 // fast cases
875 case 1:
876 emitNone(handler, isFn, this);
877 break;
878
879 case 2:
880 emitOne(handler, isFn, this, arguments[1]);
881 break;
882
883 case 3:
884 emitTwo(handler, isFn, this, arguments[1], arguments[2]);
885 break;
886
887 case 4:
888 emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
889 break;
890 // slower
891
892 default:
893 args = new Array(len - 1);
894
895 for (i = 1; i < len; i++) {
896 args[i - 1] = arguments[i];
897 }
898
899 emitMany(handler, isFn, this, args);
900 }
901
902 return true;
903 };
904
905 function _addListener(target, type, listener, prepend) {
906 var m;
907 var events;
908 var existing;
909 if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
910 events = target._events;
911
912 if (!events) {
913 events = target._events = objectCreate(null);
914 target._eventsCount = 0;
915 } else {
916 // To avoid recursion in the case that type === "newListener"! Before
917 // adding it to the listeners, first emit "newListener".
918 if (events.newListener) {
919 target.emit('newListener', type, listener.listener ? listener.listener : listener); // Re-assign `events` because a newListener handler could have caused the
920 // this._events to be assigned to a new object
921
922 events = target._events;
923 }
924
925 existing = events[type];
926 }
927
928 if (!existing) {
929 // Optimize the case of one listener. Don't need the extra array object.
930 existing = events[type] = listener;
931 ++target._eventsCount;
932 } else {
933 if (typeof existing === 'function') {
934 // Adding the second element, need to change to array.
935 existing = events[type] = prepend ? [listener, existing] : [existing, listener];
936 } else {
937 // If we've already got an array, just append.
938 if (prepend) {
939 existing.unshift(listener);
940 } else {
941 existing.push(listener);
942 }
943 } // Check for listener leak
944
945
946 if (!existing.warned) {
947 m = $getMaxListeners(target);
948
949 if (m && m > 0 && existing.length > m) {
950 existing.warned = true;
951 var w = new Error('Possible EventEmitter memory leak detected. ' + existing.length + ' "' + String(type) + '" listeners ' + 'added. Use emitter.setMaxListeners() to ' + 'increase limit.');
952 w.name = 'MaxListenersExceededWarning';
953 w.emitter = target;
954 w.type = type;
955 w.count = existing.length;
956
957 if ((typeof console === "undefined" ? "undefined" : _typeof2(console)) === 'object' && console.warn) {
958 console.warn('%s: %s', w.name, w.message);
959 }
960 }
961 }
962 }
963
964 return target;
965 }
966
967 EventEmitter.prototype.addListener = function addListener(type, listener) {
968 return _addListener(this, type, listener, false);
969 };
970
971 EventEmitter.prototype.on = EventEmitter.prototype.addListener;
972
973 EventEmitter.prototype.prependListener = function prependListener(type, listener) {
974 return _addListener(this, type, listener, true);
975 };
976
977 function onceWrapper() {
978 if (!this.fired) {
979 this.target.removeListener(this.type, this.wrapFn);
980 this.fired = true;
981
982 switch (arguments.length) {
983 case 0:
984 return this.listener.call(this.target);
985
986 case 1:
987 return this.listener.call(this.target, arguments[0]);
988
989 case 2:
990 return this.listener.call(this.target, arguments[0], arguments[1]);
991
992 case 3:
993 return this.listener.call(this.target, arguments[0], arguments[1], arguments[2]);
994
995 default:
996 var args = new Array(arguments.length);
997
998 for (var i = 0; i < args.length; ++i) {
999 args[i] = arguments[i];
1000 }
1001
1002 this.listener.apply(this.target, args);
1003 }
1004 }
1005 }
1006
1007 function _onceWrap(target, type, listener) {
1008 var state = {
1009 fired: false,
1010 wrapFn: undefined,
1011 target: target,
1012 type: type,
1013 listener: listener
1014 };
1015 var wrapped = bind.call(onceWrapper, state);
1016 wrapped.listener = listener;
1017 state.wrapFn = wrapped;
1018 return wrapped;
1019 }
1020
1021 EventEmitter.prototype.once = function once(type, listener) {
1022 if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
1023 this.on(type, _onceWrap(this, type, listener));
1024 return this;
1025 };
1026
1027 EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
1028 if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
1029 this.prependListener(type, _onceWrap(this, type, listener));
1030 return this;
1031 }; // Emits a 'removeListener' event if and only if the listener was removed.
1032
1033
1034 EventEmitter.prototype.removeListener = function removeListener(type, listener) {
1035 var list, events, position, i, originalListener;
1036 if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
1037 events = this._events;
1038 if (!events) return this;
1039 list = events[type];
1040 if (!list) return this;
1041
1042 if (list === listener || list.listener === listener) {
1043 if (--this._eventsCount === 0) this._events = objectCreate(null);else {
1044 delete events[type];
1045 if (events.removeListener) this.emit('removeListener', type, list.listener || listener);
1046 }
1047 } else if (typeof list !== 'function') {
1048 position = -1;
1049
1050 for (i = list.length - 1; i >= 0; i--) {
1051 if (list[i] === listener || list[i].listener === listener) {
1052 originalListener = list[i].listener;
1053 position = i;
1054 break;
1055 }
1056 }
1057
1058 if (position < 0) return this;
1059 if (position === 0) list.shift();else spliceOne(list, position);
1060 if (list.length === 1) events[type] = list[0];
1061 if (events.removeListener) this.emit('removeListener', type, originalListener || listener);
1062 }
1063
1064 return this;
1065 };
1066
1067 EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
1068 var listeners, events, i;
1069 events = this._events;
1070 if (!events) return this; // not listening for removeListener, no need to emit
1071
1072 if (!events.removeListener) {
1073 if (arguments.length === 0) {
1074 this._events = objectCreate(null);
1075 this._eventsCount = 0;
1076 } else if (events[type]) {
1077 if (--this._eventsCount === 0) this._events = objectCreate(null);else delete events[type];
1078 }
1079
1080 return this;
1081 } // emit removeListener for all listeners on all events
1082
1083
1084 if (arguments.length === 0) {
1085 var keys = objectKeys(events);
1086 var key;
1087
1088 for (i = 0; i < keys.length; ++i) {
1089 key = keys[i];
1090 if (key === 'removeListener') continue;
1091 this.removeAllListeners(key);
1092 }
1093
1094 this.removeAllListeners('removeListener');
1095 this._events = objectCreate(null);
1096 this._eventsCount = 0;
1097 return this;
1098 }
1099
1100 listeners = events[type];
1101
1102 if (typeof listeners === 'function') {
1103 this.removeListener(type, listeners);
1104 } else if (listeners) {
1105 // LIFO order
1106 for (i = listeners.length - 1; i >= 0; i--) {
1107 this.removeListener(type, listeners[i]);
1108 }
1109 }
1110
1111 return this;
1112 };
1113
1114 function _listeners(target, type, unwrap) {
1115 var events = target._events;
1116 if (!events) return [];
1117 var evlistener = events[type];
1118 if (!evlistener) return [];
1119 if (typeof evlistener === 'function') return unwrap ? [evlistener.listener || evlistener] : [evlistener];
1120 return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
1121 }
1122
1123 EventEmitter.prototype.listeners = function listeners(type) {
1124 return _listeners(this, type, true);
1125 };
1126
1127 EventEmitter.prototype.rawListeners = function rawListeners(type) {
1128 return _listeners(this, type, false);
1129 };
1130
1131 EventEmitter.listenerCount = function (emitter, type) {
1132 if (typeof emitter.listenerCount === 'function') {
1133 return emitter.listenerCount(type);
1134 } else {
1135 return listenerCount.call(emitter, type);
1136 }
1137 };
1138
1139 EventEmitter.prototype.listenerCount = listenerCount;
1140
1141 function listenerCount(type) {
1142 var events = this._events;
1143
1144 if (events) {
1145 var evlistener = events[type];
1146
1147 if (typeof evlistener === 'function') {
1148 return 1;
1149 } else if (evlistener) {
1150 return evlistener.length;
1151 }
1152 }
1153
1154 return 0;
1155 }
1156
1157 EventEmitter.prototype.eventNames = function eventNames() {
1158 return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
1159 }; // About 1.5x faster than the two-arg version of Array#splice().
1160
1161
1162 function spliceOne(list, index) {
1163 for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) {
1164 list[i] = list[k];
1165 }
1166
1167 list.pop();
1168 }
1169
1170 function arrayClone(arr, n) {
1171 var copy = new Array(n);
1172
1173 for (var i = 0; i < n; ++i) {
1174 copy[i] = arr[i];
1175 }
1176
1177 return copy;
1178 }
1179
1180 function unwrapListeners(arr) {
1181 var ret = new Array(arr.length);
1182
1183 for (var i = 0; i < ret.length; ++i) {
1184 ret[i] = arr[i].listener || arr[i];
1185 }
1186
1187 return ret;
1188 }
1189
1190 function objectCreatePolyfill(proto) {
1191 var F = function F() {};
1192
1193 F.prototype = proto;
1194 return new F();
1195 }
1196
1197 function objectKeysPolyfill(obj) {
1198 var keys = [];
1199
1200 for (var k in obj) {
1201 if (Object.prototype.hasOwnProperty.call(obj, k)) {
1202 keys.push(k);
1203 }
1204 }
1205
1206 return k;
1207 }
1208
1209 function functionBindPolyfill(context) {
1210 var fn = this;
1211 return function () {
1212 return fn.apply(context, arguments);
1213 };
1214 }
1215 }, {}],
1216 6: [function (require, module, exports) {
1217 exports = module.exports = stringify;
1218 exports.getSerialize = serializer;
1219
1220 function stringify(obj, replacer, spaces, cycleReplacer) {
1221 return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
1222 }
1223
1224 function serializer(replacer, cycleReplacer) {
1225 var stack = [],
1226 keys = [];
1227 if (cycleReplacer == null) cycleReplacer = function cycleReplacer(key, value) {
1228 if (stack[0] === value) return "[Circular ~]";
1229 return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
1230 };
1231 return function (key, value) {
1232 if (stack.length > 0) {
1233 var thisPos = stack.indexOf(this);
1234 ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
1235 ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
1236 if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value);
1237 } else stack.push(value);
1238
1239 return replacer == null ? value : replacer.call(this, key, value);
1240 };
1241 }
1242 }, {}],
1243 7: [function (require, module, exports) {
1244 //copyright Ryan Day 2010 <http://ryanday.org>, Joscha Feth 2013 <http://www.feth.com> [MIT Licensed]
1245 var element_start_char = "a-zA-Z_\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FFF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD";
1246 var element_non_start_char = "-.0-9\xB7\u0300-\u036F\u203F\u2040";
1247 var element_replace = new RegExp("^([^" + element_start_char + "])|^((x|X)(m|M)(l|L))|([^" + element_start_char + element_non_start_char + "])", "g");
1248 var not_safe_in_xml = /[^\x09\x0A\x0D\x20-\xFF\x85\xA0-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]/gm;
1249
1250 var process_to_xml = function process_to_xml(node_data, options) {
1251 var makeNode = function makeNode(name, content, attributes, level, hasSubNodes) {
1252 var indent_value = options.indent !== undefined ? options.indent : "\t";
1253 var indent = options.prettyPrint ? '\n' + new Array(level).join(indent_value) : '';
1254
1255 if (options.removeIllegalNameCharacters) {
1256 name = name.replace(element_replace, '_');
1257 }
1258
1259 var node = [indent, '<', name, attributes || ''];
1260
1261 if (content && content.length > 0 || options.html) {
1262 node.push('>');
1263 node.push(content);
1264 hasSubNodes && node.push(indent);
1265 node.push('</');
1266 node.push(name);
1267 node.push('>');
1268 } else {
1269 node.push('/>');
1270 }
1271
1272 return node.join('');
1273 };
1274
1275 return function fn(node_data, node_descriptor, level) {
1276 var type = _typeof2(node_data);
1277
1278 if (Array.isArray ? Array.isArray(node_data) : node_data instanceof Array) {
1279 type = 'array';
1280 } else if (node_data instanceof Date) {
1281 type = 'date';
1282 }
1283
1284 switch (type) {
1285 //if value is an array create child nodes from values
1286 case 'array':
1287 var ret = [];
1288 node_data.map(function (v) {
1289 ret.push(fn(v, 1, level + 1)); //entries that are values of an array are the only ones that can be special node descriptors
1290 });
1291 options.prettyPrint && ret.push('\n');
1292 return ret.join('');
1293 break;
1294
1295 case 'date':
1296 // cast dates to ISO 8601 date (soap likes it)
1297 return node_data.toJSON ? node_data.toJSON() : node_data + '';
1298 break;
1299
1300 case 'object':
1301 if (node_descriptor == 1 && node_data.name) {
1302 var content = [],
1303 attributes = [];
1304
1305 if (node_data.attrs) {
1306 if (_typeof2(node_data.attrs) != 'object') {
1307 // attrs is a string, etc. - just use it as an attribute
1308 attributes.push(' ');
1309 attributes.push(node_data.attrs);
1310 } else {
1311 for (var key in node_data.attrs) {
1312 var value = node_data.attrs[key];
1313 attributes.push(' ');
1314 attributes.push(key);
1315 attributes.push('="');
1316 attributes.push(options.escape ? esc(value) : value);
1317 attributes.push('"');
1318 }
1319 }
1320 } //later attributes can be added here
1321
1322
1323 if (typeof node_data.value != 'undefined') {
1324 var c = '' + node_data.value;
1325 content.push(options.escape && !node_data.noescape ? esc(c) : c);
1326 } else if (typeof node_data.text != 'undefined') {
1327 var c = '' + node_data.text;
1328 content.push(options.escape && !node_data.noescape ? esc(c) : c);
1329 }
1330
1331 if (node_data.children) {
1332 content.push(fn(node_data.children, 0, level + 1));
1333 }
1334
1335 return makeNode(node_data.name, content.join(''), attributes.join(''), level, !!node_data.children);
1336 } else {
1337 var nodes = [];
1338
1339 for (var name in node_data) {
1340 nodes.push(makeNode(name, fn(node_data[name], 0, level + 1), null, level + 1));
1341 }
1342
1343 options.prettyPrint && nodes.length > 0 && nodes.push('\n');
1344 return nodes.join('');
1345 }
1346
1347 break;
1348
1349 case 'function':
1350 return node_data();
1351 break;
1352
1353 default:
1354 return options.escape ? esc(node_data) : '' + node_data;
1355 }
1356 }(node_data, 0, 0);
1357 };
1358
1359 var xml_header = function xml_header(standalone) {
1360 var ret = ['<?xml version="1.0" encoding="utf-8"'];
1361
1362 if (standalone) {
1363 ret.push(' standalone="yes"');
1364 }
1365
1366 ret.push('?>');
1367 return ret.join('');
1368 };
1369
1370 module.exports = function (obj, options) {
1371 var Buffer = this.Buffer || function Buffer() {};
1372
1373 if (typeof obj == 'string' || obj instanceof Buffer) {
1374 try {
1375 obj = JSON.parse(obj.toString());
1376 } catch (e) {
1377 return false;
1378 }
1379 }
1380
1381 var xmlheader = '';
1382 var docType = '';
1383
1384 if (options) {
1385 if (_typeof2(options) == 'object') {
1386 // our config is an object
1387 if (options.xmlHeader) {
1388 // the user wants an xml header
1389 xmlheader = xml_header(!!options.xmlHeader.standalone);
1390 }
1391
1392 if (typeof options.docType != 'undefined') {
1393 docType = '<!DOCTYPE ' + options.docType + '>';
1394 }
1395 } else {
1396 // our config is a boolean value, so just add xml header
1397 xmlheader = xml_header();
1398 }
1399 }
1400
1401 options = options || {};
1402 var ret = [xmlheader, options.prettyPrint && docType ? '\n' : '', docType, process_to_xml(obj, options)];
1403 return ret.join('');
1404 };
1405
1406 module.exports.json_to_xml = module.exports.obj_to_xml = module.exports;
1407 module.exports.escape = esc;
1408
1409 function esc(str) {
1410 return ('' + str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;').replace(not_safe_in_xml, '');
1411 }
1412
1413 module.exports.cdata = cdata;
1414
1415 function cdata(str) {
1416 if (str) return "<![CDATA[" + str.replace(/]]>/g, '') + ']]>';
1417 return "<![CDATA[]]>";
1418 }
1419
1420 ;
1421 }, {}],
1422 8: [function (require, module, exports) {
1423 exports.endianness = function () {
1424 return 'LE';
1425 };
1426
1427 exports.hostname = function () {
1428 if (typeof location !== 'undefined') {
1429 return location.hostname;
1430 } else return '';
1431 };
1432
1433 exports.loadavg = function () {
1434 return [];
1435 };
1436
1437 exports.uptime = function () {
1438 return 0;
1439 };
1440
1441 exports.freemem = function () {
1442 return Number.MAX_VALUE;
1443 };
1444
1445 exports.totalmem = function () {
1446 return Number.MAX_VALUE;
1447 };
1448
1449 exports.cpus = function () {
1450 return [];
1451 };
1452
1453 exports.type = function () {
1454 return 'Browser';
1455 };
1456
1457 exports.release = function () {
1458 if (typeof navigator !== 'undefined') {
1459 return navigator.appVersion;
1460 }
1461
1462 return '';
1463 };
1464
1465 exports.networkInterfaces = exports.getNetworkInterfaces = function () {
1466 return {};
1467 };
1468
1469 exports.arch = function () {
1470 return 'javascript';
1471 };
1472
1473 exports.platform = function () {
1474 return 'browser';
1475 };
1476
1477 exports.tmpdir = exports.tmpDir = function () {
1478 return '/tmp';
1479 };
1480
1481 exports.EOL = '\n';
1482
1483 exports.homedir = function () {
1484 return '/';
1485 };
1486 }, {}],
1487 9: [function (require, module, exports) {
1488 // shim for using process in browser
1489 var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
1490 // don't break things. But we need to wrap it in a try catch in case it is
1491 // wrapped in strict mode code which doesn't define any globals. It's inside a
1492 // function because try/catches deoptimize in certain engines.
1493
1494 var cachedSetTimeout;
1495 var cachedClearTimeout;
1496
1497 function defaultSetTimout() {
1498 throw new Error('setTimeout has not been defined');
1499 }
1500
1501 function defaultClearTimeout() {
1502 throw new Error('clearTimeout has not been defined');
1503 }
1504
1505 (function () {
1506 try {
1507 if (typeof setTimeout === 'function') {
1508 cachedSetTimeout = setTimeout;
1509 } else {
1510 cachedSetTimeout = defaultSetTimout;
1511 }
1512 } catch (e) {
1513 cachedSetTimeout = defaultSetTimout;
1514 }
1515
1516 try {
1517 if (typeof clearTimeout === 'function') {
1518 cachedClearTimeout = clearTimeout;
1519 } else {
1520 cachedClearTimeout = defaultClearTimeout;
1521 }
1522 } catch (e) {
1523 cachedClearTimeout = defaultClearTimeout;
1524 }
1525 })();
1526
1527 function runTimeout(fun) {
1528 if (cachedSetTimeout === setTimeout) {
1529 //normal enviroments in sane situations
1530 return setTimeout(fun, 0);
1531 } // if setTimeout wasn't available but was latter defined
1532
1533
1534 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
1535 cachedSetTimeout = setTimeout;
1536 return setTimeout(fun, 0);
1537 }
1538
1539 try {
1540 // when when somebody has screwed with setTimeout but no I.E. maddness
1541 return cachedSetTimeout(fun, 0);
1542 } catch (e) {
1543 try {
1544 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1545 return cachedSetTimeout.call(null, fun, 0);
1546 } catch (e) {
1547 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
1548 return cachedSetTimeout.call(this, fun, 0);
1549 }
1550 }
1551 }
1552
1553 function runClearTimeout(marker) {
1554 if (cachedClearTimeout === clearTimeout) {
1555 //normal enviroments in sane situations
1556 return clearTimeout(marker);
1557 } // if clearTimeout wasn't available but was latter defined
1558
1559
1560 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
1561 cachedClearTimeout = clearTimeout;
1562 return clearTimeout(marker);
1563 }
1564
1565 try {
1566 // when when somebody has screwed with setTimeout but no I.E. maddness
1567 return cachedClearTimeout(marker);
1568 } catch (e) {
1569 try {
1570 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1571 return cachedClearTimeout.call(null, marker);
1572 } catch (e) {
1573 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
1574 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
1575 return cachedClearTimeout.call(this, marker);
1576 }
1577 }
1578 }
1579
1580 var queue = [];
1581 var draining = false;
1582 var currentQueue;
1583 var queueIndex = -1;
1584
1585 function cleanUpNextTick() {
1586 if (!draining || !currentQueue) {
1587 return;
1588 }
1589
1590 draining = false;
1591
1592 if (currentQueue.length) {
1593 queue = currentQueue.concat(queue);
1594 } else {
1595 queueIndex = -1;
1596 }
1597
1598 if (queue.length) {
1599 drainQueue();
1600 }
1601 }
1602
1603 function drainQueue() {
1604 if (draining) {
1605 return;
1606 }
1607
1608 var timeout = runTimeout(cleanUpNextTick);
1609 draining = true;
1610 var len = queue.length;
1611
1612 while (len) {
1613 currentQueue = queue;
1614 queue = [];
1615
1616 while (++queueIndex < len) {
1617 if (currentQueue) {
1618 currentQueue[queueIndex].run();
1619 }
1620 }
1621
1622 queueIndex = -1;
1623 len = queue.length;
1624 }
1625
1626 currentQueue = null;
1627 draining = false;
1628 runClearTimeout(timeout);
1629 }
1630
1631 process.nextTick = function (fun) {
1632 var args = new Array(arguments.length - 1);
1633
1634 if (arguments.length > 1) {
1635 for (var i = 1; i < arguments.length; i++) {
1636 args[i - 1] = arguments[i];
1637 }
1638 }
1639
1640 queue.push(new Item(fun, args));
1641
1642 if (queue.length === 1 && !draining) {
1643 runTimeout(drainQueue);
1644 }
1645 }; // v8 likes predictible objects
1646
1647
1648 function Item(fun, array) {
1649 this.fun = fun;
1650 this.array = array;
1651 }
1652
1653 Item.prototype.run = function () {
1654 this.fun.apply(null, this.array);
1655 };
1656
1657 process.title = 'browser';
1658 process.browser = true;
1659 process.env = {};
1660 process.argv = [];
1661 process.version = ''; // empty string to avoid regexp issues
1662
1663 process.versions = {};
1664
1665 function noop() {}
1666
1667 process.on = noop;
1668 process.addListener = noop;
1669 process.once = noop;
1670 process.off = noop;
1671 process.removeListener = noop;
1672 process.removeAllListeners = noop;
1673 process.emit = noop;
1674 process.prependListener = noop;
1675 process.prependOnceListener = noop;
1676
1677 process.listeners = function (name) {
1678 return [];
1679 };
1680
1681 process.binding = function (name) {
1682 throw new Error('process.binding is not supported');
1683 };
1684
1685 process.cwd = function () {
1686 return '/';
1687 };
1688
1689 process.chdir = function (dir) {
1690 throw new Error('process.chdir is not supported');
1691 };
1692
1693 process.umask = function () {
1694 return 0;
1695 };
1696 }, {}],
1697 10: [function (require, module, exports) {
1698 (function (process) {
1699 'use strict';
1700
1701 var _require = require('./util'),
1702 arrayOrPush = _require.arrayOrPush;
1703
1704 var caller = require('./lib/caller');
1705
1706 var emitter = require('./lib/emitter');
1707
1708 var reporters = require('./reporters');
1709
1710 var testrunner = require('./lib/testrunner');
1711
1712 var symbols = require('./util/symbols');
1713
1714 var Gunner =
1715 /*#__PURE__*/
1716 function () {
1717 function Gunner(name) {
1718 var _beforeHooks, _afterHooks;
1719
1720 _classCallCheck(this, Gunner);
1721
1722 this.name = name;
1723 this.__suite__ = {
1724 tests: [],
1725 beforeHooks: (_beforeHooks = {}, _defineProperty2(_beforeHooks, symbols.Start, []), _defineProperty2(_beforeHooks, symbols.End, []), _defineProperty2(_beforeHooks, '*', []), _beforeHooks),
1726 afterHooks: (_afterHooks = {}, _defineProperty2(_afterHooks, symbols.Start, []), _defineProperty2(_afterHooks, symbols.End, []), _defineProperty2(_afterHooks, '*', []), _afterHooks)
1727 };
1728 }
1729
1730 _createClass(Gunner, [{
1731 key: "test",
1732 value: function test(description, _test) {
1733 var existing = this.__suite__.tests.find(function (x) {
1734 return x.description === description;
1735 });
1736
1737 if (existing) throw new Error("Test '".concat(description, "' already exists!"));
1738 var unit = {
1739 description: description,
1740 type: 'test',
1741 run: function run(state) {
1742 return caller(_test, state);
1743 }
1744 };
1745
1746 this.__suite__.tests.push(unit);
1747
1748 return this;
1749 }
1750 }, {
1751 key: "before",
1752 value: function before(description, _run, label) {
1753 var unit = {
1754 description: description,
1755 label: label,
1756 type: 'hook',
1757 run: function run(state) {
1758 return caller(_run, state);
1759 }
1760 };
1761 arrayOrPush(this.__suite__.beforeHooks, description, unit);
1762 return this;
1763 }
1764 }, {
1765 key: "after",
1766 value: function after(description, _run2, label) {
1767 var unit = {
1768 description: description,
1769 label: label,
1770 type: 'hook',
1771 run: function run(state) {
1772 return caller(_run2, state);
1773 }
1774 };
1775 arrayOrPush(this.__suite__.afterHooks, description, unit);
1776 return this;
1777 }
1778 }, {
1779 key: "run",
1780 value: function run() {
1781 var _this = this;
1782
1783 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1784 if (options.reporter === true) reporters.default(emitter, options);else if (typeof options.reporter === 'function') options.reporter(emitter, options);else if (reporters[options.reporter]) reporters[options.reporter](emitter, options);
1785 emitter.emit('start');
1786 return testrunner(this, options).then(function (results) {
1787 var _ref;
1788
1789 results.count = results.length;
1790 results.success = results.filter(function (r) {
1791 return r.status === 'ok';
1792 });
1793 results.failures = results.filter(function (r) {
1794 return r.status === 'notOk';
1795 });
1796 results.skipped = results.filter(function (r) {
1797 return r.status === 'skip';
1798 });
1799 results.successPercent = Math.floor(results.success.length / results.length * 100);
1800 results.name = _this.name;
1801 if (results.successPercent !== 100 && typeof process !== 'undefined') process.exitCode = 1;
1802 emitter.emit('test end', results);
1803 emitter.emit('end', results);
1804 return options.request ? (_ref = {}, _defineProperty2(_ref, options.request, reporters[options.request].convert(results)), _defineProperty2(_ref, "default", results), _ref) : results;
1805 });
1806 }
1807 }]);
1808
1809 return Gunner;
1810 }();
1811
1812 var expect = require('./lib/expect');
1813
1814 module.exports = Gunner;
1815 module.exports.expect = expect;
1816 module.exports.expectMany = expect.expectMany;
1817 module.exports.Start = symbols.Start;
1818 module.exports.End = symbols.End;
1819 module.exports.Gunner = module.exports;
1820 }).call(this, require('_process'));
1821 }, {
1822 "./lib/caller": 14,
1823 "./lib/emitter": 15,
1824 "./lib/expect": 16,
1825 "./lib/testrunner": 17,
1826 "./reporters": 19,
1827 "./util": 24,
1828 "./util/symbols": 26,
1829 "_process": 9
1830 }],
1831 11: [function (require, module, exports) {
1832 var _require2 = require('../util'),
1833 isPromise = _require2.isPromise;
1834
1835 var createRejectionStatement = function createRejectionStatement(statement) {
1836 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1837 args[_key - 1] = arguments[_key];
1838 }
1839
1840 return Promise.reject(statement ? statement.apply(void 0, args) : '');
1841 };
1842
1843 var assertPromise = function assertPromise(bool, statementTuple) {
1844 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1845
1846 var _statementTuple = _toArray(statementTuple),
1847 statement = _statementTuple[0],
1848 args = _statementTuple.slice(1);
1849
1850 statement = options.skipStatement ? function () {
1851 return options.skipStatement;
1852 } : statement;
1853 if (isPromise(bool)) return bool.catch(function () {
1854 return createRejectionStatement.apply(void 0, [statement].concat(_toConsumableArray2(args)));
1855 });
1856 return bool ? Promise.resolve() : createRejectionStatement.apply(void 0, [statement].concat(_toConsumableArray2(args)));
1857 };
1858
1859 module.exports = assertPromise;
1860 }, {
1861 "../util": 24
1862 }],
1863 12: [function (require, module, exports) {
1864 var isEq = require('@codefeathers/iseq');
1865
1866 var U = require('../util');
1867
1868 var _ = U.taggedStringify;
1869 module.exports.done = [function () {
1870 return true;
1871 }, function () {
1872 return null;
1873 }];
1874 module.exports.fail = [function () {
1875 return false;
1876 }, function (_, rejection) {
1877 return rejection;
1878 }];
1879 module.exports.exists = [function (val) {
1880 return typeof val !== 'undefined';
1881 }, function () {
1882 return "Value is undefined";
1883 }];
1884 module.exports.isArray = [function (val) {
1885 return Array.isArray(val);
1886 }, function (val) {
1887 return _(_templateObject(), val);
1888 }];
1889 module.exports.isObject = [function (val) {
1890 return _typeof2(val) === 'object' && val !== null;
1891 }, function (val) {
1892 return _(_templateObject2(), val);
1893 }];
1894 module.exports.hasLength = [function (val, l) {
1895 return val.length === l;
1896 }, function (val, l) {
1897 return _(_templateObject3(), val, l);
1898 }];
1899 module.exports.equals = [function (val, thing) {
1900 return val === thing;
1901 }, function (val, thing) {
1902 return _(_templateObject4(), val, thing);
1903 }];
1904 module.exports.deepEquals = [function (val, match) {
1905 return isEq(val, match);
1906 }, function (val, match) {
1907 return _(_templateObject5(), val, match);
1908 }];
1909 module.exports.contains = [function (val, match) {
1910 return isEq(val, match, Object.keys(match));
1911 }, function (val, match) {
1912 return _(_templateObject6(), val, match);
1913 }];
1914 module.exports.isTrue = [function (val) {
1915 return val === true;
1916 }, function (val) {
1917 return _(_templateObject7(), val);
1918 }];
1919 module.exports.isFalse = [function (val) {
1920 return val === false;
1921 }, function (val) {
1922 return _(_templateObject8(), val);
1923 }];
1924 module.exports.hasProp = [function (val, prop) {
1925 return val.hasOwnProperty(prop);
1926 }, function (val, prop) {
1927 return _(_templateObject9(), val, prop);
1928 }];
1929 module.exports.hasPair = [function (val) {
1930 for (var _len2 = arguments.length, pair = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1931 pair[_key2 - 1] = arguments[_key2];
1932 }
1933
1934 return isEq(val[pair[0]], pair[1]);
1935 }, function (val) {
1936 for (var _len3 = arguments.length, pair = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
1937 pair[_key3 - 1] = arguments[_key3];
1938 }
1939
1940 return _(_templateObject10(), pair, val);
1941 }];
1942 module.exports.isPromise = [function (val) {
1943 return U.isPromise(val);
1944 }, function (val) {
1945 return _(_templateObject11(), val);
1946 }, {
1947 shouldCatch: true
1948 }];
1949 module.exports.resolvesTo = [function (val, thing) {
1950 return U.isPromise(val) ? val.then(function (x) {
1951 return x === thing ? Promise.resolve() : Promise.reject();
1952 }) : Promise.reject("".concat(val, " was not a Promise"));
1953 }, function (val, thing) {
1954 return _(_templateObject12(), val, thing);
1955 }];
1956 module.exports.isType = [function (val, type) {
1957 return type === 'nil' && (val === 'null' || val === 'undefined') || _typeof2(val) === type || Array.isArray(val) && type === "array" && val === null && type !== 'object';
1958 }, function (val, type) {
1959 return _(_templateObject13(), val, type);
1960 }];
1961 module.exports.greaterThan = [function (val, compare) {
1962 return val > compare;
1963 }, function (val, compare) {
1964 return _(_templateObject14(), val, compare);
1965 }];
1966 module.exports.lessThan = [function (val, compare) {
1967 return val < compare;
1968 }, function (val, compare) {
1969 return _(_templateObject15(), val, compare);
1970 }];
1971 module.exports.gte = [function (val, compare) {
1972 return val >= compare;
1973 }, function (val, compare) {
1974 return _(_templateObject16(), val, compare);
1975 }];
1976 module.exports.lte = [function (val, compare) {
1977 return val <= compare;
1978 }, function (val, compare) {
1979 return _(_templateObject17(), val, compare);
1980 }];
1981 /* Convenience aliases */
1982
1983 module.exports.success = module.exports.done;
1984 module.exports.succeed = module.exports.done;
1985 module.exports.failure = module.exports.fail;
1986 module.exports.equal = module.exports.equals;
1987 module.exports.deepEqual = module.exports.deepEquals;
1988 module.exports.match = module.exports.deepEquals;
1989 module.exports.greaterThanOrEqualTo = module.exports.gte;
1990 module.exports.lessThanOrEqualTo = module.exports.lte;
1991 }, {
1992 "../util": 24,
1993 "@codefeathers/iseq": 2
1994 }],
1995 13: [function (require, module, exports) {
1996 // Only imported for JSDoc
1997
1998 /* eslint-disable-next-line */
1999 var Gunner = require('../Gunner');
2000
2001 var symbols = require('../util/symbols');
2002
2003 var wrap = function wrap(type) {
2004 return function (unit) {
2005 return {
2006 type: type,
2007 unit: unit
2008 };
2009 };
2010 };
2011 /**
2012 * runs the test suite
2013 * @param {Gunner} instance
2014 */
2015
2016
2017 var buildTestTree = function buildTestTree(instance) {
2018 var testQueue = [];
2019 Array.prototype.push.apply(testQueue, instance.__suite__.beforeHooks[symbols.Start].map(wrap('@start')));
2020 testQueue.push.apply(instance.__suite__.afterHooks[symbols.Start].map(wrap('@start')));
2021
2022 instance.__suite__.tests.forEach(function (test) {
2023 return Array.prototype.push.apply(testQueue, instance.__suite__.beforeHooks['*'].map(wrap('@every'))), Array.prototype.push.apply(testQueue, (instance.__suite__.beforeHooks[test.description] || []).map(wrap('@this'))), testQueue.push(wrap('@test')(test)), Array.prototype.push.apply(testQueue, (instance.__suite__.afterHooks[test.description] || []).map(wrap('@afterTest'))), Array.prototype.push.apply(testQueue, instance.__suite__.afterHooks['*'].map(wrap('@afterEvery')));
2024 });
2025
2026 Array.prototype.push.apply(testQueue, instance.__suite__.beforeHooks[symbols.End].map(wrap('@beforeend')));
2027 Array.prototype.push.apply(testQueue, instance.__suite__.afterHooks[symbols.End].map(wrap('@end')));
2028 return testQueue;
2029 };
2030
2031 module.exports = buildTestTree;
2032 }, {
2033 "../Gunner": 10,
2034 "../util/symbols": 26
2035 }],
2036 14: [function (require, module, exports) {
2037 var _require3 = require('../util'),
2038 isPromise = _require3.isPromise;
2039
2040 var caller = function caller(test, state) {
2041 var perf = {
2042 start: 0,
2043 end: 0
2044 };
2045 var value, error, errored;
2046
2047 try {
2048 perf.start = new Date();
2049 value = test(state);
2050 perf.end = new Date();
2051 } catch (e) {
2052 perf.end = new Date();
2053 errored = true;
2054 error = e;
2055 }
2056
2057 var promise = isPromise(value);
2058
2059 if (promise) {
2060 return value.then(function (res) {
2061 return {
2062 duration: new Date() - perf.start,
2063 status: 'ok',
2064 resolve: res,
2065 promise: true
2066 };
2067 }).catch(function (rej) {
2068 return {
2069 duration: new Date() - perf.start,
2070 status: 'notOk',
2071 rejection: rej,
2072 promise: true
2073 };
2074 });
2075 } else {
2076 return Promise.resolve(_objectSpread({
2077 duration: perf.end - perf.start,
2078 status: errored ? 'notOk' : 'ok'
2079 }, !errored && {
2080 value: value
2081 }, errored && {
2082 error: error
2083 }, {
2084 promise: false
2085 }));
2086 }
2087 };
2088
2089 module.exports = caller;
2090 }, {
2091 "../util": 24
2092 }],
2093 15: [function (require, module, exports) {
2094 var EventEmitter = require('events');
2095
2096 var GunnerEmitter =
2097 /*#__PURE__*/
2098 function (_EventEmitter) {
2099 _inherits(GunnerEmitter, _EventEmitter);
2100
2101 function GunnerEmitter() {
2102 _classCallCheck(this, GunnerEmitter);
2103
2104 return _possibleConstructorReturn(this, _getPrototypeOf(GunnerEmitter).apply(this, arguments));
2105 }
2106
2107 return GunnerEmitter;
2108 }(EventEmitter);
2109
2110 module.exports = new GunnerEmitter();
2111 }, {
2112 "events": 5
2113 }],
2114 16: [function (require, module, exports) {
2115 'use strict';
2116
2117 var _require4 = require('../util'),
2118 liftPromise = _require4.liftPromise,
2119 lowerCaseFirstLetter = _require4.lowerCaseFirstLetter;
2120
2121 var library = require('./assertionsLibrary');
2122
2123 var assertPromise = require('./assertPromise');
2124
2125 var expectPromise = function expectPromise(pred, statement) {
2126 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2127 return function (toTest) {
2128 return function () {
2129 for (var _len4 = arguments.length, testValues = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2130 testValues[_key4] = arguments[_key4];
2131 }
2132
2133 return liftPromise(function (resolvedValue) {
2134 return assertPromise(pred.apply(void 0, [toTest].concat(testValues)), [statement, resolvedValue].concat(testValues));
2135 }, toTest).catch(function (rejectedValue) {
2136 return options.shouldCatch ? assertPromise(pred.apply(void 0, [toTest].concat(testValues)), [statement, rejectedValue].concat(testValues), {
2137 skipStatement: rejectedValue
2138 }) : Promise.reject(rejectedValue);
2139 });
2140 };
2141 };
2142 };
2143
2144 var expects = Object.keys(library).reduce(function (acc, e) {
2145 var _library$e = _slicedToArray(library[e], 3),
2146 pred = _library$e[0],
2147 statement = _library$e[1],
2148 options = _library$e[2];
2149
2150 acc[e] = expectPromise(pred, statement, options);
2151 return acc;
2152 }, {});
2153
2154 var negateP = function negateP(prom) {
2155 return prom.then(Promise.reject, Promise.resolve);
2156 };
2157
2158 var expect = function expect(thing, args) {
2159 return new Proxy({}, {
2160 get: function get(obj, prop) {
2161 var toCheck = args ? thing.apply(void 0, _toConsumableArray2(args)) : thing;
2162 if (expects.hasOwnProperty(prop)) return function () {
2163 return expects[prop](toCheck).apply(void 0, arguments);
2164 };else if (prop.slice(0, 3) === 'not') return function () {
2165 return negateP(expects[lowerCaseFirstLetter(prop.slice(3))](toCheck).apply(void 0, arguments));
2166 };else throw new Error('Unknown assertion method', prop);
2167 }
2168 });
2169 };
2170
2171 var expectMany = function expectMany() {
2172 for (var _len5 = arguments.length, expects = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2173 expects[_key5] = arguments[_key5];
2174 }
2175
2176 return Promise.all(expects);
2177 };
2178
2179 module.exports = expect;
2180 module.exports.expectMany = expectMany;
2181 }, {
2182 "../util": 24,
2183 "./assertPromise": 11,
2184 "./assertionsLibrary": 12
2185 }],
2186 17: [function (require, module, exports) {
2187 // Only imported for JSDoc
2188
2189 /* eslint-disable-next-line */
2190 var Gunner = require('../Gunner');
2191
2192 Promise.object = require('@codefeathers/promise.object');
2193
2194 var _require5 = require('../util'),
2195 last = _require5.last,
2196 pipe = _require5.pipe,
2197 pick = _require5.pick,
2198 assignToObject = _require5.assignToObject;
2199
2200 var _require6 = require('../util/constants'),
2201 eventMap = _require6.eventMap;
2202
2203 var emitter = require('./emitter');
2204
2205 var buildTestQueue = require('./buildTestQueue');
2206
2207 var getError = function getError(E) {
2208 return E.error.stack || E.error;
2209 };
2210
2211 var findSkip = function findSkip(skip, unit) {
2212 var startFailed = skip.findIndex(function (x) {
2213 return x.type === '@start';
2214 });
2215 var everyFailed = skip.findIndex(function (x) {
2216 return x.type === '@every';
2217 });
2218 var beforeFailed = skip.findIndex(function (x) {
2219 return x.description === unit.description;
2220 });
2221 return startFailed !== -1 && 'A start hook failed\n' + getError(skip[startFailed]) || everyFailed !== -1 && 'An every hook failed\n' + getError(skip[everyFailed].error) || beforeFailed !== -1 && 'A before test hook failed\n' + getError(skip[beforeFailed]);
2222 };
2223
2224 var reduceQueue = function reduceQueue(queue) {
2225 return queue.reduce(function (acc, item) {
2226 return Promise.resolve(acc).then(function (acc) {
2227 return Promise.all([last(acc.results), Promise.object(acc.state)]).then(function (_ref2) {
2228 var _ref3 = _slicedToArray(_ref2, 2),
2229 state = _ref3[1];
2230
2231 var toSkip = findSkip(acc.skip, item.unit);
2232 return [toSkip, state];
2233 }).then(function (_ref4) {
2234 var _ref5 = _slicedToArray(_ref4, 2),
2235 toSkip = _ref5[0],
2236 state = _ref5[1];
2237
2238 return toSkip ? {
2239 status: 'skip',
2240 description: toSkip
2241 } : item.unit.run(state);
2242 }).then(function (result) {
2243 var status = result.status,
2244 duration = result.duration;
2245
2246 if (item.type === '@test') {
2247 var resultObject = _objectSpread({
2248 status: status,
2249 duration: duration,
2250 description: item.unit.description
2251 }, (status === 'notOk' || status === 'skip') && {
2252 reason: result.error || result.rejection || result.description
2253 });
2254
2255 emitter.emit(eventMap[status], resultObject);
2256 acc.results.push(resultObject);
2257 } else {
2258 var identifier = item.unit.label || queue.filter(function (i) {
2259 return i.type === item.type;
2260 }).filter(function (i) {
2261 return i.unit.description === item.unit.description;
2262 }).length;
2263 var stateAddition =
2264 /* eslint-disable-next-line */
2265 status === 'ok' ? result.promise ? result.resolve : result.value : null;
2266 if (identifier && stateAddition) assignToObject(acc.state, item.type)(identifier, stateAddition);
2267 }
2268
2269 if (status === 'notOk') {
2270 acc.skip.push({
2271 type: item.type,
2272 description: item.unit.description,
2273 error: result.promise ? result.rejection : result.error
2274 });
2275 }
2276
2277 return acc;
2278 });
2279 });
2280 }, {
2281 results: [],
2282 state: {},
2283 skip: []
2284 });
2285 };
2286 /**
2287 * runs the test suite
2288 * @param {Gunner} instance
2289 * @param {object} options
2290 */
2291
2292
2293 var testrunner = function testrunner(instance) {
2294 var perf = {
2295 start: new Date()
2296 };
2297 return Promise.object(pipe(buildTestQueue, reduceQueue, pick('results'))(instance)).then(function (results) {
2298 perf.end = new Date();
2299 results.end = perf.end.toUTCString();
2300 results.start = perf.start.toUTCString();
2301 results.duration = perf.end - perf.start;
2302 return results;
2303 });
2304 };
2305
2306 module.exports = testrunner;
2307 }, {
2308 "../Gunner": 10,
2309 "../util": 24,
2310 "../util/constants": 23,
2311 "./buildTestQueue": 13,
2312 "./emitter": 15,
2313 "@codefeathers/promise.object": 3
2314 }],
2315 18: [function (require, module, exports) {
2316 var statusMap = {
2317 'ok': ['ok', '✅'],
2318 'notOk': ['notOk', '❌'],
2319 'skip': ['skip', '⚠️']
2320 };
2321
2322 var convert = function convert(x) {
2323 return x;
2324 };
2325
2326 var Default = function Default(runner, options) {
2327 runner.on('start', function () {
2328 return console.log('Started tests');
2329 });
2330 runner.on('test end', function (results) {
2331 results.forEach(function (x) {
2332 var s = statusMap[x.status];
2333 console.log('>', s[0], s[1], x.description);
2334 options.trace && x.reason && console.log('\n---\n\n', x.reason, '\n\n---\n');
2335 });
2336 });
2337 runner.on('end', function (results) {
2338 console.log(results.success.length, 'tests of', results.length, 'passed');
2339 console.log('Success ratio:', results.successPercent, '%');
2340 });
2341 };
2342
2343 module.exports = Default;
2344 module.exports.convert = convert;
2345 }, {}],
2346 19: [function (require, module, exports) {
2347 var def = require('./default');
2348
2349 var tap = require('./tap');
2350
2351 var xunit = require('./xunit');
2352
2353 var min = require('./min');
2354
2355 module.exports = {
2356 default: def,
2357 tap: tap,
2358 xunit: xunit,
2359 min: min
2360 };
2361 }, {
2362 "./default": 18,
2363 "./min": 20,
2364 "./tap": 21,
2365 "./xunit": 22
2366 }],
2367 20: [function (require, module, exports) {
2368 var _require7 = require('../util/constants'),
2369 eventMap = _require7.eventMap,
2370 eventVerbs = _require7.eventVerbs;
2371
2372 var _require8 = require('../util/nodeutils'),
2373 clear = _require8.clear;
2374
2375 var convert = function convert(x) {
2376 return x;
2377 };
2378
2379 var count = {
2380 pass: 0,
2381 fail: 0,
2382 skip: 0,
2383 collapse: function collapse() {
2384 return this.pass + this.fail + this.skip;
2385 }
2386 };
2387
2388 var doneHandler = function doneHandler(event) {
2389 clear();
2390 var mapEvent = eventMap[event.status];
2391 count[mapEvent]++;
2392 console.log("".concat(count[mapEvent], " tests ").concat(eventVerbs[mapEvent][2]) + " (total: ".concat(count.collapse(), ")"));
2393 };
2394
2395 var Min = function Min(runner) {
2396 runner.on('start', function () {
2397 return console.log('Started tests');
2398 });
2399 runner.on('pass', doneHandler);
2400 runner.on('fail', doneHandler);
2401 runner.on('skip', doneHandler);
2402 runner.on('end', function (results) {
2403 clear();
2404 console.log("Test suite ".concat(results.name, " has done running."));
2405 console.log('Success ratio:', results.successPercent, '%');
2406 });
2407 };
2408
2409 module.exports = Min;
2410 module.exports.convert = convert;
2411 }, {
2412 "../util/constants": 23,
2413 "../util/nodeutils": 25
2414 }],
2415 21: [function (require, module, exports) {
2416 var statusMap = {
2417 'ok': 'ok',
2418 'notOk': 'not ok',
2419 'skip': 'skip'
2420 };
2421
2422 var convert = function convert(results, options) {
2423 return "\nTAP version 13\n".concat(results.length ? '1' : 0, "..").concat(results.length, "\n").concat(results.map(function (r, i) {
2424 var status = statusMap[r.status];
2425 var message = options.trace && r.reason && (r.reason.stack ? r.reason.stack : r.reason) || '';
2426 return "".concat(status, " ").concat(i + 1, " - ").concat(r.description) + (message && '\n ---\n message: |\n ' + message + '\n ---\n');
2427 }).join('\n'), "\n");
2428 };
2429
2430 var TAP = function TAP(runner, options) {
2431 runner.on('end', function (results) {
2432 return console.log(convert(results, options));
2433 });
2434 };
2435
2436 module.exports = TAP;
2437 module.exports.convert = convert;
2438 }, {}],
2439 22: [function (require, module, exports) {
2440 var toXML = require('jsontoxml');
2441
2442 var _require9 = require('../util/nodeutils'),
2443 clear = _require9.clear;
2444
2445 var escapeXML = function escapeXML(str) {
2446 return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
2447 };
2448
2449 var toJSON = function toJSON(resultsArray) {
2450 return {
2451 testsuites: resultsArray.map(function (results) {
2452 var name = results.name,
2453 count = results.count,
2454 success = results.success,
2455 failures = results.failures,
2456 skipped = results.skipped;
2457 return {
2458 name: 'testsuite',
2459 attrs: {
2460 name: escapeXML(name),
2461 tests: count,
2462 success: success.length,
2463 failures: failures.length,
2464 skipped: skipped.length,
2465 timestamp: new Date().toUTCString(),
2466 time: results.duration / 1000 || 0
2467 },
2468 children: results.reduce(function (acc, r) {
2469 var reason = r.reason ? r.reason.stack || r.reason : '';
2470 var content = r.status !== 'ok' && {
2471 name: r.status === 'skip' ? 'skipped' : 'failure',
2472 text: escapeXML(reason)
2473 };
2474 acc.push(_objectSpread({
2475 name: 'testcase',
2476 attrs: {
2477 name: escapeXML(r.description),
2478 time: r.duration / 1000 || 0
2479 }
2480 }, _typeof2(content) === 'object' && {
2481 children: [content]
2482 }));
2483 return acc;
2484 }, [])
2485 };
2486 })
2487 };
2488 };
2489
2490 var convert = function convert(results) {
2491 return toXML(toJSON(results), {
2492 xmlHeader: {
2493 standalone: true
2494 }
2495 });
2496 };
2497
2498 var xunit = function xunit(runner) {
2499 return runner.on("end", function (results) {
2500 return clear(), console.log(convert([results]));
2501 });
2502 };
2503
2504 module.exports = xunit;
2505 module.exports.convert = convert;
2506 }, {
2507 "../util/nodeutils": 25,
2508 "jsontoxml": 7
2509 }],
2510 23: [function (require, module, exports) {
2511 var _require10 = require('os'),
2512 EOL = _require10.EOL;
2513
2514 module.exports = {
2515 EOL: EOL,
2516 eventMap: {
2517 'ok': 'pass',
2518 'notOk': 'fail',
2519 'skip': 'skip'
2520 },
2521 eventVerbs: {
2522 pass: ['pass', 'passing', 'passed'],
2523 fail: ['fail', 'failing', 'failed'],
2524 skip: ['skip', 'skipping', 'skipped']
2525 }
2526 };
2527 }, {
2528 "os": 8
2529 }],
2530 24: [function (require, module, exports) {
2531 var _stringify = require('json-stringify-safe');
2532
2533 var isObject = function isObject(x) {
2534 return x && _typeof2(x) === 'object';
2535 };
2536
2537 var stringify = function stringify(obj) {
2538 return isObject(obj) ? obj.stack || _stringify(obj) : obj;
2539 };
2540
2541 var deepFlatten = function deepFlatten(arr) {
2542 var _ref6;
2543
2544 return (_ref6 = []).concat.apply(_ref6, _toConsumableArray2(arr.map(function (v) {
2545 return Array.isArray(v) ? deepFlatten(v) : v;
2546 })));
2547 };
2548 /* Returns true if a promise is passed */
2549
2550
2551 var isPromise = function isPromise(prom) {
2552 return prom && typeof prom.then === 'function';
2553 };
2554 /* Lift a value or promise into a function */
2555
2556
2557 var liftPromise = function liftPromise(fn, thing) {
2558 return isPromise(thing) ? thing.then(fn) : fn(thing);
2559 };
2560
2561 module.exports = {
2562 /* Returns true if an object is passed */
2563 isObject: isObject,
2564
2565 /* Returns true if a promise is passed */
2566 isPromise: isPromise,
2567
2568 /* Lift a value or promise into a function */
2569 liftPromise: liftPromise,
2570
2571 /* Returns the element found at the given path or undefined */
2572 path: function path(obj) {
2573 return function (path) {
2574 return path.reduce(function (result, segment) {
2575 return result && result[segment];
2576 }, obj);
2577 };
2578 },
2579
2580 /* Picks a key from an object */
2581 pick: function pick(key) {
2582 return function (obj) {
2583 return obj[key];
2584 };
2585 },
2586
2587 /* Pipe a value or promise through any number of unary functions */
2588 pipe: function pipe() {
2589 for (var _len6 = arguments.length, fns = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
2590 fns[_key6] = arguments[_key6];
2591 }
2592
2593 return function (arg) {
2594 return fns.reduce(function (acc, fn) {
2595 return liftPromise(fn, acc);
2596 }, arg);
2597 };
2598 },
2599
2600 /* Reduces an array */
2601 reduce: function reduce(fn, def) {
2602 return function (arr) {
2603 return arr.reduce(fn, def);
2604 };
2605 },
2606
2607 /* Flattens an array of arrays to an array */
2608 flatten: function flatten(arrData) {
2609 return [].concat.apply([], arrData);
2610 },
2611
2612 /* Deep flattens arrays */
2613 deepFlatten: deepFlatten,
2614
2615 /* Maps a function over an array */
2616 map: function map(fn) {
2617 return function (x) {
2618 return x.map(fn);
2619 };
2620 },
2621
2622 /* Filter an array using provided function */
2623 filter: function filter(fn) {
2624 return function (x) {
2625 return x.filter(fn);
2626 };
2627 },
2628
2629 /* Returns identity */
2630 identity: function identity(x) {
2631 return x;
2632 },
2633
2634 /* Wraps a value in an object with given key */
2635 wrapWith: function wrapWith(x) {
2636 return function (y) {
2637 return _defineProperty2({}, x, y);
2638 };
2639 },
2640
2641 /* Unwraps a value from an object with given key */
2642 unwrapFrom: function unwrapFrom(x) {
2643 return function (y) {
2644 return y[x];
2645 };
2646 },
2647
2648 /* Resolves an array of Promises */
2649 promiseAll: function promiseAll(x) {
2650 return Promise.all(x);
2651 },
2652
2653 /* Pass partial arguments and return a function that accepts the rest */
2654 partial: function partial(fn) {
2655 for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
2656 args[_key7 - 1] = arguments[_key7];
2657 }
2658
2659 return function () {
2660 for (var _len8 = arguments.length, rest = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
2661 rest[_key8] = arguments[_key8];
2662 }
2663
2664 return fn.apply(void 0, args.concat(rest));
2665 };
2666 },
2667
2668 /* Item is in collection */
2669 isIn: function isIn(collection, item) {
2670 return collection.indexOf(item) !== -1;
2671 },
2672
2673 /* Collection contains given path */
2674 containsPath: function containsPath(collection, path) {
2675 return collection.some(function (x) {
2676 return path.match(new RegExp("/".concat(x, "/?$")));
2677 });
2678 },
2679
2680 /* Stringifies object or coerces to string */
2681 stringify: stringify,
2682
2683 /* Tagged Stringify */
2684 taggedStringify: function taggedStringify(strings) {
2685 for (var _len9 = arguments.length, expr = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) {
2686 expr[_key9 - 1] = arguments[_key9];
2687 }
2688
2689 return strings.reduce(function (acc, curr, i) {
2690 return acc + curr + (stringify(expr[i]) || '');
2691 }, '');
2692 },
2693
2694 /* Short circuits with given value on pred. Else calls function */
2695 short: function short(pred, shorter) {
2696 return function (fn) {
2697 return function (value) {
2698 return pred(value) ? shorter(value) : fn(value);
2699 };
2700 };
2701 },
2702
2703 /* Check if object has given property */
2704 hasProp: function hasProp(obj) {
2705 return function (prop) {
2706 return prop in obj;
2707 };
2708 },
2709
2710 /* Fetches last element from list */
2711 last: function last(arr) {
2712 return arr[arr.length - 1];
2713 },
2714
2715 /* Uppercases first letter of word */
2716 upperCaseFirstLetter: function upperCaseFirstLetter(word) {
2717 return word[0].toUpperCase() + word.slice(1);
2718 },
2719
2720 /* Lowercases first letter of word */
2721 lowerCaseFirstLetter: function lowerCaseFirstLetter(word) {
2722 return word[0].toLowerCase() + word.slice(1);
2723 },
2724
2725 /* Creates an array or pushes to an existing one */
2726 arrayOrPush: function arrayOrPush(obj, key, item) {
2727 return Array.isArray(obj[key]) ? obj[key].push(item) : obj[key] = [item];
2728 },
2729
2730 /* Assigns to key or creates a new object */
2731 assignToObject: function assignToObject(obj, path) {
2732 return function (key, value) {
2733 return isObject(obj[path]) ? obj[path][key] = value : obj[path] = _defineProperty2({}, key, value);
2734 };
2735 }
2736 };
2737 }, {
2738 "json-stringify-safe": 6
2739 }],
2740 25: [function (require, module, exports) {
2741 (function (global) {
2742 module.exports = {
2743 clear: function clear() {
2744 if (typeof global === 'undefined' || typeof global.process === 'undefined' || typeof global.process.stdout === 'undefined') return;
2745 var process = global.process; // clear screen
2746
2747 process.stdout.write("\x1B[2J"); // set cursor position to top
2748
2749 process.stdout.write("\x1B[1;1H");
2750 }
2751 };
2752 }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
2753 }, {}],
2754 26: [function (require, module, exports) {
2755 module.exports = {
2756 Start: Symbol('Start'),
2757 End: Symbol('End'),
2758 expect: Symbol('expect'),
2759 pass: 'pass',
2760 fail: 'fail'
2761 };
2762 }, {}]
2763 }, {}, [1])(1);
2764});