From 668a053e653a703d48221c398a01658b271d656d Mon Sep 17 00:00:00 2001 From: Slavcho Slavchev Date: Tue, 2 Aug 2016 18:48:30 +0300 Subject: [PATCH] Fix infinite request cycle --- dist/barometer-test.js | 11367 +++++++++++++++++++-------------------- dist/barometer.min.js | 7 +- lib/transport.js | 4 +- 3 files changed, 5538 insertions(+), 5840 deletions(-) diff --git a/dist/barometer-test.js b/dist/barometer-test.js index cfbd02f..fcf25db 100644 --- a/dist/barometer-test.js +++ b/dist/barometer-test.js @@ -247,7 +247,6 @@ pageResources.initialise() 'use strict' var transport = module.exports = {} -var xhrStats = require('./xhrStats') var barometer = require('./barometer.js') transport.url = 'XXXXX' @@ -258,6 +257,7 @@ transport._initialiseBuffer = function () { counters: { } } transport.bufferSize = 0 + transport.requestCount = 0 } transport._initialiseBuffer() @@ -266,6 +266,7 @@ transport.count = function (metric) { transport.buffer.counters[metric]++ transport._triggerFlushBuffer() transport.bufferSize++ + transport.requestCount++ if (window.barometer.debug) console.log('count', metric) } @@ -286,7 +287,7 @@ transport._triggerFlushBuffer = function () { } transport._flushBuffer = function (pageEnd) { - if (transport.bufferSize === 0) return + if (transport.bufferSize === 0 || transport.requestCount === 1) return if (!barometer.url) return if (bufferFlush) { @@ -310,7 +311,7 @@ transport._flushBuffer = function (pageEnd) { } } -},{"./barometer.js":1,"./xhrStats":8}],7:[function(require,module,exports){ +},{"./barometer.js":1}],7:[function(require,module,exports){ 'use strict' module.exports = function (href, hash) { var safeUrl = (href || '').split('?')[0].replace(/^https?:\/\//i, '').replace(/[^a-z0-9-\/]/gi, '_') @@ -771,7 +772,224 @@ var objectKeys = Object.keys || function (obj) { return keys; }; -},{"util/":13}],10:[function(require,module,exports){ +},{"util/":41}],10:[function(require,module,exports){ +(function (global){ +((typeof define === "function" && define.amd && function (m) { + define("formatio", ["samsam"], m); +}) || (typeof module === "object" && function (m) { + module.exports = m(require("samsam")); +}) || function (m) { this.formatio = m(this.samsam); } +)(function (samsam) { + "use strict"; + + var formatio = { + excludeConstructors: ["Object", /^.$/], + quoteStrings: true, + limitChildrenCount: 0 + }; + + var hasOwn = Object.prototype.hasOwnProperty; + + var specialObjects = []; + if (typeof global !== "undefined") { + specialObjects.push({ object: global, value: "[object global]" }); + } + if (typeof document !== "undefined") { + specialObjects.push({ + object: document, + value: "[object HTMLDocument]" + }); + } + if (typeof window !== "undefined") { + specialObjects.push({ object: window, value: "[object Window]" }); + } + + function functionName(func) { + if (!func) { return ""; } + if (func.displayName) { return func.displayName; } + if (func.name) { return func.name; } + var matches = func.toString().match(/function\s+([^\(]+)/m); + return (matches && matches[1]) || ""; + } + + function constructorName(f, object) { + var name = functionName(object && object.constructor); + var excludes = f.excludeConstructors || + formatio.excludeConstructors || []; + + var i, l; + for (i = 0, l = excludes.length; i < l; ++i) { + if (typeof excludes[i] === "string" && excludes[i] === name) { + return ""; + } else if (excludes[i].test && excludes[i].test(name)) { + return ""; + } + } + + return name; + } + + function isCircular(object, objects) { + if (typeof object !== "object") { return false; } + var i, l; + for (i = 0, l = objects.length; i < l; ++i) { + if (objects[i] === object) { return true; } + } + return false; + } + + function ascii(f, object, processed, indent) { + if (typeof object === "string") { + var qs = f.quoteStrings; + var quote = typeof qs !== "boolean" || qs; + return processed || quote ? '"' + object + '"' : object; + } + + if (typeof object === "function" && !(object instanceof RegExp)) { + return ascii.func(object); + } + + processed = processed || []; + + if (isCircular(object, processed)) { return "[Circular]"; } + + if (Object.prototype.toString.call(object) === "[object Array]") { + return ascii.array.call(f, object, processed); + } + + if (!object) { return String((1/object) === -Infinity ? "-0" : object); } + if (samsam.isElement(object)) { return ascii.element(object); } + + if (typeof object.toString === "function" && + object.toString !== Object.prototype.toString) { + return object.toString(); + } + + var i, l; + for (i = 0, l = specialObjects.length; i < l; i++) { + if (object === specialObjects[i].object) { + return specialObjects[i].value; + } + } + + return ascii.object.call(f, object, processed, indent); + } + + ascii.func = function (func) { + return "function " + functionName(func) + "() {}"; + }; + + ascii.array = function (array, processed) { + processed = processed || []; + processed.push(array); + var pieces = []; + var i, l; + l = (this.limitChildrenCount > 0) ? + Math.min(this.limitChildrenCount, array.length) : array.length; + + for (i = 0; i < l; ++i) { + pieces.push(ascii(this, array[i], processed)); + } + + if(l < array.length) + pieces.push("[... " + (array.length - l) + " more elements]"); + + return "[" + pieces.join(", ") + "]"; + }; + + ascii.object = function (object, processed, indent) { + processed = processed || []; + processed.push(object); + indent = indent || 0; + var pieces = [], properties = samsam.keys(object).sort(); + var length = 3; + var prop, str, obj, i, k, l; + l = (this.limitChildrenCount > 0) ? + Math.min(this.limitChildrenCount, properties.length) : properties.length; + + for (i = 0; i < l; ++i) { + prop = properties[i]; + obj = object[prop]; + + if (isCircular(obj, processed)) { + str = "[Circular]"; + } else { + str = ascii(this, obj, processed, indent + 2); + } + + str = (/\s/.test(prop) ? '"' + prop + '"' : prop) + ": " + str; + length += str.length; + pieces.push(str); + } + + var cons = constructorName(this, object); + var prefix = cons ? "[" + cons + "] " : ""; + var is = ""; + for (i = 0, k = indent; i < k; ++i) { is += " "; } + + if(l < properties.length) + pieces.push("[... " + (properties.length - l) + " more elements]"); + + if (length + indent > 80) { + return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" + + is + "}"; + } + return prefix + "{ " + pieces.join(", ") + " }"; + }; + + ascii.element = function (element) { + var tagName = element.tagName.toLowerCase(); + var attrs = element.attributes, attr, pairs = [], attrName, i, l, val; + + for (i = 0, l = attrs.length; i < l; ++i) { + attr = attrs.item(i); + attrName = attr.nodeName.toLowerCase().replace("html:", ""); + val = attr.nodeValue; + if (attrName !== "contenteditable" || val !== "inherit") { + if (!!val) { pairs.push(attrName + "=\"" + val + "\""); } + } + } + + var formatted = "<" + tagName + (pairs.length > 0 ? " " : ""); + var content = element.innerHTML; + + if (content.length > 20) { + content = content.substr(0, 20) + "[...]"; + } + + var res = formatted + pairs.join(" ") + ">" + content + + ""; + + return res.replace(/ contentEditable="inherit"/, ""); + }; + + function Formatio(options) { + for (var opt in options) { + this[opt] = options[opt]; + } + } + + Formatio.prototype = { + functionName: functionName, + + configure: function (options) { + return new Formatio(options); + }, + + constructorName: function (object) { + return constructorName(this, object); + }, + + ascii: function (object, processed, indent) { + return ascii(this, object, processed, indent); + } + }; + + return Formatio.prototype; +}); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"samsam":14}],11:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -796,687 +1014,578 @@ if (typeof Object.create === 'function') { } } -},{}],11:[function(require,module,exports){ -// shim for using process in browser +},{}],12:[function(require,module,exports){ +(function (global){ +/*global global, window*/ +/** + * @author Christian Johansen (christian@cjohansen.no) and contributors + * @license BSD + * + * Copyright (c) 2010-2014 Christian Johansen + */ -var process = module.exports = {}; +(function (global) { + "use strict"; -// cached from whatever global is present so that test runners that stub it -// don't break things. But we need to wrap it in a try catch in case it is -// wrapped in strict mode code which doesn't define any globals. It's inside a -// function because try/catches deoptimize in certain engines. + // Make properties writable in IE, as per + // http://www.adequatelygood.com/Replacing-setTimeout-Globally.html + // JSLint being anal + var glbl = global; -var cachedSetTimeout; -var cachedClearTimeout; + global.setTimeout = glbl.setTimeout; + global.clearTimeout = glbl.clearTimeout; + global.setInterval = glbl.setInterval; + global.clearInterval = glbl.clearInterval; + global.Date = glbl.Date; -(function () { - try { - cachedSetTimeout = setTimeout; - } catch (e) { - cachedSetTimeout = function () { - throw new Error('setTimeout is not defined'); + // setImmediate is not a standard function + // avoid adding the prop to the window object if not present + if('setImmediate' in global) { + global.setImmediate = glbl.setImmediate; + global.clearImmediate = glbl.clearImmediate; } - } - try { - cachedClearTimeout = clearTimeout; - } catch (e) { - cachedClearTimeout = function () { - throw new Error('clearTimeout is not defined'); - } - } -} ()) -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; -function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } -} + // node expects setTimeout/setInterval to return a fn object w/ .ref()/.unref() + // browsers, a number. + // see https://github.com/cjohansen/Sinon.JS/pull/436 -function drainQueue() { - if (draining) { - return; - } - var timeout = cachedSetTimeout.call(null, cleanUpNextTick); - draining = true; + var NOOP = function () { return undefined; }; + var timeoutResult = setTimeout(NOOP, 0); + var addTimerReturnsObject = typeof timeoutResult === "object"; + clearTimeout(timeoutResult); - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - cachedClearTimeout.call(null, timeout); -} + var NativeDate = Date; + var uniqueTimerId = 1; -process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; + /** + * Parse strings like "01:10:00" (meaning 1 hour, 10 minutes, 0 seconds) into + * number of milliseconds. This is used to support human-readable strings passed + * to clock.tick() + */ + function parseTime(str) { + if (!str) { + return 0; } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - cachedSetTimeout.call(null, drainQueue, 0); - } -}; - -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; -} -Item.prototype.run = function () { - this.fun.apply(null, this.array); -}; -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; -process.version = ''; // empty string to avoid regexp issues -process.versions = {}; -function noop() {} + var strings = str.split(":"); + var l = strings.length, i = l; + var ms = 0, parsed; -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; + if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) { + throw new Error("tick only understands numbers and 'h:m:s'"); + } -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; + while (i--) { + parsed = parseInt(strings[i], 10); -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; + if (parsed >= 60) { + throw new Error("Invalid time " + str); + } -},{}],12:[function(require,module,exports){ -module.exports = function isBuffer(arg) { - return arg && typeof arg === 'object' - && typeof arg.copy === 'function' - && typeof arg.fill === 'function' - && typeof arg.readUInt8 === 'function'; -} -},{}],13:[function(require,module,exports){ -(function (process,global){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. + ms += parsed * Math.pow(60, (l - i - 1)); + } -var formatRegExp = /%[sdj%]/g; -exports.format = function(f) { - if (!isString(f)) { - var objects = []; - for (var i = 0; i < arguments.length; i++) { - objects.push(inspect(arguments[i])); + return ms * 1000; } - return objects.join(' '); - } - var i = 1; - var args = arguments; - var len = args.length; - var str = String(f).replace(formatRegExp, function(x) { - if (x === '%%') return '%'; - if (i >= len) return x; - switch (x) { - case '%s': return String(args[i++]); - case '%d': return Number(args[i++]); - case '%j': - try { - return JSON.stringify(args[i++]); - } catch (_) { - return '[Circular]'; - } - default: - return x; - } - }); - for (var x = args[i]; i < len; x = args[++i]) { - if (isNull(x) || !isObject(x)) { - str += ' ' + x; - } else { - str += ' ' + inspect(x); + /** + * Used to grok the `now` parameter to createClock. + */ + function getEpoch(epoch) { + if (!epoch) { return 0; } + if (typeof epoch.getTime === "function") { return epoch.getTime(); } + if (typeof epoch === "number") { return epoch; } + throw new TypeError("now should be milliseconds since UNIX epoch"); } - } - return str; -}; + function inRange(from, to, timer) { + return timer && timer.callAt >= from && timer.callAt <= to; + } -// Mark that a method should not be used. -// Returns a modified function which warns once by default. -// If --no-deprecation is set, then it is a no-op. -exports.deprecate = function(fn, msg) { - // Allow for deprecating things in the process of starting up. - if (isUndefined(global.process)) { - return function() { - return exports.deprecate(fn, msg).apply(this, arguments); - }; - } + function mirrorDateProperties(target, source) { + var prop; + for (prop in source) { + if (source.hasOwnProperty(prop)) { + target[prop] = source[prop]; + } + } - if (process.noDeprecation === true) { - return fn; - } + // set special now implementation + if (source.now) { + target.now = function now() { + return target.clock.now; + }; + } else { + delete target.now; + } - var warned = false; - function deprecated() { - if (!warned) { - if (process.throwDeprecation) { - throw new Error(msg); - } else if (process.traceDeprecation) { - console.trace(msg); - } else { - console.error(msg); - } - warned = true; - } - return fn.apply(this, arguments); - } + // set special toSource implementation + if (source.toSource) { + target.toSource = function toSource() { + return source.toSource(); + }; + } else { + delete target.toSource; + } - return deprecated; -}; + // set special toString implementation + target.toString = function toString() { + return source.toString(); + }; + target.prototype = source.prototype; + target.parse = source.parse; + target.UTC = source.UTC; + target.prototype.toUTCString = source.prototype.toUTCString; -var debugs = {}; -var debugEnviron; -exports.debuglog = function(set) { - if (isUndefined(debugEnviron)) - debugEnviron = process.env.NODE_DEBUG || ''; - set = set.toUpperCase(); - if (!debugs[set]) { - if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { - var pid = process.pid; - debugs[set] = function() { - var msg = exports.format.apply(exports, arguments); - console.error('%s %d: %s', set, pid, msg); - }; - } else { - debugs[set] = function() {}; + return target; } - } - return debugs[set]; -}; - - -/** - * Echos the value of a value. Trys to print the value out - * in the best way possible given the different types. - * - * @param {Object} obj The object to print out. - * @param {Object} opts Optional options object that alters the output. - */ -/* legacy: obj, showHidden, depth, colors*/ -function inspect(obj, opts) { - // default options - var ctx = { - seen: [], - stylize: stylizeNoColor - }; - // legacy... - if (arguments.length >= 3) ctx.depth = arguments[2]; - if (arguments.length >= 4) ctx.colors = arguments[3]; - if (isBoolean(opts)) { - // legacy... - ctx.showHidden = opts; - } else if (opts) { - // got an "options" object - exports._extend(ctx, opts); - } - // set default options - if (isUndefined(ctx.showHidden)) ctx.showHidden = false; - if (isUndefined(ctx.depth)) ctx.depth = 2; - if (isUndefined(ctx.colors)) ctx.colors = false; - if (isUndefined(ctx.customInspect)) ctx.customInspect = true; - if (ctx.colors) ctx.stylize = stylizeWithColor; - return formatValue(ctx, obj, ctx.depth); -} -exports.inspect = inspect; + function createDate() { + function ClockDate(year, month, date, hour, minute, second, ms) { + // Defensive and verbose to avoid potential harm in passing + // explicit undefined when user does not pass argument + switch (arguments.length) { + case 0: + return new NativeDate(ClockDate.clock.now); + case 1: + return new NativeDate(year); + case 2: + return new NativeDate(year, month); + case 3: + return new NativeDate(year, month, date); + case 4: + return new NativeDate(year, month, date, hour); + case 5: + return new NativeDate(year, month, date, hour, minute); + case 6: + return new NativeDate(year, month, date, hour, minute, second); + default: + return new NativeDate(year, month, date, hour, minute, second, ms); + } + } -// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics -inspect.colors = { - 'bold' : [1, 22], - 'italic' : [3, 23], - 'underline' : [4, 24], - 'inverse' : [7, 27], - 'white' : [37, 39], - 'grey' : [90, 39], - 'black' : [30, 39], - 'blue' : [34, 39], - 'cyan' : [36, 39], - 'green' : [32, 39], - 'magenta' : [35, 39], - 'red' : [31, 39], - 'yellow' : [33, 39] -}; + return mirrorDateProperties(ClockDate, NativeDate); + } -// Don't use 'blue' not visible on cmd.exe -inspect.styles = { - 'special': 'cyan', - 'number': 'yellow', - 'boolean': 'yellow', - 'undefined': 'grey', - 'null': 'bold', - 'string': 'green', - 'date': 'magenta', - // "name": intentionally not styling - 'regexp': 'red' -}; + function addTimer(clock, timer) { + if (timer.func === undefined) { + throw new Error("Callback must be provided to timer calls"); + } + if (!clock.timers) { + clock.timers = {}; + } -function stylizeWithColor(str, styleType) { - var style = inspect.styles[styleType]; + timer.id = uniqueTimerId++; + timer.createdAt = clock.now; + timer.callAt = clock.now + (timer.delay || (clock.duringTick ? 1 : 0)); - if (style) { - return '\u001b[' + inspect.colors[style][0] + 'm' + str + - '\u001b[' + inspect.colors[style][1] + 'm'; - } else { - return str; - } -} + clock.timers[timer.id] = timer; + if (addTimerReturnsObject) { + return { + id: timer.id, + ref: NOOP, + unref: NOOP + }; + } -function stylizeNoColor(str, styleType) { - return str; -} + return timer.id; + } -function arrayToHash(array) { - var hash = {}; + function compareTimers(a, b) { + // Sort first by absolute timing + if (a.callAt < b.callAt) { + return -1; + } + if (a.callAt > b.callAt) { + return 1; + } - array.forEach(function(val, idx) { - hash[val] = true; - }); + // Sort next by immediate, immediate timers take precedence + if (a.immediate && !b.immediate) { + return -1; + } + if (!a.immediate && b.immediate) { + return 1; + } - return hash; -} + // Sort next by creation time, earlier-created timers take precedence + if (a.createdAt < b.createdAt) { + return -1; + } + if (a.createdAt > b.createdAt) { + return 1; + } + // Sort next by id, lower-id timers take precedence + if (a.id < b.id) { + return -1; + } + if (a.id > b.id) { + return 1; + } -function formatValue(ctx, value, recurseTimes) { - // Provide a hook for user-specified inspect functions. - // Check that value is an object with an inspect function on it - if (ctx.customInspect && - value && - isFunction(value.inspect) && - // Filter out the util module, it's inspect function is special - value.inspect !== exports.inspect && - // Also filter out any prototype objects using the circular check. - !(value.constructor && value.constructor.prototype === value)) { - var ret = value.inspect(recurseTimes, ctx); - if (!isString(ret)) { - ret = formatValue(ctx, ret, recurseTimes); + // As timer ids are unique, no fallback `0` is necessary } - return ret; - } - - // Primitive types cannot have properties - var primitive = formatPrimitive(ctx, value); - if (primitive) { - return primitive; - } - // Look up the keys of the object. - var keys = Object.keys(value); - var visibleKeys = arrayToHash(keys); + function firstTimerInRange(clock, from, to) { + var timers = clock.timers, + timer = null, + id, + isInRange; - if (ctx.showHidden) { - keys = Object.getOwnPropertyNames(value); - } + for (id in timers) { + if (timers.hasOwnProperty(id)) { + isInRange = inRange(from, to, timers[id]); - // IE doesn't make error fields non-enumerable - // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx - if (isError(value) - && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { - return formatError(value); - } + if (isInRange && (!timer || compareTimers(timer, timers[id]) === 1)) { + timer = timers[id]; + } + } + } - // Some type of object without properties can be shortcutted. - if (keys.length === 0) { - if (isFunction(value)) { - var name = value.name ? ': ' + value.name : ''; - return ctx.stylize('[Function' + name + ']', 'special'); - } - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); - } - if (isDate(value)) { - return ctx.stylize(Date.prototype.toString.call(value), 'date'); - } - if (isError(value)) { - return formatError(value); + return timer; } - } - var base = '', array = false, braces = ['{', '}']; + function callTimer(clock, timer) { + var exception; - // Make Array say that they are Array - if (isArray(value)) { - array = true; - braces = ['[', ']']; - } + if (typeof timer.interval === "number") { + clock.timers[timer.id].callAt += timer.interval; + } else { + delete clock.timers[timer.id]; + } - // Make functions say that they are functions - if (isFunction(value)) { - var n = value.name ? ': ' + value.name : ''; - base = ' [Function' + n + ']'; - } - - // Make RegExps say that they are RegExps - if (isRegExp(value)) { - base = ' ' + RegExp.prototype.toString.call(value); - } - - // Make dates with properties first say the date - if (isDate(value)) { - base = ' ' + Date.prototype.toUTCString.call(value); - } - - // Make error with message first say the error - if (isError(value)) { - base = ' ' + formatError(value); - } + try { + if (typeof timer.func === "function") { + timer.func.apply(null, timer.args); + } else { + eval(timer.func); + } + } catch (e) { + exception = e; + } - if (keys.length === 0 && (!array || value.length == 0)) { - return braces[0] + base + braces[1]; - } + if (!clock.timers[timer.id]) { + if (exception) { + throw exception; + } + return; + } - if (recurseTimes < 0) { - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); - } else { - return ctx.stylize('[Object]', 'special'); + if (exception) { + throw exception; + } } - } - - ctx.seen.push(value); - var output; - if (array) { - output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); - } else { - output = keys.map(function(key) { - return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); - }); - } + function timerType(timer) { + if (timer.immediate) { + return "Immediate"; + } else if (typeof timer.interval !== "undefined") { + return "Interval"; + } else { + return "Timeout"; + } + } - ctx.seen.pop(); + function clearTimer(clock, timerId, ttype) { + if (!timerId) { + // null appears to be allowed in most browsers, and appears to be + // relied upon by some libraries, like Bootstrap carousel + return; + } - return reduceToSingleString(output, base, braces); -} + if (!clock.timers) { + clock.timers = []; + } + // in Node, timerId is an object with .ref()/.unref(), and + // its .id field is the actual timer id. + if (typeof timerId === "object") { + timerId = timerId.id; + } -function formatPrimitive(ctx, value) { - if (isUndefined(value)) - return ctx.stylize('undefined', 'undefined'); - if (isString(value)) { - var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') - .replace(/'/g, "\\'") - .replace(/\\"/g, '"') + '\''; - return ctx.stylize(simple, 'string'); - } - if (isNumber(value)) - return ctx.stylize('' + value, 'number'); - if (isBoolean(value)) - return ctx.stylize('' + value, 'boolean'); - // For some reason typeof null is "object", so special case here. - if (isNull(value)) - return ctx.stylize('null', 'null'); -} + if (clock.timers.hasOwnProperty(timerId)) { + // check that the ID matches a timer of the correct type + var timer = clock.timers[timerId]; + if (timerType(timer) === ttype) { + delete clock.timers[timerId]; + } else { + throw new Error("Cannot clear timer: timer created with set" + ttype + "() but cleared with clear" + timerType(timer) + "()"); + } + } + } + function uninstall(clock, target) { + var method, + i, + l; -function formatError(value) { - return '[' + Error.prototype.toString.call(value) + ']'; -} + for (i = 0, l = clock.methods.length; i < l; i++) { + method = clock.methods[i]; + if (target[method].hadOwnProperty) { + target[method] = clock["_" + method]; + } else { + try { + delete target[method]; + } catch (ignore) {} + } + } -function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { - var output = []; - for (var i = 0, l = value.length; i < l; ++i) { - if (hasOwnProperty(value, String(i))) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - String(i), true)); - } else { - output.push(''); - } - } - keys.forEach(function(key) { - if (!key.match(/^\d+$/)) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, true)); + // Prevent multiple executions which will completely remove these props + clock.methods = []; } - }); - return output; -} + function hijackMethod(target, method, clock) { + var prop; -function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { - var name, str, desc; - desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; - if (desc.get) { - if (desc.set) { - str = ctx.stylize('[Getter/Setter]', 'special'); - } else { - str = ctx.stylize('[Getter]', 'special'); - } - } else { - if (desc.set) { - str = ctx.stylize('[Setter]', 'special'); - } - } - if (!hasOwnProperty(visibleKeys, key)) { - name = '[' + key + ']'; - } - if (!str) { - if (ctx.seen.indexOf(desc.value) < 0) { - if (isNull(recurseTimes)) { - str = formatValue(ctx, desc.value, null); - } else { - str = formatValue(ctx, desc.value, recurseTimes - 1); - } - if (str.indexOf('\n') > -1) { - if (array) { - str = str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n').substr(2); + clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(target, method); + clock["_" + method] = target[method]; + + if (method === "Date") { + var date = mirrorDateProperties(clock[method], target[method]); + target[method] = date; } else { - str = '\n' + str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n'); + target[method] = function () { + return clock[method].apply(clock, arguments); + }; + + for (prop in clock[method]) { + if (clock[method].hasOwnProperty(prop)) { + target[method][prop] = clock[method][prop]; + } + } } - } - } else { - str = ctx.stylize('[Circular]', 'special'); - } - } - if (isUndefined(name)) { - if (array && key.match(/^\d+$/)) { - return str; - } - name = JSON.stringify('' + key); - if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { - name = name.substr(1, name.length - 2); - name = ctx.stylize(name, 'name'); - } else { - name = name.replace(/'/g, "\\'") - .replace(/\\"/g, '"') - .replace(/(^"|"$)/g, "'"); - name = ctx.stylize(name, 'string'); + + target[method].clock = clock; } - } - return name + ': ' + str; -} + var timers = { + setTimeout: setTimeout, + clearTimeout: clearTimeout, + setImmediate: global.setImmediate, + clearImmediate: global.clearImmediate, + setInterval: setInterval, + clearInterval: clearInterval, + Date: Date + }; + var keys = Object.keys || function (obj) { + var ks = [], + key; -function reduceToSingleString(output, base, braces) { - var numLinesEst = 0; - var length = output.reduce(function(prev, cur) { - numLinesEst++; - if (cur.indexOf('\n') >= 0) numLinesEst++; - return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; - }, 0); + for (key in obj) { + if (obj.hasOwnProperty(key)) { + ks.push(key); + } + } - if (length > 60) { - return braces[0] + - (base === '' ? '' : base + '\n ') + - ' ' + - output.join(',\n ') + - ' ' + - braces[1]; - } + return ks; + }; - return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; -} + exports.timers = timers; + function createClock(now) { + var clock = { + now: getEpoch(now), + timeouts: {}, + Date: createDate() + }; -// NOTE: These type checking functions intentionally don't use `instanceof` -// because it is fragile and can be easily faked with `Object.create()`. -function isArray(ar) { - return Array.isArray(ar); -} -exports.isArray = isArray; + clock.Date.clock = clock; -function isBoolean(arg) { - return typeof arg === 'boolean'; -} -exports.isBoolean = isBoolean; + clock.setTimeout = function setTimeout(func, timeout) { + return addTimer(clock, { + func: func, + args: Array.prototype.slice.call(arguments, 2), + delay: timeout + }); + }; -function isNull(arg) { - return arg === null; -} -exports.isNull = isNull; + clock.clearTimeout = function clearTimeout(timerId) { + return clearTimer(clock, timerId, "Timeout"); + }; -function isNullOrUndefined(arg) { - return arg == null; -} -exports.isNullOrUndefined = isNullOrUndefined; + clock.setInterval = function setInterval(func, timeout) { + return addTimer(clock, { + func: func, + args: Array.prototype.slice.call(arguments, 2), + delay: timeout, + interval: timeout + }); + }; -function isNumber(arg) { - return typeof arg === 'number'; -} -exports.isNumber = isNumber; + clock.clearInterval = function clearInterval(timerId) { + return clearTimer(clock, timerId, "Interval"); + }; -function isString(arg) { - return typeof arg === 'string'; -} -exports.isString = isString; + clock.setImmediate = function setImmediate(func) { + return addTimer(clock, { + func: func, + args: Array.prototype.slice.call(arguments, 1), + immediate: true + }); + }; -function isSymbol(arg) { - return typeof arg === 'symbol'; -} -exports.isSymbol = isSymbol; + clock.clearImmediate = function clearImmediate(timerId) { + return clearTimer(clock, timerId, "Immediate"); + }; -function isUndefined(arg) { - return arg === void 0; -} -exports.isUndefined = isUndefined; + clock.tick = function tick(ms) { + ms = typeof ms === "number" ? ms : parseTime(ms); + var tickFrom = clock.now, tickTo = clock.now + ms, previous = clock.now; + var timer = firstTimerInRange(clock, tickFrom, tickTo); + var oldNow; -function isRegExp(re) { - return isObject(re) && objectToString(re) === '[object RegExp]'; -} -exports.isRegExp = isRegExp; + clock.duringTick = true; -function isObject(arg) { - return typeof arg === 'object' && arg !== null; -} -exports.isObject = isObject; + var firstException; + while (timer && tickFrom <= tickTo) { + if (clock.timers[timer.id]) { + tickFrom = clock.now = timer.callAt; + try { + oldNow = clock.now; + callTimer(clock, timer); + // compensate for any setSystemTime() call during timer callback + if (oldNow !== clock.now) { + tickFrom += clock.now - oldNow; + tickTo += clock.now - oldNow; + previous += clock.now - oldNow; + } + } catch (e) { + firstException = firstException || e; + } + } -function isDate(d) { - return isObject(d) && objectToString(d) === '[object Date]'; -} -exports.isDate = isDate; + timer = firstTimerInRange(clock, previous, tickTo); + previous = tickFrom; + } -function isError(e) { - return isObject(e) && - (objectToString(e) === '[object Error]' || e instanceof Error); -} -exports.isError = isError; + clock.duringTick = false; + clock.now = tickTo; -function isFunction(arg) { - return typeof arg === 'function'; -} -exports.isFunction = isFunction; + if (firstException) { + throw firstException; + } -function isPrimitive(arg) { - return arg === null || - typeof arg === 'boolean' || - typeof arg === 'number' || - typeof arg === 'string' || - typeof arg === 'symbol' || // ES6 symbol - typeof arg === 'undefined'; -} -exports.isPrimitive = isPrimitive; + return clock.now; + }; -exports.isBuffer = require('./support/isBuffer'); + clock.reset = function reset() { + clock.timers = {}; + }; -function objectToString(o) { - return Object.prototype.toString.call(o); -} + clock.setSystemTime = function setSystemTime(now) { + // determine time difference + var newNow = getEpoch(now); + var difference = newNow - clock.now; + // update 'system clock' + clock.now = newNow; -function pad(n) { - return n < 10 ? '0' + n.toString(10) : n.toString(10); -} + // update timers and intervals to keep them stable + for (var id in clock.timers) { + if (clock.timers.hasOwnProperty(id)) { + var timer = clock.timers[id]; + timer.createdAt += difference; + timer.callAt += difference; + } + } + }; -<<<<<<< 43fdfde7ecd48b6ed6c264b20b9d4c6c38fb47cf + return clock; + } + exports.createClock = createClock; -var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', - 'Oct', 'Nov', 'Dec']; + exports.install = function install(target, now, toFake) { + var i, + l; -// 26 Feb 16:19:34 -function timestamp() { - var d = new Date(); - var time = [pad(d.getHours()), - pad(d.getMinutes()), - pad(d.getSeconds())].join(':'); - return [d.getDate(), months[d.getMonth()], time].join(' '); + if (typeof target === "number") { + toFake = now; + now = target; + target = null; + } + + if (!target) { + target = global; + } + + var clock = createClock(now); + + clock.uninstall = function () { + uninstall(clock, target); + }; + + clock.methods = toFake || []; + + if (clock.methods.length === 0) { + clock.methods = keys(timers); + } + + for (i = 0, l = clock.methods.length; i < l; i++) { + hijackMethod(target, clock.methods[i], clock); + } + + return clock; + }; + +}(global || this)); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],13:[function(require,module,exports){ +// shim for using process in browser + +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +(function () { + try { + cachedSetTimeout = setTimeout; + } catch (e) { + cachedSetTimeout = function () { + throw new Error('setTimeout is not defined'); + } + } + try { + cachedClearTimeout = clearTimeout; + } catch (e) { + cachedClearTimeout = function () { + throw new Error('clearTimeout is not defined'); + } + } +} ()) +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } } -======= function drainQueue() { if (draining) { return; @@ -1513,1193 +1622,711 @@ process.nextTick = function (fun) { cachedSetTimeout.call(null, drainQueue, 0); } }; ->>>>>>> Track barometer request times -// log is just a thin wrapper to console.log that prepends a timestamp -exports.log = function() { - console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); -}; - - -/** - * Inherit the prototype methods from one constructor into another. - * - * The Function.prototype.inherits from lang.js rewritten as a standalone - * function (not on Function.prototype). NOTE: If this file is to be loaded - * during bootstrapping this function needs to be rewritten using some native - * functions as prototype setup using normal JavaScript does not work as - * expected during bootstrapping (see mirror.js in r114903). - * - * @param {function} ctor Constructor function which needs to inherit the - * prototype. - * @param {function} superCtor Constructor function to inherit prototype from. - */ -exports.inherits = require('inherits'); - -exports._extend = function(origin, add) { - // Don't do anything if add isn't an object - if (!add || !isObject(add)) return origin; - - var keys = Object.keys(add); - var i = keys.length; - while (i--) { - origin[keys[i]] = add[keys[i]]; - } - return origin; -}; - -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -} - -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":12,"_process":11,"inherits":10}],14:[function(require,module,exports){ -/** - * Sinon core utilities. For internal use only. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -var sinon = (function () { // eslint-disable-line no-unused-vars - "use strict"; - - var sinonModule; - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - - function loadDependencies(require, exports, module) { - sinonModule = module.exports = require("./sinon/util/core"); - require("./sinon/extend"); - require("./sinon/walk"); - require("./sinon/typeOf"); - require("./sinon/times_in_words"); - require("./sinon/spy"); - require("./sinon/call"); - require("./sinon/behavior"); - require("./sinon/stub"); - require("./sinon/mock"); - require("./sinon/collection"); - require("./sinon/assert"); - require("./sinon/sandbox"); - require("./sinon/test"); - require("./sinon/test_case"); - require("./sinon/match"); - require("./sinon/format"); - require("./sinon/log_error"); - } - - if (isAMD) { - define(loadDependencies); - } else if (isNode) { - loadDependencies(require, module.exports, module); - sinonModule = module.exports; - } else { - sinonModule = {}; - } - - return sinonModule; -}()); - -},{"./sinon/assert":15,"./sinon/behavior":16,"./sinon/call":17,"./sinon/collection":18,"./sinon/extend":19,"./sinon/format":20,"./sinon/log_error":21,"./sinon/match":22,"./sinon/mock":23,"./sinon/sandbox":24,"./sinon/spy":25,"./sinon/stub":26,"./sinon/test":27,"./sinon/test_case":28,"./sinon/times_in_words":29,"./sinon/typeOf":30,"./sinon/util/core":31,"./sinon/walk":38}],15:[function(require,module,exports){ -(function (global){ -/** - * @depend times_in_words.js - * @depend util/core.js - * @depend match.js - * @depend format.js - */ -/** - * Assertions matching the test spy retrieval interface. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -(function (sinonGlobal, global) { - "use strict"; - - var slice = Array.prototype.slice; - - function makeApi(sinon) { - var assert; - - function verifyIsStub() { - var method; - - for (var i = 0, l = arguments.length; i < l; ++i) { - method = arguments[i]; - - if (!method) { - assert.fail("fake is not a spy"); - } - - if (method.proxy && method.proxy.isSinonProxy) { - verifyIsStub(method.proxy); - } else { - if (typeof method !== "function") { - assert.fail(method + " is not a function"); - } - - if (typeof method.getCall !== "function") { - assert.fail(method + " is not stubbed"); - } - } - - } - } - - function verifyIsValidAssertion(assertionMethod, assertionArgs) { - switch (assertionMethod) { - case "notCalled": - case "called": - case "calledOnce": - case "calledTwice": - case "calledThrice": - if (assertionArgs.length !== 0) { - assert.fail(assertionMethod + - " takes 1 argument but was called with " + - (assertionArgs.length + 1) + " arguments"); - } - break; - default: - break; - } - } - - function failAssertion(object, msg) { - object = object || global; - var failMethod = object.fail || assert.fail; - failMethod.call(object, msg); - } - - function mirrorPropAsAssertion(name, method, message) { - if (arguments.length === 2) { - message = method; - method = name; - } - - assert[name] = function (fake) { - verifyIsStub(fake); - - var args = slice.call(arguments, 1); - verifyIsValidAssertion(name, args); - - var failed = false; - - if (typeof method === "function") { - failed = !method(fake); - } else { - failed = typeof fake[method] === "function" ? - !fake[method].apply(fake, args) : !fake[method]; - } - - if (failed) { - failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, [message].concat(args))); - } else { - assert.pass(name); - } - }; - } - - function exposedName(prefix, prop) { - return !prefix || /^fail/.test(prop) ? prop : - prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1); - } - - assert = { - failException: "AssertError", - - fail: function fail(message) { - var error = new Error(message); - error.name = this.failException || assert.failException; - - throw error; - }, - - pass: function pass() {}, - - callOrder: function assertCallOrder() { - verifyIsStub.apply(null, arguments); - var expected = ""; - var actual = ""; - - if (!sinon.calledInOrder(arguments)) { - try { - expected = [].join.call(arguments, ", "); - var calls = slice.call(arguments); - var i = calls.length; - while (i) { - if (!calls[--i].called) { - calls.splice(i, 1); - } - } - actual = sinon.orderByFirstCall(calls).join(", "); - } catch (e) { - // If this fails, we'll just fall back to the blank string - } - - failAssertion(this, "expected " + expected + " to be " + - "called in order but were called as " + actual); - } else { - assert.pass("callOrder"); - } - }, - - callCount: function assertCallCount(method, count) { - verifyIsStub(method); - - if (method.callCount !== count) { - var msg = "expected %n to be called " + sinon.timesInWords(count) + - " but was called %c%C"; - failAssertion(this, method.printf(msg)); - } else { - assert.pass("callCount"); - } - }, - - expose: function expose(target, options) { - if (!target) { - throw new TypeError("target is null or undefined"); - } - - var o = options || {}; - var prefix = typeof o.prefix === "undefined" && "assert" || o.prefix; - var includeFail = typeof o.includeFail === "undefined" || !!o.includeFail; - - for (var method in this) { - if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) { - target[exposedName(prefix, method)] = this[method]; - } - } - - return target; - }, - - match: function match(actual, expectation) { - var matcher = sinon.match(expectation); - if (matcher.test(actual)) { - assert.pass("match"); - } else { - var formatted = [ - "expected value to match", - " expected = " + sinon.format(expectation), - " actual = " + sinon.format(actual) - ]; - - failAssertion(this, formatted.join("\n")); - } - } - }; - - mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called"); - mirrorPropAsAssertion("notCalled", function (spy) { - return !spy.called; - }, "expected %n to not have been called but was called %c%C"); - mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C"); - mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); - mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); - mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); - mirrorPropAsAssertion( - "alwaysCalledOn", - "expected %n to always be called with %1 as this but was called with %t" - ); - mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); - mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); - mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C"); - mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C"); - mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C"); - mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C"); - mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C"); - mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C"); - mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C"); - mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C"); - mirrorPropAsAssertion("threw", "%n did not throw exception%C"); - mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C"); - - sinon.assert = assert; - return assert; - } - - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - - function loadDependencies(require, exports, module) { - var sinon = require("./util/core"); - require("./match"); - require("./format"); - module.exports = makeApi(sinon); - } - - if (isAMD) { - define(loadDependencies); - return; - } - - if (isNode) { - loadDependencies(require, module.exports, module); - return; - } - - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon, // eslint-disable-line no-undef - typeof global !== "undefined" ? global : self -)); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./format":20,"./match":22,"./util/core":31}],16:[function(require,module,exports){ -(function (process){ -/** - * @depend util/core.js - * @depend extend.js - */ -/** - * Stub behavior - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Tim Fischbach (mail@timfischbach.de) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -(function (sinonGlobal) { - "use strict"; - - var slice = Array.prototype.slice; - var join = Array.prototype.join; - var useLeftMostCallback = -1; - var useRightMostCallback = -2; - - var nextTick = (function () { - if (typeof process === "object" && typeof process.nextTick === "function") { - return process.nextTick; - } - - if (typeof setImmediate === "function") { - return setImmediate; - } - - return function (callback) { - setTimeout(callback, 0); - }; - })(); - - function throwsException(error, message) { - if (typeof error === "string") { - this.exception = new Error(message || ""); - this.exception.name = error; - } else if (!error) { - this.exception = new Error("Error"); - } else { - this.exception = error; - } - - return this; - } - - function getCallback(behavior, args) { - var callArgAt = behavior.callArgAt; - - if (callArgAt >= 0) { - return args[callArgAt]; - } - -<<<<<<< 43fdfde7ecd48b6ed6c264b20b9d4c6c38fb47cf -======= - function verifyIsValidAssertion(assertionMethod, assertionArgs) { - switch (assertionMethod) { - case "notCalled": - case "called": - case "calledOnce": - case "calledTwice": - case "calledThrice": - if (assertionArgs.length !== 0) { - assert.fail(assertionMethod + - " takes 1 argument but was called with " + - (assertionArgs.length + 1) + " arguments"); - } - break; - default: - break; - } - } - - function failAssertion(object, msg) { - object = object || global; - var failMethod = object.fail || assert.fail; - failMethod.call(object, msg); - } - - function mirrorPropAsAssertion(name, method, message) { - if (arguments.length === 2) { - message = method; - method = name; - } - - assert[name] = function (fake) { - verifyIsStub(fake); - - var args = slice.call(arguments, 1); - verifyIsValidAssertion(name, args); - - var failed = false; - - if (typeof method === "function") { - failed = !method(fake); - } else { - failed = typeof fake[method] === "function" ? - !fake[method].apply(fake, args) : !fake[method]; - } - - if (failed) { - failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, [message].concat(args))); - } else { - assert.pass(name); - } - }; - } - - function exposedName(prefix, prop) { - return !prefix || /^fail/.test(prop) ? prop : - prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1); - } - - assert = { - failException: "AssertError", - - fail: function fail(message) { - var error = new Error(message); - error.name = this.failException || assert.failException; - - throw error; - }, - - pass: function pass() {}, - - callOrder: function assertCallOrder() { - verifyIsStub.apply(null, arguments); - var expected = ""; - var actual = ""; - - if (!sinon.calledInOrder(arguments)) { - try { - expected = [].join.call(arguments, ", "); - var calls = slice.call(arguments); - var i = calls.length; - while (i) { - if (!calls[--i].called) { - calls.splice(i, 1); - } - } - actual = sinon.orderByFirstCall(calls).join(", "); - } catch (e) { - // If this fails, we'll just fall back to the blank string - } - - failAssertion(this, "expected " + expected + " to be " + - "called in order but were called as " + actual); - } else { - assert.pass("callOrder"); - } - }, - - callCount: function assertCallCount(method, count) { - verifyIsStub(method); - - if (method.callCount !== count) { - var msg = "expected %n to be called " + sinon.timesInWords(count) + - " but was called %c%C"; - failAssertion(this, method.printf(msg)); - } else { - assert.pass("callCount"); - } - }, - - expose: function expose(target, options) { - if (!target) { - throw new TypeError("target is null or undefined"); - } - - var o = options || {}; - var prefix = typeof o.prefix === "undefined" && "assert" || o.prefix; - var includeFail = typeof o.includeFail === "undefined" || !!o.includeFail; - - for (var method in this) { - if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) { - target[exposedName(prefix, method)] = this[method]; - } - } - - return target; - }, - - match: function match(actual, expectation) { - var matcher = sinon.match(expectation); - if (matcher.test(actual)) { - assert.pass("match"); - } else { - var formatted = [ - "expected value to match", - " expected = " + sinon.format(expectation), - " actual = " + sinon.format(actual) - ]; - - failAssertion(this, formatted.join("\n")); - } - } - }; +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; - mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called"); - mirrorPropAsAssertion("notCalled", function (spy) { - return !spy.called; - }, "expected %n to not have been called but was called %c%C"); - mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C"); - mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); - mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); - mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); - mirrorPropAsAssertion( - "alwaysCalledOn", - "expected %n to always be called with %1 as this but was called with %t" - ); - mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); - mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); - mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C"); - mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C"); - mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C"); - mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C"); - mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C"); - mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C"); - mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C"); - mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C"); - mirrorPropAsAssertion("threw", "%n did not throw exception%C"); - mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C"); +function noop() {} - sinon.assert = assert; - return assert; - } +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; - function loadDependencies(require, exports, module) { - var sinon = require("./util/core"); - require("./match"); - require("./format"); - module.exports = makeApi(sinon); - } +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; - if (isAMD) { - define(loadDependencies); - return; - } +},{}],14:[function(require,module,exports){ +((typeof define === "function" && define.amd && function (m) { define("samsam", m); }) || + (typeof module === "object" && + function (m) { module.exports = m(); }) || // Node + function (m) { this.samsam = m(); } // Browser globals +)(function () { + var o = Object.prototype; + var div = typeof document !== "undefined" && document.createElement("div"); - if (isNode) { - loadDependencies(require, module.exports, module); - return; + function isNaN(value) { + // Unlike global isNaN, this avoids type coercion + // typeof check avoids IE host object issues, hat tip to + // lodash + var val = value; // JsLint thinks value !== value is "weird" + return typeof value === "number" && value !== val; } - if (sinonGlobal) { - makeApi(sinonGlobal); + function getClass(value) { + // Returns the internal [[Class]] by calling Object.prototype.toString + // with the provided value as this. Return value is a string, naming the + // internal class, e.g. "Array" + return o.toString.call(value).split(/[ \]]/)[1]; } -}( - typeof sinon === "object" && sinon, // eslint-disable-line no-undef - typeof global !== "undefined" ? global : self -)); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./format":20,"./match":22,"./util/core":31}],16:[function(require,module,exports){ -(function (process){ -/** - * @depend util/core.js - * @depend extend.js - */ -/** - * Stub behavior - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Tim Fischbach (mail@timfischbach.de) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -(function (sinonGlobal) { - "use strict"; - var slice = Array.prototype.slice; - var join = Array.prototype.join; - var useLeftMostCallback = -1; - var useRightMostCallback = -2; - - var nextTick = (function () { - if (typeof process === "object" && typeof process.nextTick === "function") { - return process.nextTick; + /** + * @name samsam.isArguments + * @param Object object + * + * Returns ``true`` if ``object`` is an ``arguments`` object, + * ``false`` otherwise. + */ + function isArguments(object) { + if (getClass(object) === 'Arguments') { return true; } + if (typeof object !== "object" || typeof object.length !== "number" || + getClass(object) === "Array") { + return false; } - - if (typeof setImmediate === "function") { - return setImmediate; + if (typeof object.callee == "function") { return true; } + try { + object[object.length] = 6; + delete object[object.length]; + } catch (e) { + return true; } + return false; + } - return function (callback) { - setTimeout(callback, 0); - }; - })(); + /** + * @name samsam.isElement + * @param Object object + * + * Returns ``true`` if ``object`` is a DOM element node. Unlike + * Underscore.js/lodash, this function will return ``false`` if ``object`` + * is an *element-like* object, i.e. a regular object with a ``nodeType`` + * property that holds the value ``1``. + */ + function isElement(object) { + if (!object || object.nodeType !== 1 || !div) { return false; } + try { + object.appendChild(div); + object.removeChild(div); + } catch (e) { + return false; + } + return true; + } - function throwsException(error, message) { - if (typeof error === "string") { - this.exception = new Error(message || ""); - this.exception.name = error; - } else if (!error) { - this.exception = new Error("Error"); - } else { - this.exception = error; + /** + * @name samsam.keys + * @param Object object + * + * Return an array of own property names. + */ + function keys(object) { + var ks = [], prop; + for (prop in object) { + if (o.hasOwnProperty.call(object, prop)) { ks.push(prop); } } + return ks; + } - return this; + /** + * @name samsam.isDate + * @param Object value + * + * Returns true if the object is a ``Date``, or *date-like*. Duck typing + * of date objects work by checking that the object has a ``getTime`` + * function whose return value equals the return value from the object's + * ``valueOf``. + */ + function isDate(value) { + return typeof value.getTime == "function" && + value.getTime() == value.valueOf(); } - function getCallback(behavior, args) { - var callArgAt = behavior.callArgAt; + /** + * @name samsam.isNegZero + * @param Object value + * + * Returns ``true`` if ``value`` is ``-0``. + */ + function isNegZero(value) { + return value === 0 && 1 / value === -Infinity; + } - if (callArgAt >= 0) { - return args[callArgAt]; + /** + * @name samsam.equal + * @param Object obj1 + * @param Object obj2 + * + * Returns ``true`` if two objects are strictly equal. Compared to + * ``===`` there are two exceptions: + * + * - NaN is considered equal to NaN + * - -0 and +0 are not considered equal + */ + function identical(obj1, obj2) { + if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) { + return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2); } + } ->>>>>>> Track barometer request times - var argumentList; - if (callArgAt === useLeftMostCallback) { - argumentList = args; - } + /** + * @name samsam.deepEqual + * @param Object obj1 + * @param Object obj2 + * + * Deep equal comparison. Two values are "deep equal" if: + * + * - They are equal, according to samsam.identical + * - They are both date objects representing the same time + * - They are both arrays containing elements that are all deepEqual + * - They are objects with the same set of properties, and each property + * in ``obj1`` is deepEqual to the corresponding property in ``obj2`` + * + * Supports cyclic objects. + */ + function deepEqualCyclic(obj1, obj2) { + + // used for cyclic comparison + // contain already visited objects + var objects1 = [], + objects2 = [], + // contain pathes (position in the object structure) + // of the already visited objects + // indexes same as in objects arrays + paths1 = [], + paths2 = [], + // contains combinations of already compared objects + // in the manner: { "$1['ref']$2['ref']": true } + compared = {}; - if (callArgAt === useRightMostCallback) { - argumentList = slice.call(args).reverse(); - } + /** + * used to check, if the value of a property is an object + * (cyclic logic is only needed for objects) + * only needed for cyclic logic + */ + function isObject(value) { - var callArgProp = behavior.callArgProp; + if (typeof value === 'object' && value !== null && + !(value instanceof Boolean) && + !(value instanceof Date) && + !(value instanceof Number) && + !(value instanceof RegExp) && + !(value instanceof String)) { - for (var i = 0, l = argumentList.length; i < l; ++i) { - if (!callArgProp && typeof argumentList[i] === "function") { - return argumentList[i]; + return true; } - if (callArgProp && argumentList[i] && - typeof argumentList[i][callArgProp] === "function") { - return argumentList[i][callArgProp]; - } + return false; } - return null; - } - - function makeApi(sinon) { - function getCallbackError(behavior, func, args) { - if (behavior.callArgAt < 0) { - var msg; - - if (behavior.callArgProp) { - msg = sinon.functionName(behavior.stub) + - " expected to yield to '" + behavior.callArgProp + - "', but no object with such a property was passed."; - } else { - msg = sinon.functionName(behavior.stub) + - " expected to yield, but no callback was passed."; - } + /** + * returns the index of the given object in the + * given objects array, -1 if not contained + * only needed for cyclic logic + */ + function getIndex(objects, obj) { - if (args.length > 0) { - msg += " Received [" + join.call(args, ", ") + "]"; + var i; + for (i = 0; i < objects.length; i++) { + if (objects[i] === obj) { + return i; } - - return msg; } - return "argument at index " + behavior.callArgAt + " is not a function: " + func; + return -1; } - function callCallback(behavior, args) { - if (typeof behavior.callArgAt === "number") { - var func = getCallback(behavior, args); + // does the recursion for the deep equal check + return (function deepEqual(obj1, obj2, path1, path2) { + var type1 = typeof obj1; + var type2 = typeof obj2; - if (typeof func !== "function") { - throw new TypeError(getCallbackError(behavior, func, args)); - } + // == null also matches undefined + if (obj1 === obj2 || + isNaN(obj1) || isNaN(obj2) || + obj1 == null || obj2 == null || + type1 !== "object" || type2 !== "object") { - if (behavior.callbackAsync) { - nextTick(function () { - func.apply(behavior.callbackContext, behavior.callbackArguments); - }); - } else { - func.apply(behavior.callbackContext, behavior.callbackArguments); - } + return identical(obj1, obj2); } - } - - var proto = { - create: function create(stub) { - var behavior = sinon.extend({}, sinon.behavior); - delete behavior.create; - behavior.stub = stub; - - return behavior; - }, - - isPresent: function isPresent() { - return (typeof this.callArgAt === "number" || - this.exception || - typeof this.returnArgAt === "number" || - this.returnThis || - this.returnValueDefined); - }, - - invoke: function invoke(context, args) { - callCallback(this, args); - - if (this.exception) { - throw this.exception; - } else if (typeof this.returnArgAt === "number") { - return args[this.returnArgAt]; - } else if (this.returnThis) { - return context; - } - - return this.returnValue; - }, - - onCall: function onCall(index) { - return this.stub.onCall(index); - }, - - onFirstCall: function onFirstCall() { - return this.stub.onFirstCall(); - }, - - onSecondCall: function onSecondCall() { - return this.stub.onSecondCall(); - }, - onThirdCall: function onThirdCall() { - return this.stub.onThirdCall(); - }, - - withArgs: function withArgs(/* arguments */) { - throw new Error( - "Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" " + - "is not supported. Use \"stub.withArgs(...).onCall(...)\" " + - "to define sequential behavior for calls with certain arguments." - ); - }, - - callsArg: function callsArg(pos) { - if (typeof pos !== "number") { - throw new TypeError("argument index is not number"); - } - - this.callArgAt = pos; - this.callbackArguments = []; - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, + // Elements are only equal if identical(expected, actual) + if (isElement(obj1) || isElement(obj2)) { return false; } - callsArgOn: function callsArgOn(pos, context) { - if (typeof pos !== "number") { - throw new TypeError("argument index is not number"); - } - if (typeof context !== "object") { - throw new TypeError("argument context is not an object"); + var isDate1 = isDate(obj1), isDate2 = isDate(obj2); + if (isDate1 || isDate2) { + if (!isDate1 || !isDate2 || obj1.getTime() !== obj2.getTime()) { + return false; } + } - this.callArgAt = pos; - this.callbackArguments = []; - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; + if (obj1 instanceof RegExp && obj2 instanceof RegExp) { + if (obj1.toString() !== obj2.toString()) { return false; } + } - return this; - }, + var class1 = getClass(obj1); + var class2 = getClass(obj2); + var keys1 = keys(obj1); + var keys2 = keys(obj2); - callsArgWith: function callsArgWith(pos) { - if (typeof pos !== "number") { - throw new TypeError("argument index is not number"); + if (isArguments(obj1) || isArguments(obj2)) { + if (obj1.length !== obj2.length) { return false; } + } else { + if (type1 !== type2 || class1 !== class2 || + keys1.length !== keys2.length) { + return false; } + } - this.callArgAt = pos; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, + var key, i, l, + // following vars are used for the cyclic logic + value1, value2, + isObject1, isObject2, + index1, index2, + newPath1, newPath2; - callsArgOnWith: function callsArgWith(pos, context) { - if (typeof pos !== "number") { - throw new TypeError("argument index is not number"); - } - if (typeof context !== "object") { - throw new TypeError("argument context is not an object"); + for (i = 0, l = keys1.length; i < l; i++) { + key = keys1[i]; + if (!o.hasOwnProperty.call(obj2, key)) { + return false; } - this.callArgAt = pos; - this.callbackArguments = slice.call(arguments, 2); - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, + // Start of the cyclic logic - yields: function () { - this.callArgAt = useLeftMostCallback; - this.callbackArguments = slice.call(arguments, 0); - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; + value1 = obj1[key]; + value2 = obj2[key]; - return this; - }, + isObject1 = isObject(value1); + isObject2 = isObject(value2); - yieldsRight: function () { - this.callArgAt = useRightMostCallback; - this.callbackArguments = slice.call(arguments, 0); - this.callbackContext = undefined; - this.callArgProp = undefined; - this.callbackAsync = false; + // determine, if the objects were already visited + // (it's faster to check for isObject first, than to + // get -1 from getIndex for non objects) + index1 = isObject1 ? getIndex(objects1, value1) : -1; + index2 = isObject2 ? getIndex(objects2, value2) : -1; - return this; - }, + // determine the new pathes of the objects + // - for non cyclic objects the current path will be extended + // by current property name + // - for cyclic objects the stored path is taken + newPath1 = index1 !== -1 + ? paths1[index1] + : path1 + '[' + JSON.stringify(key) + ']'; + newPath2 = index2 !== -1 + ? paths2[index2] + : path2 + '[' + JSON.stringify(key) + ']'; - yieldsOn: function (context) { - if (typeof context !== "object") { - throw new TypeError("argument context is not an object"); + // stop recursion if current objects are already compared + if (compared[newPath1 + newPath2]) { + return true; } - this.callArgAt = useLeftMostCallback; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = context; - this.callArgProp = undefined; - this.callbackAsync = false; - - return this; - }, + // remember the current objects and their pathes + if (index1 === -1 && isObject1) { + objects1.push(value1); + paths1.push(newPath1); + } + if (index2 === -1 && isObject2) { + objects2.push(value2); + paths2.push(newPath2); + } - yieldsTo: function (prop) { - this.callArgAt = useLeftMostCallback; - this.callbackArguments = slice.call(arguments, 1); - this.callbackContext = undefined; - this.callArgProp = prop; - this.callbackAsync = false; + // remember that the current objects are already compared + if (isObject1 && isObject2) { + compared[newPath1 + newPath2] = true; + } - return this; - }, + // End of cyclic logic - yieldsToOn: function (prop, context) { - if (typeof context !== "object") { - throw new TypeError("argument context is not an object"); + // neither value1 nor value2 is a cycle + // continue with next level + if (!deepEqual(value1, value2, newPath1, newPath2)) { + return false; } + } - this.callArgAt = useLeftMostCallback; - this.callbackArguments = slice.call(arguments, 2); - this.callbackContext = context; - this.callArgProp = prop; - this.callbackAsync = false; + return true; - return this; - }, + }(obj1, obj2, '$1', '$2')); + } - throws: throwsException, - throwsException: throwsException, + var match; - returns: function returns(value) { - this.returnValue = value; - this.returnValueDefined = true; - this.exception = undefined; + function arrayContains(array, subset) { + if (subset.length === 0) { return true; } + var i, l, j, k; + for (i = 0, l = array.length; i < l; ++i) { + if (match(array[i], subset[0])) { + for (j = 0, k = subset.length; j < k; ++j) { + if (!match(array[i + j], subset[j])) { return false; } + } + return true; + } + } + return false; + } - return this; - }, + /** + * @name samsam.match + * @param Object object + * @param Object matcher + * + * Compare arbitrary value ``object`` with matcher. + */ + match = function match(object, matcher) { + if (matcher && typeof matcher.test === "function") { + return matcher.test(object); + } - returnsArg: function returnsArg(pos) { - if (typeof pos !== "number") { - throw new TypeError("argument index is not number"); - } + if (typeof matcher === "function") { + return matcher(object) === true; + } - this.returnArgAt = pos; + if (typeof matcher === "string") { + matcher = matcher.toLowerCase(); + var notNull = typeof object === "string" || !!object; + return notNull && + (String(object)).toLowerCase().indexOf(matcher) >= 0; + } - return this; - }, + if (typeof matcher === "number") { + return matcher === object; + } - returnsThis: function returnsThis() { - this.returnThis = true; + if (typeof matcher === "boolean") { + return matcher === object; + } - return this; - } - }; + if (typeof(matcher) === "undefined") { + return typeof(object) === "undefined"; + } - function createAsyncVersion(syncFnName) { - return function () { - var result = this[syncFnName].apply(this, arguments); - this.callbackAsync = true; - return result; - }; + if (matcher === null) { + return object === null; } - // create asynchronous versions of callsArg* and yields* methods - for (var method in proto) { - // need to avoid creating anotherasync versions of the newly added async methods - if (proto.hasOwnProperty(method) && method.match(/^(callsArg|yields)/) && !method.match(/Async/)) { - proto[method + "Async"] = createAsyncVersion(method); + if (getClass(object) === "Array" && getClass(matcher) === "Array") { + return arrayContains(object, matcher); + } + + if (matcher && typeof matcher === "object") { + if (matcher === object) { + return true; + } + var prop; + for (prop in matcher) { + var value = object[prop]; + if (typeof value === "undefined" && + typeof object.getAttribute === "function") { + value = object.getAttribute(prop); + } + if (matcher[prop] === null || typeof matcher[prop] === 'undefined') { + if (value !== matcher[prop]) { + return false; + } + } else if (typeof value === "undefined" || !match(value, matcher[prop])) { + return false; + } } + return true; } - sinon.behavior = proto; - return proto; - } + throw new Error("Matcher was not a string, a number, a " + + "function, a boolean or an object"); + }; + + return { + isArguments: isArguments, + isElement: isElement, + isDate: isDate, + isNegZero: isNegZero, + identical: identical, + deepEqual: deepEqualCyclic, + match: match, + keys: keys + }; +}); + +},{}],15:[function(require,module,exports){ +/** + * Sinon core utilities. For internal use only. + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +var sinon = (function () { // eslint-disable-line no-unused-vars + "use strict"; + var sinonModule; var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; function loadDependencies(require, exports, module) { - var sinon = require("./util/core"); - require("./extend"); - module.exports = makeApi(sinon); + sinonModule = module.exports = require("./sinon/util/core"); + require("./sinon/extend"); + require("./sinon/walk"); + require("./sinon/typeOf"); + require("./sinon/times_in_words"); + require("./sinon/spy"); + require("./sinon/call"); + require("./sinon/behavior"); + require("./sinon/stub"); + require("./sinon/mock"); + require("./sinon/collection"); + require("./sinon/assert"); + require("./sinon/sandbox"); + require("./sinon/test"); + require("./sinon/test_case"); + require("./sinon/match"); + require("./sinon/format"); + require("./sinon/log_error"); } if (isAMD) { define(loadDependencies); - return; - } - - if (isNode) { + } else if (isNode) { loadDependencies(require, module.exports, module); - return; + sinonModule = module.exports; + } else { + sinonModule = {}; } - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + return sinonModule; +}()); -}).call(this,require('_process')) -},{"./extend":19,"./util/core":31,"_process":11}],17:[function(require,module,exports){ +},{"./sinon/assert":16,"./sinon/behavior":17,"./sinon/call":18,"./sinon/collection":19,"./sinon/extend":20,"./sinon/format":21,"./sinon/log_error":22,"./sinon/match":23,"./sinon/mock":24,"./sinon/sandbox":25,"./sinon/spy":26,"./sinon/stub":27,"./sinon/test":28,"./sinon/test_case":29,"./sinon/times_in_words":30,"./sinon/typeOf":31,"./sinon/util/core":32,"./sinon/walk":39}],16:[function(require,module,exports){ +(function (global){ /** - * @depend util/core.js - * @depend match.js - * @depend format.js - */ + * @depend times_in_words.js + * @depend util/core.js + * @depend match.js + * @depend format.js + */ /** - * Spy calls - * - * @author Christian Johansen (christian@cjohansen.no) - * @author Maximilian Antoni (mail@maxantoni.de) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - * Copyright (c) 2013 Maximilian Antoni - */ -(function (sinonGlobal) { + * Assertions matching the test spy retrieval interface. + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +(function (sinonGlobal, global) { "use strict"; var slice = Array.prototype.slice; - function makeApi(sinon) { - function throwYieldError(proxy, text, args) { - var msg = sinon.functionName(proxy) + text; - if (args.length) { - msg += " Received [" + slice.call(args).join(", ") + "]"; - } - throw new Error(msg); - } + function makeApi(sinon) { + var assert; + + function verifyIsStub() { + var method; + + for (var i = 0, l = arguments.length; i < l; ++i) { + method = arguments[i]; - var callProto = { - calledOn: function calledOn(thisValue) { - if (sinon.match && sinon.match.isMatcher(thisValue)) { - return thisValue.test(this.thisValue); + if (!method) { + assert.fail("fake is not a spy"); } - return this.thisValue === thisValue; - }, - calledWith: function calledWith() { - var l = arguments.length; - if (l > this.args.length) { - return false; - } - for (var i = 0; i < l; i += 1) { - if (!sinon.deepEqual(arguments[i], this.args[i])) { - return false; + if (method.proxy && method.proxy.isSinonProxy) { + verifyIsStub(method.proxy); + } else { + if (typeof method !== "function") { + assert.fail(method + " is not a function"); } - } - - return true; - }, - calledWithMatch: function calledWithMatch() { - var l = arguments.length; - if (l > this.args.length) { - return false; - } - for (var i = 0; i < l; i += 1) { - var actual = this.args[i]; - var expectation = arguments[i]; - if (!sinon.match || !sinon.match(expectation).test(actual)) { - return false; + if (typeof method.getCall !== "function") { + assert.fail(method + " is not stubbed"); } } - return true; - }, - - calledWithExactly: function calledWithExactly() { - return arguments.length === this.args.length && - this.calledWith.apply(this, arguments); - }, - notCalledWith: function notCalledWith() { - return !this.calledWith.apply(this, arguments); - }, + } + } - notCalledWithMatch: function notCalledWithMatch() { - return !this.calledWithMatch.apply(this, arguments); - }, + function verifyIsValidAssertion(assertionMethod, assertionArgs) { + switch (assertionMethod) { + case "notCalled": + case "called": + case "calledOnce": + case "calledTwice": + case "calledThrice": + if (assertionArgs.length !== 0) { + assert.fail(assertionMethod + + " takes 1 argument but was called with " + + (assertionArgs.length + 1) + " arguments"); + } + break; + default: + break; + } + } - returned: function returned(value) { - return sinon.deepEqual(value, this.returnValue); - }, + function failAssertion(object, msg) { + object = object || global; + var failMethod = object.fail || assert.fail; + failMethod.call(object, msg); + } - threw: function threw(error) { - if (typeof error === "undefined" || !this.exception) { - return !!this.exception; - } + function mirrorPropAsAssertion(name, method, message) { + if (arguments.length === 2) { + message = method; + method = name; + } - return this.exception === error || this.exception.name === error; - }, + assert[name] = function (fake) { + verifyIsStub(fake); - calledWithNew: function calledWithNew() { - return this.proxy.prototype && this.thisValue instanceof this.proxy; - }, + var args = slice.call(arguments, 1); + verifyIsValidAssertion(name, args); - calledBefore: function (other) { - return this.callId < other.callId; - }, + var failed = false; - calledAfter: function (other) { - return this.callId > other.callId; - }, + if (typeof method === "function") { + failed = !method(fake); + } else { + failed = typeof fake[method] === "function" ? + !fake[method].apply(fake, args) : !fake[method]; + } - callArg: function (pos) { - this.args[pos](); - }, + if (failed) { + failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, [message].concat(args))); + } else { + assert.pass(name); + } + }; + } - callArgOn: function (pos, thisValue) { - this.args[pos].apply(thisValue); - }, + function exposedName(prefix, prop) { + return !prefix || /^fail/.test(prop) ? prop : + prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1); + } - callArgWith: function (pos) { - this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1))); - }, + assert = { + failException: "AssertError", - callArgOnWith: function (pos, thisValue) { - var args = slice.call(arguments, 2); - this.args[pos].apply(thisValue, args); - }, + fail: function fail(message) { + var error = new Error(message); + error.name = this.failException || assert.failException; - "yield": function () { - this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0))); + throw error; }, - yieldOn: function (thisValue) { - var args = this.args; - for (var i = 0, l = args.length; i < l; ++i) { - if (typeof args[i] === "function") { - args[i].apply(thisValue, slice.call(arguments, 1)); - return; - } - } - throwYieldError(this.proxy, " cannot yield since no callback was passed.", args); - }, + pass: function pass() {}, - yieldTo: function (prop) { - this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1))); - }, + callOrder: function assertCallOrder() { + verifyIsStub.apply(null, arguments); + var expected = ""; + var actual = ""; - yieldToOn: function (prop, thisValue) { - var args = this.args; - for (var i = 0, l = args.length; i < l; ++i) { - if (args[i] && typeof args[i][prop] === "function") { - args[i][prop].apply(thisValue, slice.call(arguments, 2)); - return; + if (!sinon.calledInOrder(arguments)) { + try { + expected = [].join.call(arguments, ", "); + var calls = slice.call(arguments); + var i = calls.length; + while (i) { + if (!calls[--i].called) { + calls.splice(i, 1); + } + } + actual = sinon.orderByFirstCall(calls).join(", "); + } catch (e) { + // If this fails, we'll just fall back to the blank string } - } - throwYieldError(this.proxy, " cannot yield to '" + prop + - "' since no callback was passed.", args); - }, - getStackFrames: function () { - // Omit the error message and the two top stack frames in sinon itself: - return this.stack && this.stack.split("\n").slice(3); + failAssertion(this, "expected " + expected + " to be " + + "called in order but were called as " + actual); + } else { + assert.pass("callOrder"); + } }, - toString: function () { - var callStr = this.proxy ? this.proxy.toString() + "(" : ""; - var args = []; - - if (!this.args) { - return ":("; - } + callCount: function assertCallCount(method, count) { + verifyIsStub(method); - for (var i = 0, l = this.args.length; i < l; ++i) { - args.push(sinon.format(this.args[i])); + if (method.callCount !== count) { + var msg = "expected %n to be called " + sinon.timesInWords(count) + + " but was called %c%C"; + failAssertion(this, method.printf(msg)); + } else { + assert.pass("callCount"); } + }, - callStr = callStr + args.join(", ") + ")"; - - if (typeof this.returnValue !== "undefined") { - callStr += " => " + sinon.format(this.returnValue); + expose: function expose(target, options) { + if (!target) { + throw new TypeError("target is null or undefined"); } - if (this.exception) { - callStr += " !" + this.exception.name; + var o = options || {}; + var prefix = typeof o.prefix === "undefined" && "assert" || o.prefix; + var includeFail = typeof o.includeFail === "undefined" || !!o.includeFail; - if (this.exception.message) { - callStr += "(" + this.exception.message + ")"; + for (var method in this) { + if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) { + target[exposedName(prefix, method)] = this[method]; } } - if (this.stack) { - callStr += this.getStackFrames()[0].replace(/^\s*(?:at\s+|@)?/, " at "); - - } - return callStr; - } - }; + return target; + }, - callProto.invokeCallback = callProto.yield; + match: function match(actual, expectation) { + var matcher = sinon.match(expectation); + if (matcher.test(actual)) { + assert.pass("match"); + } else { + var formatted = [ + "expected value to match", + " expected = " + sinon.format(expectation), + " actual = " + sinon.format(actual) + ]; - function createSpyCall(spy, thisValue, args, returnValue, exception, id, stack) { - if (typeof id !== "number") { - throw new TypeError("Call id is not a number"); + failAssertion(this, formatted.join("\n")); + } } - var proxyCall = sinon.create(callProto); - proxyCall.proxy = spy; - proxyCall.thisValue = thisValue; - proxyCall.args = args; - proxyCall.returnValue = returnValue; - proxyCall.exception = exception; - proxyCall.callId = id; - proxyCall.stack = stack; + }; - return proxyCall; - } - createSpyCall.toString = callProto.toString; // used by mocks + mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called"); + mirrorPropAsAssertion("notCalled", function (spy) { + return !spy.called; + }, "expected %n to not have been called but was called %c%C"); + mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C"); + mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); + mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); + mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); + mirrorPropAsAssertion( + "alwaysCalledOn", + "expected %n to always be called with %1 as this but was called with %t" + ); + mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); + mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); + mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C"); + mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C"); + mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C"); + mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C"); + mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C"); + mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C"); + mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C"); + mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C"); + mirrorPropAsAssertion("threw", "%n did not throw exception%C"); + mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C"); - sinon.spyCall = createSpyCall; - return createSpyCall; + sinon.assert = assert; + return assert; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; @@ -2726,20 +2353,22 @@ var sinon = (function () { // eslint-disable-line no-unused-vars makeApi(sinonGlobal); } }( - typeof sinon === "object" && sinon // eslint-disable-line no-undef + typeof sinon === "object" && sinon, // eslint-disable-line no-undef + typeof global !== "undefined" ? global : self )); -},{"./format":20,"./match":22,"./util/core":31}],18:[function(require,module,exports){ +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./format":21,"./match":23,"./util/core":32}],17:[function(require,module,exports){ +(function (process){ /** * @depend util/core.js - * @depend spy.js - * @depend stub.js - * @depend mock.js + * @depend extend.js */ /** - * Collections of stubs, spies and mocks. + * Stub behavior * * @author Christian Johansen (christian@cjohansen.no) + * @author Tim Fischbach (mail@timfischbach.de) * @license BSD * * Copyright (c) 2010-2013 Christian Johansen @@ -2747,354 +2376,345 @@ var sinon = (function () { // eslint-disable-line no-unused-vars (function (sinonGlobal) { "use strict"; - var push = [].push; - var hasOwnProperty = Object.prototype.hasOwnProperty; + var slice = Array.prototype.slice; + var join = Array.prototype.join; + var useLeftMostCallback = -1; + var useRightMostCallback = -2; - function getFakes(fakeCollection) { - if (!fakeCollection.fakes) { - fakeCollection.fakes = []; + var nextTick = (function () { + if (typeof process === "object" && typeof process.nextTick === "function") { + return process.nextTick; } - return fakeCollection.fakes; - } + if (typeof setImmediate === "function") { + return setImmediate; + } - function each(fakeCollection, method) { - var fakes = getFakes(fakeCollection); + return function (callback) { + setTimeout(callback, 0); + }; + })(); - for (var i = 0, l = fakes.length; i < l; i += 1) { - if (typeof fakes[i][method] === "function") { - fakes[i][method](); - } + function throwsException(error, message) { + if (typeof error === "string") { + this.exception = new Error(message || ""); + this.exception.name = error; + } else if (!error) { + this.exception = new Error("Error"); + } else { + this.exception = error; } + + return this; } - function compact(fakeCollection) { - var fakes = getFakes(fakeCollection); - var i = 0; - while (i < fakes.length) { - fakes.splice(i, 1); + function getCallback(behavior, args) { + var callArgAt = behavior.callArgAt; + + if (callArgAt >= 0) { + return args[callArgAt]; } - } - function makeApi(sinon) { - var collection = { - verify: function resolve() { - each(this, "verify"); - }, + var argumentList; - restore: function restore() { - each(this, "restore"); - compact(this); - }, + if (callArgAt === useLeftMostCallback) { + argumentList = args; + } - reset: function restore() { - each(this, "reset"); - }, + if (callArgAt === useRightMostCallback) { + argumentList = slice.call(args).reverse(); + } - verifyAndRestore: function verifyAndRestore() { - var exception; + var callArgProp = behavior.callArgProp; - try { - this.verify(); - } catch (e) { - exception = e; - } + for (var i = 0, l = argumentList.length; i < l; ++i) { + if (!callArgProp && typeof argumentList[i] === "function") { + return argumentList[i]; + } - this.restore(); + if (callArgProp && argumentList[i] && + typeof argumentList[i][callArgProp] === "function") { + return argumentList[i][callArgProp]; + } + } - if (exception) { - throw exception; + return null; + } + + function makeApi(sinon) { + function getCallbackError(behavior, func, args) { + if (behavior.callArgAt < 0) { + var msg; + + if (behavior.callArgProp) { + msg = sinon.functionName(behavior.stub) + + " expected to yield to '" + behavior.callArgProp + + "', but no object with such a property was passed."; + } else { + msg = sinon.functionName(behavior.stub) + + " expected to yield, but no callback was passed."; } - }, - add: function add(fake) { - push.call(getFakes(this), fake); - return fake; - }, + if (args.length > 0) { + msg += " Received [" + join.call(args, ", ") + "]"; + } - spy: function spy() { - return this.add(sinon.spy.apply(sinon, arguments)); - }, + return msg; + } - stub: function stub(object, property, value) { - if (property) { - var original = object[property]; + return "argument at index " + behavior.callArgAt + " is not a function: " + func; + } - if (typeof original !== "function") { - if (!hasOwnProperty.call(object, property)) { - throw new TypeError("Cannot stub non-existent own property " + property); - } + function callCallback(behavior, args) { + if (typeof behavior.callArgAt === "number") { + var func = getCallback(behavior, args); - object[property] = value; + if (typeof func !== "function") { + throw new TypeError(getCallbackError(behavior, func, args)); + } - return this.add({ - restore: function () { - object[property] = original; - } - }); - } + if (behavior.callbackAsync) { + nextTick(function () { + func.apply(behavior.callbackContext, behavior.callbackArguments); + }); + } else { + func.apply(behavior.callbackContext, behavior.callbackArguments); } - if (!property && !!object && typeof object === "object") { - var stubbedObj = sinon.stub.apply(sinon, arguments); + } + } - for (var prop in stubbedObj) { - if (typeof stubbedObj[prop] === "function") { - this.add(stubbedObj[prop]); - } - } + var proto = { + create: function create(stub) { + var behavior = sinon.extend({}, sinon.behavior); + delete behavior.create; + behavior.stub = stub; - return stubbedObj; + return behavior; + }, + + isPresent: function isPresent() { + return (typeof this.callArgAt === "number" || + this.exception || + typeof this.returnArgAt === "number" || + this.returnThis || + this.returnValueDefined); + }, + + invoke: function invoke(context, args) { + callCallback(this, args); + + if (this.exception) { + throw this.exception; + } else if (typeof this.returnArgAt === "number") { + return args[this.returnArgAt]; + } else if (this.returnThis) { + return context; } - return this.add(sinon.stub.apply(sinon, arguments)); + return this.returnValue; }, - mock: function mock() { - return this.add(sinon.mock.apply(sinon, arguments)); + onCall: function onCall(index) { + return this.stub.onCall(index); }, - inject: function inject(obj) { - var col = this; + onFirstCall: function onFirstCall() { + return this.stub.onFirstCall(); + }, - obj.spy = function () { - return col.spy.apply(col, arguments); - }; + onSecondCall: function onSecondCall() { + return this.stub.onSecondCall(); + }, - obj.stub = function () { - return col.stub.apply(col, arguments); - }; + onThirdCall: function onThirdCall() { + return this.stub.onThirdCall(); + }, - obj.mock = function () { - return col.mock.apply(col, arguments); - }; + withArgs: function withArgs(/* arguments */) { + throw new Error( + "Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" " + + "is not supported. Use \"stub.withArgs(...).onCall(...)\" " + + "to define sequential behavior for calls with certain arguments." + ); + }, - return obj; - } - }; + callsArg: function callsArg(pos) { + if (typeof pos !== "number") { + throw new TypeError("argument index is not number"); + } - sinon.collection = collection; - return collection; - } + this.callArgAt = pos; + this.callbackArguments = []; + this.callbackContext = undefined; + this.callArgProp = undefined; + this.callbackAsync = false; - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + return this; + }, - function loadDependencies(require, exports, module) { - var sinon = require("./util/core"); - require("./mock"); - require("./spy"); - require("./stub"); - module.exports = makeApi(sinon); - } + callsArgOn: function callsArgOn(pos, context) { + if (typeof pos !== "number") { + throw new TypeError("argument index is not number"); + } + if (typeof context !== "object") { + throw new TypeError("argument context is not an object"); + } - if (isAMD) { - define(loadDependencies); - return; - } + this.callArgAt = pos; + this.callbackArguments = []; + this.callbackContext = context; + this.callArgProp = undefined; + this.callbackAsync = false; - if (isNode) { - loadDependencies(require, module.exports, module); - return; - } + return this; + }, - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + callsArgWith: function callsArgWith(pos) { + if (typeof pos !== "number") { + throw new TypeError("argument index is not number"); + } -},{"./mock":23,"./spy":25,"./stub":26,"./util/core":31}],19:[function(require,module,exports){ -/** - * @depend util/core.js - */ -(function (sinonGlobal) { - "use strict"; + this.callArgAt = pos; + this.callbackArguments = slice.call(arguments, 1); + this.callbackContext = undefined; + this.callArgProp = undefined; + this.callbackAsync = false; - function makeApi(sinon) { + return this; + }, - // Adapted from https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug - var hasDontEnumBug = (function () { - var obj = { - constructor: function () { - return "0"; - }, - toString: function () { - return "1"; - }, - valueOf: function () { - return "2"; - }, - toLocaleString: function () { - return "3"; - }, - prototype: function () { - return "4"; - }, - isPrototypeOf: function () { - return "5"; - }, - propertyIsEnumerable: function () { - return "6"; - }, - hasOwnProperty: function () { - return "7"; - }, - length: function () { - return "8"; - }, - unique: function () { - return "9"; + callsArgOnWith: function callsArgWith(pos, context) { + if (typeof pos !== "number") { + throw new TypeError("argument index is not number"); } - }; - - var result = []; - for (var prop in obj) { - if (obj.hasOwnProperty(prop)) { - result.push(obj[prop]()); + if (typeof context !== "object") { + throw new TypeError("argument context is not an object"); } - } - return result.join("") !== "0123456789"; - })(); - /* Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will - * override properties in previous sources. - * - * target - The Object to extend - * sources - Objects to copy properties from. - * - * Returns the extended target - */ - function extend(target /*, sources */) { - var sources = Array.prototype.slice.call(arguments, 1); - var source, i, prop; + this.callArgAt = pos; + this.callbackArguments = slice.call(arguments, 2); + this.callbackContext = context; + this.callArgProp = undefined; + this.callbackAsync = false; - for (i = 0; i < sources.length; i++) { - source = sources[i]; + return this; + }, - for (prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } + yields: function () { + this.callArgAt = useLeftMostCallback; + this.callbackArguments = slice.call(arguments, 0); + this.callbackContext = undefined; + this.callArgProp = undefined; + this.callbackAsync = false; - // Make sure we copy (own) toString method even when in JScript with DontEnum bug - // See https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug - if (hasDontEnumBug && source.hasOwnProperty("toString") && source.toString !== target.toString) { - target.toString = source.toString; - } - } + return this; + }, - return target; - } + yieldsRight: function () { + this.callArgAt = useRightMostCallback; + this.callbackArguments = slice.call(arguments, 0); + this.callbackContext = undefined; + this.callArgProp = undefined; + this.callbackAsync = false; - sinon.extend = extend; - return sinon.extend; - } + return this; + }, - function loadDependencies(require, exports, module) { - var sinon = require("./util/core"); - module.exports = makeApi(sinon); - } + yieldsOn: function (context) { + if (typeof context !== "object") { + throw new TypeError("argument context is not an object"); + } - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + this.callArgAt = useLeftMostCallback; + this.callbackArguments = slice.call(arguments, 1); + this.callbackContext = context; + this.callArgProp = undefined; + this.callbackAsync = false; - if (isAMD) { - define(loadDependencies); - return; - } + return this; + }, - if (isNode) { - loadDependencies(require, module.exports, module); - return; - } + yieldsTo: function (prop) { + this.callArgAt = useLeftMostCallback; + this.callbackArguments = slice.call(arguments, 1); + this.callbackContext = undefined; + this.callArgProp = prop; + this.callbackAsync = false; - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + return this; + }, -},{"./util/core":31}],20:[function(require,module,exports){ -/** - * @depend util/core.js - */ -/** - * Format functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2014 Christian Johansen - */ -(function (sinonGlobal, formatio) { - "use strict"; + yieldsToOn: function (prop, context) { + if (typeof context !== "object") { + throw new TypeError("argument context is not an object"); + } - function makeApi(sinon) { - function valueFormatter(value) { - return "" + value; - } + this.callArgAt = useLeftMostCallback; + this.callbackArguments = slice.call(arguments, 2); + this.callbackContext = context; + this.callArgProp = prop; + this.callbackAsync = false; - function getFormatioFormatter() { - var formatter = formatio.configure({ - quoteStrings: false, - limitChildrenCount: 250 - }); + return this; + }, + + throws: throwsException, + throwsException: throwsException, - function format() { - return formatter.ascii.apply(formatter, arguments); - } + returns: function returns(value) { + this.returnValue = value; + this.returnValueDefined = true; + this.exception = undefined; - return format; - } + return this; + }, - function getNodeFormatter() { - try { - var util = require("util"); - } catch (e) { - /* Node, but no util module - would be very old, but better safe than sorry */ - } + returnsArg: function returnsArg(pos) { + if (typeof pos !== "number") { + throw new TypeError("argument index is not number"); + } - function format(v) { - var isObjectWithNativeToString = typeof v === "object" && v.toString === Object.prototype.toString; - return isObjectWithNativeToString ? util.inspect(v) : v; - } + this.returnArgAt = pos; - return util ? format : valueFormatter; - } + return this; + }, - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var formatter; + returnsThis: function returnsThis() { + this.returnThis = true; - if (isNode) { - try { - formatio = require("formatio"); + return this; } - catch (e) {} // eslint-disable-line no-empty + }; + + function createAsyncVersion(syncFnName) { + return function () { + var result = this[syncFnName].apply(this, arguments); + this.callbackAsync = true; + return result; + }; } - if (formatio) { - formatter = getFormatioFormatter(); - } else if (isNode) { - formatter = getNodeFormatter(); - } else { - formatter = valueFormatter; + // create asynchronous versions of callsArg* and yields* methods + for (var method in proto) { + // need to avoid creating anotherasync versions of the newly added async methods + if (proto.hasOwnProperty(method) && method.match(/^(callsArg|yields)/) && !method.match(/Async/)) { + proto[method + "Async"] = createAsyncVersion(method); + } } - sinon.format = formatter; - return sinon.format; + sinon.behavior = proto; + return proto; } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + function loadDependencies(require, exports, module) { var sinon = require("./util/core"); + require("./extend"); module.exports = makeApi(sinon); } - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - if (isAMD) { define(loadDependencies); return; @@ -3109,331 +2729,222 @@ var sinon = (function () { // eslint-disable-line no-unused-vars makeApi(sinonGlobal); } }( - typeof sinon === "object" && sinon, // eslint-disable-line no-undef - typeof formatio === "object" && formatio // eslint-disable-line no-undef + typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./util/core":31,"formatio":39,"util":13}],21:[function(require,module,exports){ +}).call(this,require('_process')) +},{"./extend":20,"./util/core":32,"_process":13}],18:[function(require,module,exports){ /** - * @depend util/core.js - */ + * @depend util/core.js + * @depend match.js + * @depend format.js + */ /** - * Logs errors - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2014 Christian Johansen - */ + * Spy calls + * + * @author Christian Johansen (christian@cjohansen.no) + * @author Maximilian Antoni (mail@maxantoni.de) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + * Copyright (c) 2013 Maximilian Antoni + */ (function (sinonGlobal) { "use strict"; - // cache a reference to setTimeout, so that our reference won't be stubbed out - // when using fake timers and errors will still get logged - // https://github.com/cjohansen/Sinon.JS/issues/381 - var realSetTimeout = setTimeout; + var slice = Array.prototype.slice; function makeApi(sinon) { - - function log() {} - - function logError(label, err) { - var msg = label + " threw exception: "; - - function throwLoggedError() { - err.message = msg + err.message; - throw err; + function throwYieldError(proxy, text, args) { + var msg = sinon.functionName(proxy) + text; + if (args.length) { + msg += " Received [" + slice.call(args).join(", ") + "]"; } + throw new Error(msg); + } - sinon.log(msg + "[" + err.name + "] " + err.message); + var callProto = { + calledOn: function calledOn(thisValue) { + if (sinon.match && sinon.match.isMatcher(thisValue)) { + return thisValue.test(this.thisValue); + } + return this.thisValue === thisValue; + }, - if (err.stack) { - sinon.log(err.stack); - } + calledWith: function calledWith() { + var l = arguments.length; + if (l > this.args.length) { + return false; + } + for (var i = 0; i < l; i += 1) { + if (!sinon.deepEqual(arguments[i], this.args[i])) { + return false; + } + } - if (logError.useImmediateExceptions) { - throwLoggedError(); - } else { - logError.setTimeout(throwLoggedError, 0); - } - } + return true; + }, - // When set to true, any errors logged will be thrown immediately; - // If set to false, the errors will be thrown in separate execution frame. - logError.useImmediateExceptions = false; + calledWithMatch: function calledWithMatch() { + var l = arguments.length; + if (l > this.args.length) { + return false; + } + for (var i = 0; i < l; i += 1) { + var actual = this.args[i]; + var expectation = arguments[i]; + if (!sinon.match || !sinon.match(expectation).test(actual)) { + return false; + } + } + return true; + }, - // wrap realSetTimeout with something we can stub in tests - logError.setTimeout = function (func, timeout) { - realSetTimeout(func, timeout); - }; + calledWithExactly: function calledWithExactly() { + return arguments.length === this.args.length && + this.calledWith.apply(this, arguments); + }, - var exports = {}; - exports.log = sinon.log = log; - exports.logError = sinon.logError = logError; + notCalledWith: function notCalledWith() { + return !this.calledWith.apply(this, arguments); + }, - return exports; - } + notCalledWithMatch: function notCalledWithMatch() { + return !this.calledWithMatch.apply(this, arguments); + }, - function loadDependencies(require, exports, module) { - var sinon = require("./util/core"); - module.exports = makeApi(sinon); - } + returned: function returned(value) { + return sinon.deepEqual(value, this.returnValue); + }, - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + threw: function threw(error) { + if (typeof error === "undefined" || !this.exception) { + return !!this.exception; + } - if (isAMD) { - define(loadDependencies); - return; - } + return this.exception === error || this.exception.name === error; + }, - if (isNode) { - loadDependencies(require, module.exports, module); - return; - } + calledWithNew: function calledWithNew() { + return this.proxy.prototype && this.thisValue instanceof this.proxy; + }, - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + calledBefore: function (other) { + return this.callId < other.callId; + }, -},{"./util/core":31}],22:[function(require,module,exports){ -/** - * @depend util/core.js - * @depend typeOf.js - */ -/*jslint eqeqeq: false, onevar: false, plusplus: false*/ -/*global module, require, sinon*/ -/** - * Match functions - * - * @author Maximilian Antoni (mail@maxantoni.de) - * @license BSD - * - * Copyright (c) 2012 Maximilian Antoni - */ -(function (sinonGlobal) { - "use strict"; + calledAfter: function (other) { + return this.callId > other.callId; + }, - function makeApi(sinon) { - function assertType(value, type, name) { - var actual = sinon.typeOf(value); - if (actual !== type) { - throw new TypeError("Expected type of " + name + " to be " + - type + ", but was " + actual); - } - } + callArg: function (pos) { + this.args[pos](); + }, - var matcher = { - toString: function () { - return this.message; - } - }; + callArgOn: function (pos, thisValue) { + this.args[pos].apply(thisValue); + }, + + callArgWith: function (pos) { + this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1))); + }, - function isMatcher(object) { - return matcher.isPrototypeOf(object); - } + callArgOnWith: function (pos, thisValue) { + var args = slice.call(arguments, 2); + this.args[pos].apply(thisValue, args); + }, - function matchObject(expectation, actual) { - if (actual === null || actual === undefined) { - return false; - } - for (var key in expectation) { - if (expectation.hasOwnProperty(key)) { - var exp = expectation[key]; - var act = actual[key]; - if (isMatcher(exp)) { - if (!exp.test(act)) { - return false; - } - } else if (sinon.typeOf(exp) === "object") { - if (!matchObject(exp, act)) { - return false; - } - } else if (!sinon.deepEqual(exp, act)) { - return false; - } - } - } - return true; - } + "yield": function () { + this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0))); + }, - function match(expectation, message) { - var m = sinon.create(matcher); - var type = sinon.typeOf(expectation); - switch (type) { - case "object": - if (typeof expectation.test === "function") { - m.test = function (actual) { - return expectation.test(actual) === true; - }; - m.message = "match(" + sinon.functionName(expectation.test) + ")"; - return m; - } - var str = []; - for (var key in expectation) { - if (expectation.hasOwnProperty(key)) { - str.push(key + ": " + expectation[key]); + yieldOn: function (thisValue) { + var args = this.args; + for (var i = 0, l = args.length; i < l; ++i) { + if (typeof args[i] === "function") { + args[i].apply(thisValue, slice.call(arguments, 1)); + return; } } - m.test = function (actual) { - return matchObject(expectation, actual); - }; - m.message = "match(" + str.join(", ") + ")"; - break; - case "number": - m.test = function (actual) { - // we need type coercion here - return expectation == actual; // eslint-disable-line eqeqeq - }; - break; - case "string": - m.test = function (actual) { - if (typeof actual !== "string") { - return false; - } - return actual.indexOf(expectation) !== -1; - }; - m.message = "match(\"" + expectation + "\")"; - break; - case "regexp": - m.test = function (actual) { - if (typeof actual !== "string") { - return false; + throwYieldError(this.proxy, " cannot yield since no callback was passed.", args); + }, + + yieldTo: function (prop) { + this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1))); + }, + + yieldToOn: function (prop, thisValue) { + var args = this.args; + for (var i = 0, l = args.length; i < l; ++i) { + if (args[i] && typeof args[i][prop] === "function") { + args[i][prop].apply(thisValue, slice.call(arguments, 2)); + return; } - return expectation.test(actual); - }; - break; - case "function": - m.test = expectation; - if (message) { - m.message = message; - } else { - m.message = "match(" + sinon.functionName(expectation) + ")"; } - break; - default: - m.test = function (actual) { - return sinon.deepEqual(expectation, actual); - }; - } - if (!m.message) { - m.message = "match(" + expectation + ")"; - } - return m; - } + throwYieldError(this.proxy, " cannot yield to '" + prop + + "' since no callback was passed.", args); + }, - matcher.or = function (m2) { - if (!arguments.length) { - throw new TypeError("Matcher expected"); - } else if (!isMatcher(m2)) { - m2 = match(m2); - } - var m1 = this; - var or = sinon.create(matcher); - or.test = function (actual) { - return m1.test(actual) || m2.test(actual); - }; - or.message = m1.message + ".or(" + m2.message + ")"; - return or; - }; + getStackFrames: function () { + // Omit the error message and the two top stack frames in sinon itself: + return this.stack && this.stack.split("\n").slice(3); + }, - matcher.and = function (m2) { - if (!arguments.length) { - throw new TypeError("Matcher expected"); - } else if (!isMatcher(m2)) { - m2 = match(m2); - } - var m1 = this; - var and = sinon.create(matcher); - and.test = function (actual) { - return m1.test(actual) && m2.test(actual); - }; - and.message = m1.message + ".and(" + m2.message + ")"; - return and; - }; + toString: function () { + var callStr = this.proxy ? this.proxy.toString() + "(" : ""; + var args = []; - match.isMatcher = isMatcher; + if (!this.args) { + return ":("; + } - match.any = match(function () { - return true; - }, "any"); + for (var i = 0, l = this.args.length; i < l; ++i) { + args.push(sinon.format(this.args[i])); + } - match.defined = match(function (actual) { - return actual !== null && actual !== undefined; - }, "defined"); + callStr = callStr + args.join(", ") + ")"; - match.truthy = match(function (actual) { - return !!actual; - }, "truthy"); + if (typeof this.returnValue !== "undefined") { + callStr += " => " + sinon.format(this.returnValue); + } - match.falsy = match(function (actual) { - return !actual; - }, "falsy"); + if (this.exception) { + callStr += " !" + this.exception.name; - match.same = function (expectation) { - return match(function (actual) { - return expectation === actual; - }, "same(" + expectation + ")"); - }; + if (this.exception.message) { + callStr += "(" + this.exception.message + ")"; + } + } + if (this.stack) { + callStr += this.getStackFrames()[0].replace(/^\s*(?:at\s+|@)?/, " at "); - match.typeOf = function (type) { - assertType(type, "string", "type"); - return match(function (actual) { - return sinon.typeOf(actual) === type; - }, "typeOf(\"" + type + "\")"); - }; + } - match.instanceOf = function (type) { - assertType(type, "function", "type"); - return match(function (actual) { - return actual instanceof type; - }, "instanceOf(" + sinon.functionName(type) + ")"); + return callStr; + } }; - function createPropertyMatcher(propertyTest, messagePrefix) { - return function (property, value) { - assertType(property, "string", "property"); - var onlyProperty = arguments.length === 1; - var message = messagePrefix + "(\"" + property + "\""; - if (!onlyProperty) { - message += ", " + value; - } - message += ")"; - return match(function (actual) { - if (actual === undefined || actual === null || - !propertyTest(actual, property)) { - return false; - } - return onlyProperty || sinon.deepEqual(value, actual[property]); - }, message); - }; - } + callProto.invokeCallback = callProto.yield; - match.has = createPropertyMatcher(function (actual, property) { - if (typeof actual === "object") { - return property in actual; + function createSpyCall(spy, thisValue, args, returnValue, exception, id, stack) { + if (typeof id !== "number") { + throw new TypeError("Call id is not a number"); } - return actual[property] !== undefined; - }, "has"); - - match.hasOwn = createPropertyMatcher(function (actual, property) { - return actual.hasOwnProperty(property); - }, "hasOwn"); + var proxyCall = sinon.create(callProto); + proxyCall.proxy = spy; + proxyCall.thisValue = thisValue; + proxyCall.args = args; + proxyCall.returnValue = returnValue; + proxyCall.exception = exception; + proxyCall.callId = id; + proxyCall.stack = stack; - match.bool = match.typeOf("boolean"); - match.number = match.typeOf("number"); - match.string = match.typeOf("string"); - match.object = match.typeOf("object"); - match.func = match.typeOf("function"); - match.array = match.typeOf("array"); - match.regexp = match.typeOf("regexp"); - match.date = match.typeOf("date"); + return proxyCall; + } + createSpyCall.toString = callProto.toString; // used by mocks - sinon.match = match; - return match; + sinon.spyCall = createSpyCall; + return createSpyCall; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; @@ -3441,7 +2952,8 @@ var sinon = (function () { // eslint-disable-line no-unused-vars function loadDependencies(require, exports, module) { var sinon = require("./util/core"); - require("./typeOf"); + require("./match"); + require("./format"); module.exports = makeApi(sinon); } @@ -3462,19 +2974,15 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./typeOf":30,"./util/core":31}],23:[function(require,module,exports){ +},{"./format":21,"./match":23,"./util/core":32}],19:[function(require,module,exports){ /** - * @depend times_in_words.js * @depend util/core.js - * @depend call.js - * @depend extend.js - * @depend match.js * @depend spy.js * @depend stub.js - * @depend format.js + * @depend mock.js */ /** - * Mock functions. + * Collections of stubs, spies and mocks. * * @author Christian Johansen (christian@cjohansen.no) * @license BSD @@ -3484,442 +2992,693 @@ var sinon = (function () { // eslint-disable-line no-unused-vars (function (sinonGlobal) { "use strict"; - function makeApi(sinon) { - var push = [].push; - var match = sinon.match; + var push = [].push; + var hasOwnProperty = Object.prototype.hasOwnProperty; - function mock(object) { - // if (typeof console !== undefined && console.warn) { - // console.warn("mock will be removed from Sinon.JS v2.0"); - // } + function getFakes(fakeCollection) { + if (!fakeCollection.fakes) { + fakeCollection.fakes = []; + } - if (!object) { - return sinon.expectation.create("Anonymous mock"); - } + return fakeCollection.fakes; + } - return mock.create(object); - } + function each(fakeCollection, method) { + var fakes = getFakes(fakeCollection); - function each(collection, callback) { - if (!collection) { - return; + for (var i = 0, l = fakes.length; i < l; i += 1) { + if (typeof fakes[i][method] === "function") { + fakes[i][method](); } + } + } - for (var i = 0, l = collection.length; i < l; i += 1) { - callback(collection[i]); - } + function compact(fakeCollection) { + var fakes = getFakes(fakeCollection); + var i = 0; + while (i < fakes.length) { + fakes.splice(i, 1); } + } - function arrayEquals(arr1, arr2, compareLength) { - if (compareLength && (arr1.length !== arr2.length)) { - return false; - } + function makeApi(sinon) { + var collection = { + verify: function resolve() { + each(this, "verify"); + }, - for (var i = 0, l = arr1.length; i < l; i++) { - if (!sinon.deepEqual(arr1[i], arr2[i])) { - return false; + restore: function restore() { + each(this, "restore"); + compact(this); + }, + + reset: function restore() { + each(this, "reset"); + }, + + verifyAndRestore: function verifyAndRestore() { + var exception; + + try { + this.verify(); + } catch (e) { + exception = e; } - } - return true; - } - sinon.extend(mock, { - create: function create(object) { - if (!object) { - throw new TypeError("object is null"); + this.restore(); + + if (exception) { + throw exception; } + }, - var mockObject = sinon.extend({}, mock); - mockObject.object = object; - delete mockObject.create; + add: function add(fake) { + push.call(getFakes(this), fake); + return fake; + }, - return mockObject; + spy: function spy() { + return this.add(sinon.spy.apply(sinon, arguments)); }, - expects: function expects(method) { - if (!method) { - throw new TypeError("method is falsy"); - } + stub: function stub(object, property, value) { + if (property) { + var original = object[property]; - if (!this.expectations) { - this.expectations = {}; - this.proxies = []; - } + if (typeof original !== "function") { + if (!hasOwnProperty.call(object, property)) { + throw new TypeError("Cannot stub non-existent own property " + property); + } - if (!this.expectations[method]) { - this.expectations[method] = []; - var mockObject = this; + object[property] = value; - sinon.wrapMethod(this.object, method, function () { - return mockObject.invokeMethod(method, this, arguments); - }); + return this.add({ + restore: function () { + object[property] = original; + } + }); + } + } + if (!property && !!object && typeof object === "object") { + var stubbedObj = sinon.stub.apply(sinon, arguments); - push.call(this.proxies, method); + for (var prop in stubbedObj) { + if (typeof stubbedObj[prop] === "function") { + this.add(stubbedObj[prop]); + } + } + + return stubbedObj; } - var expectation = sinon.expectation.create(method); - push.call(this.expectations[method], expectation); + return this.add(sinon.stub.apply(sinon, arguments)); + }, - return expectation; + mock: function mock() { + return this.add(sinon.mock.apply(sinon, arguments)); }, - restore: function restore() { - var object = this.object; + inject: function inject(obj) { + var col = this; - each(this.proxies, function (proxy) { - if (typeof object[proxy].restore === "function") { - object[proxy].restore(); - } - }); - }, + obj.spy = function () { + return col.spy.apply(col, arguments); + }; - verify: function verify() { - var expectations = this.expectations || {}; - var messages = []; - var met = []; + obj.stub = function () { + return col.stub.apply(col, arguments); + }; - each(this.proxies, function (proxy) { - each(expectations[proxy], function (expectation) { - if (!expectation.met()) { - push.call(messages, expectation.toString()); - } else { - push.call(met, expectation.toString()); - } - }); - }); + obj.mock = function () { + return col.mock.apply(col, arguments); + }; - this.restore(); + return obj; + } + }; + + sinon.collection = collection; + return collection; + } + + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + + function loadDependencies(require, exports, module) { + var sinon = require("./util/core"); + require("./mock"); + require("./spy"); + require("./stub"); + module.exports = makeApi(sinon); + } + + if (isAMD) { + define(loadDependencies); + return; + } + + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } + + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); + +},{"./mock":24,"./spy":26,"./stub":27,"./util/core":32}],20:[function(require,module,exports){ +/** + * @depend util/core.js + */ +(function (sinonGlobal) { + "use strict"; + + function makeApi(sinon) { + + // Adapted from https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug + var hasDontEnumBug = (function () { + var obj = { + constructor: function () { + return "0"; + }, + toString: function () { + return "1"; + }, + valueOf: function () { + return "2"; + }, + toLocaleString: function () { + return "3"; + }, + prototype: function () { + return "4"; + }, + isPrototypeOf: function () { + return "5"; + }, + propertyIsEnumerable: function () { + return "6"; + }, + hasOwnProperty: function () { + return "7"; + }, + length: function () { + return "8"; + }, + unique: function () { + return "9"; + } + }; - if (messages.length > 0) { - sinon.expectation.fail(messages.concat(met).join("\n")); - } else if (met.length > 0) { - sinon.expectation.pass(messages.concat(met).join("\n")); + var result = []; + for (var prop in obj) { + if (obj.hasOwnProperty(prop)) { + result.push(obj[prop]()); } + } + return result.join("") !== "0123456789"; + })(); - return true; - }, + /* Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will + * override properties in previous sources. + * + * target - The Object to extend + * sources - Objects to copy properties from. + * + * Returns the extended target + */ + function extend(target /*, sources */) { + var sources = Array.prototype.slice.call(arguments, 1); + var source, i, prop; - invokeMethod: function invokeMethod(method, thisValue, args) { - var expectations = this.expectations && this.expectations[method] ? this.expectations[method] : []; - var expectationsWithMatchingArgs = []; - var currentArgs = args || []; - var i, available; + for (i = 0; i < sources.length; i++) { + source = sources[i]; - for (i = 0; i < expectations.length; i += 1) { - var expectedArgs = expectations[i].expectedArguments || []; - if (arrayEquals(expectedArgs, currentArgs, expectations[i].expectsExactArgCount)) { - expectationsWithMatchingArgs.push(expectations[i]); + for (prop in source) { + if (source.hasOwnProperty(prop)) { + target[prop] = source[prop]; } } - for (i = 0; i < expectationsWithMatchingArgs.length; i += 1) { - if (!expectationsWithMatchingArgs[i].met() && - expectationsWithMatchingArgs[i].allowsCall(thisValue, args)) { - return expectationsWithMatchingArgs[i].apply(thisValue, args); - } + // Make sure we copy (own) toString method even when in JScript with DontEnum bug + // See https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug + if (hasDontEnumBug && source.hasOwnProperty("toString") && source.toString !== target.toString) { + target.toString = source.toString; } + } - var messages = []; - var exhausted = 0; + return target; + } - for (i = 0; i < expectationsWithMatchingArgs.length; i += 1) { - if (expectationsWithMatchingArgs[i].allowsCall(thisValue, args)) { - available = available || expectationsWithMatchingArgs[i]; - } else { - exhausted += 1; - } - } + sinon.extend = extend; + return sinon.extend; + } - if (available && exhausted === 0) { - return available.apply(thisValue, args); - } + function loadDependencies(require, exports, module) { + var sinon = require("./util/core"); + module.exports = makeApi(sinon); + } - for (i = 0; i < expectations.length; i += 1) { - push.call(messages, " " + expectations[i].toString()); - } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - messages.unshift("Unexpected call: " + sinon.spyCall.toString.call({ - proxy: method, - args: args - })); + if (isAMD) { + define(loadDependencies); + return; + } - sinon.expectation.fail(messages.join("\n")); - } - }); + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } - var times = sinon.timesInWords; - var slice = Array.prototype.slice; + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); - function callCountInWords(callCount) { - if (callCount === 0) { - return "never called"; - } +},{"./util/core":32}],21:[function(require,module,exports){ +/** + * @depend util/core.js + */ +/** + * Format functions + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2014 Christian Johansen + */ +(function (sinonGlobal, formatio) { + "use strict"; - return "called " + times(callCount); + function makeApi(sinon) { + function valueFormatter(value) { + return "" + value; } - function expectedCallCountInWords(expectation) { - var min = expectation.minCalls; - var max = expectation.maxCalls; + function getFormatioFormatter() { + var formatter = formatio.configure({ + quoteStrings: false, + limitChildrenCount: 250 + }); - if (typeof min === "number" && typeof max === "number") { - var str = times(min); + function format() { + return formatter.ascii.apply(formatter, arguments); + } - if (min !== max) { - str = "at least " + str + " and at most " + times(max); - } + return format; + } - return str; + function getNodeFormatter() { + try { + var util = require("util"); + } catch (e) { + /* Node, but no util module - would be very old, but better safe than sorry */ } - if (typeof min === "number") { - return "at least " + times(min); + function format(v) { + var isObjectWithNativeToString = typeof v === "object" && v.toString === Object.prototype.toString; + return isObjectWithNativeToString ? util.inspect(v) : v; } - return "at most " + times(max); + return util ? format : valueFormatter; } - function receivedMinCalls(expectation) { - var hasMinLimit = typeof expectation.minCalls === "number"; - return !hasMinLimit || expectation.callCount >= expectation.minCalls; - } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var formatter; - function receivedMaxCalls(expectation) { - if (typeof expectation.maxCalls !== "number") { - return false; + if (isNode) { + try { + formatio = require("formatio"); } - - return expectation.callCount === expectation.maxCalls; + catch (e) {} // eslint-disable-line no-empty } - function verifyMatcher(possibleMatcher, arg) { - var isMatcher = match && match.isMatcher(possibleMatcher); - - return isMatcher && possibleMatcher.test(arg) || true; + if (formatio) { + formatter = getFormatioFormatter(); + } else if (isNode) { + formatter = getNodeFormatter(); + } else { + formatter = valueFormatter; } - sinon.expectation = { - minCalls: 1, - maxCalls: 1, - - create: function create(methodName) { - var expectation = sinon.extend(sinon.stub.create(), sinon.expectation); - delete expectation.create; - expectation.method = methodName; - - return expectation; - }, - - invoke: function invoke(func, thisValue, args) { - this.verifyCallAllowed(thisValue, args); - - return sinon.spy.invoke.apply(this, arguments); - }, - - atLeast: function atLeast(num) { - if (typeof num !== "number") { - throw new TypeError("'" + num + "' is not number"); - } + sinon.format = formatter; + return sinon.format; + } - if (!this.limitsSet) { - this.maxCalls = null; - this.limitsSet = true; - } + function loadDependencies(require, exports, module) { + var sinon = require("./util/core"); + module.exports = makeApi(sinon); + } - this.minCalls = num; + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - return this; - }, + if (isAMD) { + define(loadDependencies); + return; + } - atMost: function atMost(num) { - if (typeof num !== "number") { - throw new TypeError("'" + num + "' is not number"); - } + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } - if (!this.limitsSet) { - this.minCalls = null; - this.limitsSet = true; - } + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon, // eslint-disable-line no-undef + typeof formatio === "object" && formatio // eslint-disable-line no-undef +)); - this.maxCalls = num; +},{"./util/core":32,"formatio":10,"util":41}],22:[function(require,module,exports){ +/** + * @depend util/core.js + */ +/** + * Logs errors + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2014 Christian Johansen + */ +(function (sinonGlobal) { + "use strict"; - return this; - }, + // cache a reference to setTimeout, so that our reference won't be stubbed out + // when using fake timers and errors will still get logged + // https://github.com/cjohansen/Sinon.JS/issues/381 + var realSetTimeout = setTimeout; - never: function never() { - return this.exactly(0); - }, + function makeApi(sinon) { - once: function once() { - return this.exactly(1); - }, + function log() {} - twice: function twice() { - return this.exactly(2); - }, + function logError(label, err) { + var msg = label + " threw exception: "; - thrice: function thrice() { - return this.exactly(3); - }, + function throwLoggedError() { + err.message = msg + err.message; + throw err; + } - exactly: function exactly(num) { - if (typeof num !== "number") { - throw new TypeError("'" + num + "' is not a number"); - } + sinon.log(msg + "[" + err.name + "] " + err.message); - this.atLeast(num); - return this.atMost(num); - }, + if (err.stack) { + sinon.log(err.stack); + } - met: function met() { - return !this.failed && receivedMinCalls(this); - }, + if (logError.useImmediateExceptions) { + throwLoggedError(); + } else { + logError.setTimeout(throwLoggedError, 0); + } + } - verifyCallAllowed: function verifyCallAllowed(thisValue, args) { - if (receivedMaxCalls(this)) { - this.failed = true; - sinon.expectation.fail(this.method + " already called " + times(this.maxCalls)); - } + // When set to true, any errors logged will be thrown immediately; + // If set to false, the errors will be thrown in separate execution frame. + logError.useImmediateExceptions = false; - if ("expectedThis" in this && this.expectedThis !== thisValue) { - sinon.expectation.fail(this.method + " called with " + thisValue + " as thisValue, expected " + - this.expectedThis); - } + // wrap realSetTimeout with something we can stub in tests + logError.setTimeout = function (func, timeout) { + realSetTimeout(func, timeout); + }; - if (!("expectedArguments" in this)) { - return; - } + var exports = {}; + exports.log = sinon.log = log; + exports.logError = sinon.logError = logError; - if (!args) { - sinon.expectation.fail(this.method + " received no arguments, expected " + - sinon.format(this.expectedArguments)); - } + return exports; + } - if (args.length < this.expectedArguments.length) { - sinon.expectation.fail(this.method + " received too few arguments (" + sinon.format(args) + - "), expected " + sinon.format(this.expectedArguments)); - } + function loadDependencies(require, exports, module) { + var sinon = require("./util/core"); + module.exports = makeApi(sinon); + } - if (this.expectsExactArgCount && - args.length !== this.expectedArguments.length) { - sinon.expectation.fail(this.method + " received too many arguments (" + sinon.format(args) + - "), expected " + sinon.format(this.expectedArguments)); - } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) { + if (isAMD) { + define(loadDependencies); + return; + } - if (!verifyMatcher(this.expectedArguments[i], args[i])) { - sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + - ", didn't match " + this.expectedArguments.toString()); - } + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } - if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { - sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + - ", expected " + sinon.format(this.expectedArguments)); - } - } - }, + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); - allowsCall: function allowsCall(thisValue, args) { - if (this.met() && receivedMaxCalls(this)) { - return false; - } +},{"./util/core":32}],23:[function(require,module,exports){ +/** + * @depend util/core.js + * @depend typeOf.js + */ +/*jslint eqeqeq: false, onevar: false, plusplus: false*/ +/*global module, require, sinon*/ +/** + * Match functions + * + * @author Maximilian Antoni (mail@maxantoni.de) + * @license BSD + * + * Copyright (c) 2012 Maximilian Antoni + */ +(function (sinonGlobal) { + "use strict"; - if ("expectedThis" in this && this.expectedThis !== thisValue) { - return false; - } + function makeApi(sinon) { + function assertType(value, type, name) { + var actual = sinon.typeOf(value); + if (actual !== type) { + throw new TypeError("Expected type of " + name + " to be " + + type + ", but was " + actual); + } + } - if (!("expectedArguments" in this)) { - return true; - } + var matcher = { + toString: function () { + return this.message; + } + }; - args = args || []; + function isMatcher(object) { + return matcher.isPrototypeOf(object); + } - if (args.length < this.expectedArguments.length) { - return false; + function matchObject(expectation, actual) { + if (actual === null || actual === undefined) { + return false; + } + for (var key in expectation) { + if (expectation.hasOwnProperty(key)) { + var exp = expectation[key]; + var act = actual[key]; + if (isMatcher(exp)) { + if (!exp.test(act)) { + return false; + } + } else if (sinon.typeOf(exp) === "object") { + if (!matchObject(exp, act)) { + return false; + } + } else if (!sinon.deepEqual(exp, act)) { + return false; + } } + } + return true; + } - if (this.expectsExactArgCount && - args.length !== this.expectedArguments.length) { - return false; + function match(expectation, message) { + var m = sinon.create(matcher); + var type = sinon.typeOf(expectation); + switch (type) { + case "object": + if (typeof expectation.test === "function") { + m.test = function (actual) { + return expectation.test(actual) === true; + }; + m.message = "match(" + sinon.functionName(expectation.test) + ")"; + return m; } - - for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) { - if (!verifyMatcher(this.expectedArguments[i], args[i])) { + var str = []; + for (var key in expectation) { + if (expectation.hasOwnProperty(key)) { + str.push(key + ": " + expectation[key]); + } + } + m.test = function (actual) { + return matchObject(expectation, actual); + }; + m.message = "match(" + str.join(", ") + ")"; + break; + case "number": + m.test = function (actual) { + // we need type coercion here + return expectation == actual; // eslint-disable-line eqeqeq + }; + break; + case "string": + m.test = function (actual) { + if (typeof actual !== "string") { return false; } - - if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { + return actual.indexOf(expectation) !== -1; + }; + m.message = "match(\"" + expectation + "\")"; + break; + case "regexp": + m.test = function (actual) { + if (typeof actual !== "string") { return false; } + return expectation.test(actual); + }; + break; + case "function": + m.test = expectation; + if (message) { + m.message = message; + } else { + m.message = "match(" + sinon.functionName(expectation) + ")"; } + break; + default: + m.test = function (actual) { + return sinon.deepEqual(expectation, actual); + }; + } + if (!m.message) { + m.message = "match(" + expectation + ")"; + } + return m; + } - return true; - }, + matcher.or = function (m2) { + if (!arguments.length) { + throw new TypeError("Matcher expected"); + } else if (!isMatcher(m2)) { + m2 = match(m2); + } + var m1 = this; + var or = sinon.create(matcher); + or.test = function (actual) { + return m1.test(actual) || m2.test(actual); + }; + or.message = m1.message + ".or(" + m2.message + ")"; + return or; + }; - withArgs: function withArgs() { - this.expectedArguments = slice.call(arguments); - return this; - }, + matcher.and = function (m2) { + if (!arguments.length) { + throw new TypeError("Matcher expected"); + } else if (!isMatcher(m2)) { + m2 = match(m2); + } + var m1 = this; + var and = sinon.create(matcher); + and.test = function (actual) { + return m1.test(actual) && m2.test(actual); + }; + and.message = m1.message + ".and(" + m2.message + ")"; + return and; + }; - withExactArgs: function withExactArgs() { - this.withArgs.apply(this, arguments); - this.expectsExactArgCount = true; - return this; - }, + match.isMatcher = isMatcher; - on: function on(thisValue) { - this.expectedThis = thisValue; - return this; - }, + match.any = match(function () { + return true; + }, "any"); - toString: function () { - var args = (this.expectedArguments || []).slice(); + match.defined = match(function (actual) { + return actual !== null && actual !== undefined; + }, "defined"); - if (!this.expectsExactArgCount) { - push.call(args, "[...]"); - } + match.truthy = match(function (actual) { + return !!actual; + }, "truthy"); - var callStr = sinon.spyCall.toString.call({ - proxy: this.method || "anonymous mock expectation", - args: args - }); + match.falsy = match(function (actual) { + return !actual; + }, "falsy"); - var message = callStr.replace(", [...", "[, ...") + " " + - expectedCallCountInWords(this); + match.same = function (expectation) { + return match(function (actual) { + return expectation === actual; + }, "same(" + expectation + ")"); + }; - if (this.met()) { - return "Expectation met: " + message; - } + match.typeOf = function (type) { + assertType(type, "string", "type"); + return match(function (actual) { + return sinon.typeOf(actual) === type; + }, "typeOf(\"" + type + "\")"); + }; - return "Expected " + message + " (" + - callCountInWords(this.callCount) + ")"; - }, + match.instanceOf = function (type) { + assertType(type, "function", "type"); + return match(function (actual) { + return actual instanceof type; + }, "instanceOf(" + sinon.functionName(type) + ")"); + }; - verify: function verify() { - if (!this.met()) { - sinon.expectation.fail(this.toString()); - } else { - sinon.expectation.pass(this.toString()); + function createPropertyMatcher(propertyTest, messagePrefix) { + return function (property, value) { + assertType(property, "string", "property"); + var onlyProperty = arguments.length === 1; + var message = messagePrefix + "(\"" + property + "\""; + if (!onlyProperty) { + message += ", " + value; } + message += ")"; + return match(function (actual) { + if (actual === undefined || actual === null || + !propertyTest(actual, property)) { + return false; + } + return onlyProperty || sinon.deepEqual(value, actual[property]); + }, message); + }; + } - return true; - }, - - pass: function pass(message) { - sinon.assert.pass(message); - }, + match.has = createPropertyMatcher(function (actual, property) { + if (typeof actual === "object") { + return property in actual; + } + return actual[property] !== undefined; + }, "has"); - fail: function fail(message) { - var exception = new Error(message); - exception.name = "ExpectationError"; + match.hasOwn = createPropertyMatcher(function (actual, property) { + return actual.hasOwnProperty(property); + }, "hasOwn"); - throw exception; - } - }; + match.bool = match.typeOf("boolean"); + match.number = match.typeOf("number"); + match.string = match.typeOf("string"); + match.object = match.typeOf("object"); + match.func = match.typeOf("function"); + match.array = match.typeOf("array"); + match.regexp = match.typeOf("regexp"); + match.date = match.typeOf("date"); - sinon.mock = mock; - return mock; + sinon.match = match; + return match; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; @@ -3927,14 +3686,7 @@ var sinon = (function () { // eslint-disable-line no-unused-vars function loadDependencies(require, exports, module) { var sinon = require("./util/core"); - require("./times_in_words"); - require("./call"); - require("./extend"); - require("./match"); - require("./spy"); - require("./stub"); - require("./format"); - + require("./typeOf"); module.exports = makeApi(sinon); } @@ -3955,17 +3707,19 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./call":17,"./extend":19,"./format":20,"./match":22,"./spy":25,"./stub":26,"./times_in_words":29,"./util/core":31}],24:[function(require,module,exports){ +},{"./typeOf":31,"./util/core":32}],24:[function(require,module,exports){ /** + * @depend times_in_words.js * @depend util/core.js + * @depend call.js * @depend extend.js - * @depend collection.js - * @depend util/fake_timers.js - * @depend util/fake_server_with_clock.js + * @depend match.js + * @depend spy.js + * @depend stub.js + * @depend format.js */ /** - * Manages fake collections as well as fake utilities such as Sinon's - * timers and fake XHR implementation in one convenient object. + * Mock functions. * * @author Christian Johansen (christian@cjohansen.no) * @license BSD @@ -3977,602 +3731,456 @@ var sinon = (function () { // eslint-disable-line no-unused-vars function makeApi(sinon) { var push = [].push; + var match = sinon.match; - function exposeValue(sandbox, config, key, value) { - if (!value) { - return; - } + function mock(object) { + // if (typeof console !== undefined && console.warn) { + // console.warn("mock will be removed from Sinon.JS v2.0"); + // } - if (config.injectInto && !(key in config.injectInto)) { - config.injectInto[key] = value; - sandbox.injectedKeys.push(key); - } else { - push.call(sandbox.args, value); + if (!object) { + return sinon.expectation.create("Anonymous mock"); } - } - function prepareSandboxFromConfig(config) { - var sandbox = sinon.create(sinon.sandbox); - - if (config.useFakeServer) { - if (typeof config.useFakeServer === "object") { - sandbox.serverPrototype = config.useFakeServer; - } + return mock.create(object); + } - sandbox.useFakeServer(); + function each(collection, callback) { + if (!collection) { + return; } - if (config.useFakeTimers) { - if (typeof config.useFakeTimers === "object") { - sandbox.useFakeTimers.apply(sandbox, config.useFakeTimers); - } else { - sandbox.useFakeTimers(); - } + for (var i = 0, l = collection.length; i < l; i += 1) { + callback(collection[i]); } - - return sandbox; } - sinon.sandbox = sinon.extend(sinon.create(sinon.collection), { - useFakeTimers: function useFakeTimers() { - this.clock = sinon.useFakeTimers.apply(sinon, arguments); - - return this.add(this.clock); - }, - - serverPrototype: sinon.fakeServer, - - useFakeServer: function useFakeServer() { - var proto = this.serverPrototype || sinon.fakeServer; - - if (!proto || !proto.create) { - return null; - } - - this.server = proto.create(); - return this.add(this.server); - }, - - inject: function (obj) { - sinon.collection.inject.call(this, obj); + function arrayEquals(arr1, arr2, compareLength) { + if (compareLength && (arr1.length !== arr2.length)) { + return false; + } - if (this.clock) { - obj.clock = this.clock; + for (var i = 0, l = arr1.length; i < l; i++) { + if (!sinon.deepEqual(arr1[i], arr2[i])) { + return false; } + } + return true; + } - if (this.server) { - obj.server = this.server; - obj.requests = this.server.requests; + sinon.extend(mock, { + create: function create(object) { + if (!object) { + throw new TypeError("object is null"); } - obj.match = sinon.match; - - return obj; - }, + var mockObject = sinon.extend({}, mock); + mockObject.object = object; + delete mockObject.create; - restore: function () { - sinon.collection.restore.apply(this, arguments); - this.restoreContext(); + return mockObject; }, - restoreContext: function () { - if (this.injectedKeys) { - for (var i = 0, j = this.injectedKeys.length; i < j; i++) { - delete this.injectInto[this.injectedKeys[i]]; - } - this.injectedKeys = []; + expects: function expects(method) { + if (!method) { + throw new TypeError("method is falsy"); } - }, - create: function (config) { - if (!config) { - return sinon.create(sinon.sandbox); + if (!this.expectations) { + this.expectations = {}; + this.proxies = []; } - var sandbox = prepareSandboxFromConfig(config); - sandbox.args = sandbox.args || []; - sandbox.injectedKeys = []; - sandbox.injectInto = config.injectInto; - var prop, - value; - var exposed = sandbox.inject({}); + if (!this.expectations[method]) { + this.expectations[method] = []; + var mockObject = this; - if (config.properties) { - for (var i = 0, l = config.properties.length; i < l; i++) { - prop = config.properties[i]; - value = exposed[prop] || prop === "sandbox" && sandbox; - exposeValue(sandbox, config, prop, value); - } - } else { - exposeValue(sandbox, config, "sandbox", value); + sinon.wrapMethod(this.object, method, function () { + return mockObject.invokeMethod(method, this, arguments); + }); + + push.call(this.proxies, method); } - return sandbox; + var expectation = sinon.expectation.create(method); + push.call(this.expectations[method], expectation); + + return expectation; }, - match: sinon.match - }); + restore: function restore() { + var object = this.object; - sinon.sandbox.useFakeXMLHttpRequest = sinon.sandbox.useFakeServer; + each(this.proxies, function (proxy) { + if (typeof object[proxy].restore === "function") { + object[proxy].restore(); + } + }); + }, - return sinon.sandbox; - } + verify: function verify() { + var expectations = this.expectations || {}; + var messages = []; + var met = []; - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + each(this.proxies, function (proxy) { + each(expectations[proxy], function (expectation) { + if (!expectation.met()) { + push.call(messages, expectation.toString()); + } else { + push.call(met, expectation.toString()); + } + }); + }); - function loadDependencies(require, exports, module) { - var sinon = require("./util/core"); - require("./extend"); - require("./util/fake_server_with_clock"); - require("./util/fake_timers"); - require("./collection"); - module.exports = makeApi(sinon); - } + this.restore(); - if (isAMD) { - define(loadDependencies); - return; - } + if (messages.length > 0) { + sinon.expectation.fail(messages.concat(met).join("\n")); + } else if (met.length > 0) { + sinon.expectation.pass(messages.concat(met).join("\n")); + } - if (isNode) { - loadDependencies(require, module.exports, module); - return; - } + return true; + }, - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + invokeMethod: function invokeMethod(method, thisValue, args) { + var expectations = this.expectations && this.expectations[method] ? this.expectations[method] : []; + var expectationsWithMatchingArgs = []; + var currentArgs = args || []; + var i, available; -},{"./collection":18,"./extend":19,"./util/core":31,"./util/fake_server_with_clock":34,"./util/fake_timers":35}],25:[function(require,module,exports){ -/** - * @depend times_in_words.js - * @depend util/core.js - * @depend extend.js - * @depend call.js - * @depend format.js - */ -/** - * Spy functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -(function (sinonGlobal) { - "use strict"; + for (i = 0; i < expectations.length; i += 1) { + var expectedArgs = expectations[i].expectedArguments || []; + if (arrayEquals(expectedArgs, currentArgs, expectations[i].expectsExactArgCount)) { + expectationsWithMatchingArgs.push(expectations[i]); + } + } - function makeApi(sinon) { - var push = Array.prototype.push; - var slice = Array.prototype.slice; - var callId = 0; + for (i = 0; i < expectationsWithMatchingArgs.length; i += 1) { + if (!expectationsWithMatchingArgs[i].met() && + expectationsWithMatchingArgs[i].allowsCall(thisValue, args)) { + return expectationsWithMatchingArgs[i].apply(thisValue, args); + } + } - function spy(object, property, types) { - if (!property && typeof object === "function") { - return spy.create(object); - } + var messages = []; + var exhausted = 0; - if (!object && !property) { - return spy.create(function () { }); - } + for (i = 0; i < expectationsWithMatchingArgs.length; i += 1) { + if (expectationsWithMatchingArgs[i].allowsCall(thisValue, args)) { + available = available || expectationsWithMatchingArgs[i]; + } else { + exhausted += 1; + } + } - if (types) { - var methodDesc = sinon.getPropertyDescriptor(object, property); - for (var i = 0; i < types.length; i++) { - methodDesc[types[i]] = spy.create(methodDesc[types[i]]); + if (available && exhausted === 0) { + return available.apply(thisValue, args); } - return sinon.wrapMethod(object, property, methodDesc); - } - return sinon.wrapMethod(object, property, spy.create(object[property])); - } + for (i = 0; i < expectations.length; i += 1) { + push.call(messages, " " + expectations[i].toString()); + } - function matchingFake(fakes, args, strict) { - if (!fakes) { - return undefined; - } + messages.unshift("Unexpected call: " + sinon.spyCall.toString.call({ + proxy: method, + args: args + })); - for (var i = 0, l = fakes.length; i < l; i++) { - if (fakes[i].matches(args, strict)) { - return fakes[i]; - } + sinon.expectation.fail(messages.join("\n")); } - } - - function incrementCallCount() { - this.called = true; - this.callCount += 1; - this.notCalled = false; - this.calledOnce = this.callCount === 1; - this.calledTwice = this.callCount === 2; - this.calledThrice = this.callCount === 3; - } + }); - function createCallProperties() { - this.firstCall = this.getCall(0); - this.secondCall = this.getCall(1); - this.thirdCall = this.getCall(2); - this.lastCall = this.getCall(this.callCount - 1); - } + var times = sinon.timesInWords; + var slice = Array.prototype.slice; - var vars = "a,b,c,d,e,f,g,h,i,j,k,l"; - function createProxy(func, proxyLength) { - // Retain the function length: - var p; - if (proxyLength) { - eval("p = (function proxy(" + vars.substring(0, proxyLength * 2 - 1) + // eslint-disable-line no-eval - ") { return p.invoke(func, this, slice.call(arguments)); });"); - } else { - p = function proxy() { - return p.invoke(func, this, slice.call(arguments)); - }; + function callCountInWords(callCount) { + if (callCount === 0) { + return "never called"; } - p.isSinonProxy = true; - return p; + + return "called " + times(callCount); } - var uuid = 0; + function expectedCallCountInWords(expectation) { + var min = expectation.minCalls; + var max = expectation.maxCalls; - // Public API - var spyApi = { - reset: function () { - if (this.invoking) { - var err = new Error("Cannot reset Sinon function while invoking it. " + - "Move the call to .reset outside of the callback."); - err.name = "InvalidResetException"; - throw err; - } + if (typeof min === "number" && typeof max === "number") { + var str = times(min); - this.called = false; - this.notCalled = true; - this.calledOnce = false; - this.calledTwice = false; - this.calledThrice = false; - this.callCount = 0; - this.firstCall = null; - this.secondCall = null; - this.thirdCall = null; - this.lastCall = null; - this.args = []; - this.returnValues = []; - this.thisValues = []; - this.exceptions = []; - this.callIds = []; - this.stacks = []; - if (this.fakes) { - for (var i = 0; i < this.fakes.length; i++) { - this.fakes[i].reset(); - } + if (min !== max) { + str = "at least " + str + " and at most " + times(max); } - return this; - }, - - create: function create(func, spyLength) { - var name; - - if (typeof func !== "function") { - func = function () { }; - } else { - name = sinon.functionName(func); - } + return str; + } - if (!spyLength) { - spyLength = func.length; - } + if (typeof min === "number") { + return "at least " + times(min); + } - var proxy = createProxy(func, spyLength); + return "at most " + times(max); + } - sinon.extend(proxy, spy); - delete proxy.create; - sinon.extend(proxy, func); + function receivedMinCalls(expectation) { + var hasMinLimit = typeof expectation.minCalls === "number"; + return !hasMinLimit || expectation.callCount >= expectation.minCalls; + } - proxy.reset(); - proxy.prototype = func.prototype; - proxy.displayName = name || "spy"; - proxy.toString = sinon.functionToString; - proxy.instantiateFake = sinon.spy.create; - proxy.id = "spy#" + uuid++; + function receivedMaxCalls(expectation) { + if (typeof expectation.maxCalls !== "number") { + return false; + } - return proxy; - }, + return expectation.callCount === expectation.maxCalls; + } - invoke: function invoke(func, thisValue, args) { - var matching = matchingFake(this.fakes, args); - var exception, returnValue; + function verifyMatcher(possibleMatcher, arg) { + var isMatcher = match && match.isMatcher(possibleMatcher); - incrementCallCount.call(this); - push.call(this.thisValues, thisValue); - push.call(this.args, args); - push.call(this.callIds, callId++); + return isMatcher && possibleMatcher.test(arg) || true; + } - // Make call properties available from within the spied function: - createCallProperties.call(this); + sinon.expectation = { + minCalls: 1, + maxCalls: 1, - try { - this.invoking = true; + create: function create(methodName) { + var expectation = sinon.extend(sinon.stub.create(), sinon.expectation); + delete expectation.create; + expectation.method = methodName; - if (matching) { - returnValue = matching.invoke(func, thisValue, args); - } else { - returnValue = (this.func || func).apply(thisValue, args); - } + return expectation; + }, - var thisCall = this.getCall(this.callCount - 1); - if (thisCall.calledWithNew() && typeof returnValue !== "object") { - returnValue = thisValue; - } - } catch (e) { - exception = e; - } finally { - delete this.invoking; - } + invoke: function invoke(func, thisValue, args) { + this.verifyCallAllowed(thisValue, args); - push.call(this.exceptions, exception); - push.call(this.returnValues, returnValue); - push.call(this.stacks, new Error().stack); + return sinon.spy.invoke.apply(this, arguments); + }, - // Make return value and exception available in the calls: - createCallProperties.call(this); + atLeast: function atLeast(num) { + if (typeof num !== "number") { + throw new TypeError("'" + num + "' is not number"); + } - if (exception !== undefined) { - throw exception; + if (!this.limitsSet) { + this.maxCalls = null; + this.limitsSet = true; } - return returnValue; - }, + this.minCalls = num; - named: function named(name) { - this.displayName = name; return this; }, - getCall: function getCall(i) { - if (i < 0 || i >= this.callCount) { - return null; + atMost: function atMost(num) { + if (typeof num !== "number") { + throw new TypeError("'" + num + "' is not number"); } - return sinon.spyCall(this, this.thisValues[i], this.args[i], - this.returnValues[i], this.exceptions[i], - this.callIds[i], this.stacks[i]); - }, + if (!this.limitsSet) { + this.minCalls = null; + this.limitsSet = true; + } - getCalls: function () { - var calls = []; - var i; + this.maxCalls = num; - for (i = 0; i < this.callCount; i++) { - calls.push(this.getCall(i)); - } + return this; + }, - return calls; + never: function never() { + return this.exactly(0); }, - calledBefore: function calledBefore(spyFn) { - if (!this.called) { - return false; - } + once: function once() { + return this.exactly(1); + }, - if (!spyFn.called) { - return true; - } + twice: function twice() { + return this.exactly(2); + }, - return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1]; + thrice: function thrice() { + return this.exactly(3); }, - calledAfter: function calledAfter(spyFn) { - if (!this.called || !spyFn.called) { - return false; + exactly: function exactly(num) { + if (typeof num !== "number") { + throw new TypeError("'" + num + "' is not a number"); } - return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1]; + this.atLeast(num); + return this.atMost(num); }, - withArgs: function () { - var args = slice.call(arguments); + met: function met() { + return !this.failed && receivedMinCalls(this); + }, - if (this.fakes) { - var match = matchingFake(this.fakes, args, true); + verifyCallAllowed: function verifyCallAllowed(thisValue, args) { + if (receivedMaxCalls(this)) { + this.failed = true; + sinon.expectation.fail(this.method + " already called " + times(this.maxCalls)); + } - if (match) { - return match; - } - } else { - this.fakes = []; + if ("expectedThis" in this && this.expectedThis !== thisValue) { + sinon.expectation.fail(this.method + " called with " + thisValue + " as thisValue, expected " + + this.expectedThis); } - var original = this; - var fake = this.instantiateFake(); - fake.matchingAguments = args; - fake.parent = this; - push.call(this.fakes, fake); + if (!("expectedArguments" in this)) { + return; + } - fake.withArgs = function () { - return original.withArgs.apply(original, arguments); - }; + if (!args) { + sinon.expectation.fail(this.method + " received no arguments, expected " + + sinon.format(this.expectedArguments)); + } - for (var i = 0; i < this.args.length; i++) { - if (fake.matches(this.args[i])) { - incrementCallCount.call(fake); - push.call(fake.thisValues, this.thisValues[i]); - push.call(fake.args, this.args[i]); - push.call(fake.returnValues, this.returnValues[i]); - push.call(fake.exceptions, this.exceptions[i]); - push.call(fake.callIds, this.callIds[i]); - } + if (args.length < this.expectedArguments.length) { + sinon.expectation.fail(this.method + " received too few arguments (" + sinon.format(args) + + "), expected " + sinon.format(this.expectedArguments)); } - createCallProperties.call(fake); - return fake; - }, + if (this.expectsExactArgCount && + args.length !== this.expectedArguments.length) { + sinon.expectation.fail(this.method + " received too many arguments (" + sinon.format(args) + + "), expected " + sinon.format(this.expectedArguments)); + } - matches: function (args, strict) { - var margs = this.matchingAguments; + for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) { - if (margs.length <= args.length && - sinon.deepEqual(margs, args.slice(0, margs.length))) { - return !strict || margs.length === args.length; + if (!verifyMatcher(this.expectedArguments[i], args[i])) { + sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + + ", didn't match " + this.expectedArguments.toString()); + } + + if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { + sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + + ", expected " + sinon.format(this.expectedArguments)); + } } }, - printf: function (format) { - var spyInstance = this; - var args = slice.call(arguments, 1); - var formatter; + allowsCall: function allowsCall(thisValue, args) { + if (this.met() && receivedMaxCalls(this)) { + return false; + } - return (format || "").replace(/%(.)/g, function (match, specifyer) { - formatter = spyApi.formatters[specifyer]; + if ("expectedThis" in this && this.expectedThis !== thisValue) { + return false; + } - if (typeof formatter === "function") { - return formatter.call(null, spyInstance, args); - } else if (!isNaN(parseInt(specifyer, 10))) { - return sinon.format(args[specifyer - 1]); - } + if (!("expectedArguments" in this)) { + return true; + } - return "%" + specifyer; - }); - } - }; + args = args || []; - function delegateToCalls(method, matchAny, actual, notCalled) { - spyApi[method] = function () { - if (!this.called) { - if (notCalled) { - return notCalled.apply(this, arguments); - } + if (args.length < this.expectedArguments.length) { return false; } - var currentCall; - var matches = 0; - - for (var i = 0, l = this.callCount; i < l; i += 1) { - currentCall = this.getCall(i); + if (this.expectsExactArgCount && + args.length !== this.expectedArguments.length) { + return false; + } - if (currentCall[actual || method].apply(currentCall, arguments)) { - matches += 1; + for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) { + if (!verifyMatcher(this.expectedArguments[i], args[i])) { + return false; + } - if (matchAny) { - return true; - } + if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { + return false; } } - return matches === this.callCount; - }; - } + return true; + }, - delegateToCalls("calledOn", true); - delegateToCalls("alwaysCalledOn", false, "calledOn"); - delegateToCalls("calledWith", true); - delegateToCalls("calledWithMatch", true); - delegateToCalls("alwaysCalledWith", false, "calledWith"); - delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch"); - delegateToCalls("calledWithExactly", true); - delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly"); - delegateToCalls("neverCalledWith", false, "notCalledWith", function () { - return true; - }); - delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch", function () { - return true; - }); - delegateToCalls("threw", true); - delegateToCalls("alwaysThrew", false, "threw"); - delegateToCalls("returned", true); - delegateToCalls("alwaysReturned", false, "returned"); - delegateToCalls("calledWithNew", true); - delegateToCalls("alwaysCalledWithNew", false, "calledWithNew"); - delegateToCalls("callArg", false, "callArgWith", function () { - throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); - }); - spyApi.callArgWith = spyApi.callArg; - delegateToCalls("callArgOn", false, "callArgOnWith", function () { - throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); - }); - spyApi.callArgOnWith = spyApi.callArgOn; - delegateToCalls("yield", false, "yield", function () { - throw new Error(this.toString() + " cannot yield since it was not yet invoked."); - }); - // "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode. - spyApi.invokeCallback = spyApi.yield; - delegateToCalls("yieldOn", false, "yieldOn", function () { - throw new Error(this.toString() + " cannot yield since it was not yet invoked."); - }); - delegateToCalls("yieldTo", false, "yieldTo", function (property) { - throw new Error(this.toString() + " cannot yield to '" + property + - "' since it was not yet invoked."); - }); - delegateToCalls("yieldToOn", false, "yieldToOn", function (property) { - throw new Error(this.toString() + " cannot yield to '" + property + - "' since it was not yet invoked."); - }); + withArgs: function withArgs() { + this.expectedArguments = slice.call(arguments); + return this; + }, - spyApi.formatters = { - c: function (spyInstance) { - return sinon.timesInWords(spyInstance.callCount); + withExactArgs: function withExactArgs() { + this.withArgs.apply(this, arguments); + this.expectsExactArgCount = true; + return this; }, - n: function (spyInstance) { - return spyInstance.toString(); + on: function on(thisValue) { + this.expectedThis = thisValue; + return this; }, - C: function (spyInstance) { - var calls = []; + toString: function () { + var args = (this.expectedArguments || []).slice(); - for (var i = 0, l = spyInstance.callCount; i < l; ++i) { - var stringifiedCall = " " + spyInstance.getCall(i).toString(); - if (/\n/.test(calls[i - 1])) { - stringifiedCall = "\n" + stringifiedCall; - } - push.call(calls, stringifiedCall); + if (!this.expectsExactArgCount) { + push.call(args, "[...]"); } - return calls.length > 0 ? "\n" + calls.join("\n") : ""; - }, + var callStr = sinon.spyCall.toString.call({ + proxy: this.method || "anonymous mock expectation", + args: args + }); - t: function (spyInstance) { - var objects = []; + var message = callStr.replace(", [...", "[, ...") + " " + + expectedCallCountInWords(this); - for (var i = 0, l = spyInstance.callCount; i < l; ++i) { - push.call(objects, sinon.format(spyInstance.thisValues[i])); + if (this.met()) { + return "Expectation met: " + message; } - return objects.join(", "); + return "Expected " + message + " (" + + callCountInWords(this.callCount) + ")"; }, - "*": function (spyInstance, args) { - var formatted = []; - - for (var i = 0, l = args.length; i < l; ++i) { - push.call(formatted, sinon.format(args[i])); + verify: function verify() { + if (!this.met()) { + sinon.expectation.fail(this.toString()); + } else { + sinon.expectation.pass(this.toString()); } - return formatted.join(", "); - } - }; + return true; + }, - sinon.extend(spy, spyApi); + pass: function pass(message) { + sinon.assert.pass(message); + }, - spy.spyCall = sinon.spyCall; - sinon.spy = spy; + fail: function fail(message) { + var exception = new Error(message); + exception.name = "ExpectationError"; - return spy; + throw exception; + } + }; + + sinon.mock = mock; + return mock; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; function loadDependencies(require, exports, module) { - var core = require("./util/core"); + var sinon = require("./util/core"); + require("./times_in_words"); require("./call"); require("./extend"); - require("./times_in_words"); + require("./match"); + require("./spy"); + require("./stub"); require("./format"); - module.exports = makeApi(core); + + module.exports = makeApi(sinon); } if (isAMD) { @@ -4592,16 +4200,17 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./call":17,"./extend":19,"./format":20,"./times_in_words":29,"./util/core":31}],26:[function(require,module,exports){ +},{"./call":18,"./extend":20,"./format":21,"./match":23,"./spy":26,"./stub":27,"./times_in_words":30,"./util/core":32}],25:[function(require,module,exports){ /** * @depend util/core.js * @depend extend.js - * @depend spy.js - * @depend behavior.js - * @depend walk.js + * @depend collection.js + * @depend util/fake_timers.js + * @depend util/fake_server_with_clock.js */ /** - * Stub functions + * Manages fake collections as well as fake utilities such as Sinon's + * timers and fake XHR implementation in one convenient object. * * @author Christian Johansen (christian@cjohansen.no) * @license BSD @@ -4612,169 +4221,138 @@ var sinon = (function () { // eslint-disable-line no-unused-vars "use strict"; function makeApi(sinon) { - function stub(object, property, func) { - if (!!func && typeof func !== "function" && typeof func !== "object") { - throw new TypeError("Custom stub should be a function or a property descriptor"); - } + var push = [].push; - var wrapper; + function exposeValue(sandbox, config, key, value) { + if (!value) { + return; + } - if (func) { - if (typeof func === "function") { - wrapper = sinon.spy && sinon.spy.create ? sinon.spy.create(func) : func; - } else { - wrapper = func; - if (sinon.spy && sinon.spy.create) { - var types = sinon.objectKeys(wrapper); - for (var i = 0; i < types.length; i++) { - wrapper[types[i]] = sinon.spy.create(wrapper[types[i]]); - } - } - } + if (config.injectInto && !(key in config.injectInto)) { + config.injectInto[key] = value; + sandbox.injectedKeys.push(key); } else { - var stubLength = 0; - if (typeof object === "object" && typeof object[property] === "function") { - stubLength = object[property].length; - } - wrapper = stub.create(stubLength); + push.call(sandbox.args, value); } + } - if (!object && typeof property === "undefined") { - return sinon.stub.create(); - } + function prepareSandboxFromConfig(config) { + var sandbox = sinon.create(sinon.sandbox); - if (typeof property === "undefined" && typeof object === "object") { - sinon.walk(object || {}, function (value, prop, propOwner) { - // we don't want to stub things like toString(), valueOf(), etc. so we only stub if the object - // is not Object.prototype - if ( - propOwner !== Object.prototype && - prop !== "constructor" && - typeof sinon.getPropertyDescriptor(propOwner, prop).value === "function" - ) { - stub(object, prop); - } - }); + if (config.useFakeServer) { + if (typeof config.useFakeServer === "object") { + sandbox.serverPrototype = config.useFakeServer; + } - return object; + sandbox.useFakeServer(); } - return sinon.wrapMethod(object, property, wrapper); - } - + if (config.useFakeTimers) { + if (typeof config.useFakeTimers === "object") { + sandbox.useFakeTimers.apply(sandbox, config.useFakeTimers); + } else { + sandbox.useFakeTimers(); + } + } - /*eslint-disable no-use-before-define*/ - function getParentBehaviour(stubInstance) { - return (stubInstance.parent && getCurrentBehavior(stubInstance.parent)); + return sandbox; } - function getDefaultBehavior(stubInstance) { - return stubInstance.defaultBehavior || - getParentBehaviour(stubInstance) || - sinon.behavior.create(stubInstance); - } + sinon.sandbox = sinon.extend(sinon.create(sinon.collection), { + useFakeTimers: function useFakeTimers() { + this.clock = sinon.useFakeTimers.apply(sinon, arguments); - function getCurrentBehavior(stubInstance) { - var behavior = stubInstance.behaviors[stubInstance.callCount - 1]; - return behavior && behavior.isPresent() ? behavior : getDefaultBehavior(stubInstance); - } - /*eslint-enable no-use-before-define*/ + return this.add(this.clock); + }, - var uuid = 0; + serverPrototype: sinon.fakeServer, - var proto = { - create: function create(stubLength) { - var functionStub = function () { - return getCurrentBehavior(functionStub).invoke(this, arguments); - }; + useFakeServer: function useFakeServer() { + var proto = this.serverPrototype || sinon.fakeServer; - functionStub.id = "stub#" + uuid++; - var orig = functionStub; - functionStub = sinon.spy.create(functionStub, stubLength); - functionStub.func = orig; + if (!proto || !proto.create) { + return null; + } + + this.server = proto.create(); + return this.add(this.server); + }, - sinon.extend(functionStub, stub); - functionStub.instantiateFake = sinon.stub.create; - functionStub.displayName = "stub"; - functionStub.toString = sinon.functionToString; + inject: function (obj) { + sinon.collection.inject.call(this, obj); - functionStub.defaultBehavior = null; - functionStub.behaviors = []; + if (this.clock) { + obj.clock = this.clock; + } - return functionStub; - }, + if (this.server) { + obj.server = this.server; + obj.requests = this.server.requests; + } - resetBehavior: function () { - var i; + obj.match = sinon.match; - this.defaultBehavior = null; - this.behaviors = []; + return obj; + }, - delete this.returnValue; - delete this.returnArgAt; - this.returnThis = false; + restore: function () { + sinon.collection.restore.apply(this, arguments); + this.restoreContext(); + }, - if (this.fakes) { - for (i = 0; i < this.fakes.length; i++) { - this.fakes[i].resetBehavior(); + restoreContext: function () { + if (this.injectedKeys) { + for (var i = 0, j = this.injectedKeys.length; i < j; i++) { + delete this.injectInto[this.injectedKeys[i]]; } + this.injectedKeys = []; } }, - onCall: function onCall(index) { - if (!this.behaviors[index]) { - this.behaviors[index] = sinon.behavior.create(this); + create: function (config) { + if (!config) { + return sinon.create(sinon.sandbox); } - return this.behaviors[index]; - }, + var sandbox = prepareSandboxFromConfig(config); + sandbox.args = sandbox.args || []; + sandbox.injectedKeys = []; + sandbox.injectInto = config.injectInto; + var prop, + value; + var exposed = sandbox.inject({}); - onFirstCall: function onFirstCall() { - return this.onCall(0); - }, + if (config.properties) { + for (var i = 0, l = config.properties.length; i < l; i++) { + prop = config.properties[i]; + value = exposed[prop] || prop === "sandbox" && sandbox; + exposeValue(sandbox, config, prop, value); + } + } else { + exposeValue(sandbox, config, "sandbox", value); + } - onSecondCall: function onSecondCall() { - return this.onCall(1); + return sandbox; }, - onThirdCall: function onThirdCall() { - return this.onCall(2); - } - }; - - function createBehavior(behaviorMethod) { - return function () { - this.defaultBehavior = this.defaultBehavior || sinon.behavior.create(this); - this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments); - return this; - }; - } - - for (var method in sinon.behavior) { - if (sinon.behavior.hasOwnProperty(method) && - !proto.hasOwnProperty(method) && - method !== "create" && - method !== "withArgs" && - method !== "invoke") { - proto[method] = createBehavior(method); - } - } + match: sinon.match + }); - sinon.extend(stub, proto); - sinon.stub = stub; + sinon.sandbox.useFakeXMLHttpRequest = sinon.sandbox.useFakeServer; - return stub; + return sinon.sandbox; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; function loadDependencies(require, exports, module) { - var core = require("./util/core"); - require("./behavior"); - require("./spy"); + var sinon = require("./util/core"); require("./extend"); - module.exports = makeApi(core); + require("./util/fake_server_with_clock"); + require("./util/fake_timers"); + require("./collection"); + module.exports = makeApi(sinon); } if (isAMD) { @@ -4794,641 +4372,744 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{"./behavior":16,"./extend":19,"./spy":25,"./util/core":31}],27:[function(require,module,exports){ +},{"./collection":19,"./extend":20,"./util/core":32,"./util/fake_server_with_clock":35,"./util/fake_timers":36}],26:[function(require,module,exports){ /** - * @depend util/core.js - * @depend sandbox.js - */ + * @depend times_in_words.js + * @depend util/core.js + * @depend extend.js + * @depend call.js + * @depend format.js + */ /** - * Test function, sandboxes fakes - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ + * Spy functions + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ (function (sinonGlobal) { "use strict"; - function makeApi(sinon) { - var slice = Array.prototype.slice; + function makeApi(sinon) { + var push = Array.prototype.push; + var slice = Array.prototype.slice; + var callId = 0; + + function spy(object, property, types) { + if (!property && typeof object === "function") { + return spy.create(object); + } + + if (!object && !property) { + return spy.create(function () { }); + } + + if (types) { + var methodDesc = sinon.getPropertyDescriptor(object, property); + for (var i = 0; i < types.length; i++) { + methodDesc[types[i]] = spy.create(methodDesc[types[i]]); + } + return sinon.wrapMethod(object, property, methodDesc); + } + + return sinon.wrapMethod(object, property, spy.create(object[property])); + } + + function matchingFake(fakes, args, strict) { + if (!fakes) { + return undefined; + } + + for (var i = 0, l = fakes.length; i < l; i++) { + if (fakes[i].matches(args, strict)) { + return fakes[i]; + } + } + } + + function incrementCallCount() { + this.called = true; + this.callCount += 1; + this.notCalled = false; + this.calledOnce = this.callCount === 1; + this.calledTwice = this.callCount === 2; + this.calledThrice = this.callCount === 3; + } + + function createCallProperties() { + this.firstCall = this.getCall(0); + this.secondCall = this.getCall(1); + this.thirdCall = this.getCall(2); + this.lastCall = this.getCall(this.callCount - 1); + } + + var vars = "a,b,c,d,e,f,g,h,i,j,k,l"; + function createProxy(func, proxyLength) { + // Retain the function length: + var p; + if (proxyLength) { + eval("p = (function proxy(" + vars.substring(0, proxyLength * 2 - 1) + // eslint-disable-line no-eval + ") { return p.invoke(func, this, slice.call(arguments)); });"); + } else { + p = function proxy() { + return p.invoke(func, this, slice.call(arguments)); + }; + } + p.isSinonProxy = true; + return p; + } + + var uuid = 0; + + // Public API + var spyApi = { + reset: function () { + if (this.invoking) { + var err = new Error("Cannot reset Sinon function while invoking it. " + + "Move the call to .reset outside of the callback."); + err.name = "InvalidResetException"; + throw err; + } + + this.called = false; + this.notCalled = true; + this.calledOnce = false; + this.calledTwice = false; + this.calledThrice = false; + this.callCount = 0; + this.firstCall = null; + this.secondCall = null; + this.thirdCall = null; + this.lastCall = null; + this.args = []; + this.returnValues = []; + this.thisValues = []; + this.exceptions = []; + this.callIds = []; + this.stacks = []; + if (this.fakes) { + for (var i = 0; i < this.fakes.length; i++) { + this.fakes[i].reset(); + } + } + + return this; + }, + + create: function create(func, spyLength) { + var name; + + if (typeof func !== "function") { + func = function () { }; + } else { + name = sinon.functionName(func); + } + + if (!spyLength) { + spyLength = func.length; + } + + var proxy = createProxy(func, spyLength); + + sinon.extend(proxy, spy); + delete proxy.create; + sinon.extend(proxy, func); + + proxy.reset(); + proxy.prototype = func.prototype; + proxy.displayName = name || "spy"; + proxy.toString = sinon.functionToString; + proxy.instantiateFake = sinon.spy.create; + proxy.id = "spy#" + uuid++; - function test(callback) { - var type = typeof callback; + return proxy; + }, - if (type !== "function") { - throw new TypeError("sinon.test needs to wrap a test function, got " + type); - } + invoke: function invoke(func, thisValue, args) { + var matching = matchingFake(this.fakes, args); + var exception, returnValue; - function sinonSandboxedTest() { - var config = sinon.getConfig(sinon.config); - config.injectInto = config.injectIntoThis && this || config.injectInto; - var sandbox = sinon.sandbox.create(config); - var args = slice.call(arguments); - var oldDone = args.length && args[args.length - 1]; - var exception, result; + incrementCallCount.call(this); + push.call(this.thisValues, thisValue); + push.call(this.args, args); + push.call(this.callIds, callId++); - if (typeof oldDone === "function") { - args[args.length - 1] = function sinonDone(res) { - if (res) { - sandbox.restore(); - } else { - sandbox.verifyAndRestore(); - } - oldDone(res); - }; - } + // Make call properties available from within the spied function: + createCallProperties.call(this); try { - result = callback.apply(this, args.concat(sandbox.args)); + this.invoking = true; + + if (matching) { + returnValue = matching.invoke(func, thisValue, args); + } else { + returnValue = (this.func || func).apply(thisValue, args); + } + + var thisCall = this.getCall(this.callCount - 1); + if (thisCall.calledWithNew() && typeof returnValue !== "object") { + returnValue = thisValue; + } } catch (e) { exception = e; + } finally { + delete this.invoking; } - if (typeof exception !== "undefined") { - sandbox.restore(); - throw exception; - } else if (typeof oldDone !== "function") { - sandbox.verifyAndRestore(); - } - - return result; - } - - if (callback.length) { - return function sinonAsyncSandboxedTest(done) { // eslint-disable-line no-unused-vars - return sinonSandboxedTest.apply(this, arguments); - }; - } - - return sinonSandboxedTest; - } - - test.config = { - injectIntoThis: true, - injectInto: null, - properties: ["spy", "stub", "mock", "clock", "server", "requests"], - useFakeTimers: true, - useFakeServer: true - }; + push.call(this.exceptions, exception); + push.call(this.returnValues, returnValue); + push.call(this.stacks, new Error().stack); - sinon.test = test; - return test; - } + // Make return value and exception available in the calls: + createCallProperties.call(this); - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + if (exception !== undefined) { + throw exception; + } - function loadDependencies(require, exports, module) { - var core = require("./util/core"); - require("./sandbox"); - module.exports = makeApi(core); - } + return returnValue; + }, - if (isAMD) { - define(loadDependencies); - } else if (isNode) { - loadDependencies(require, module.exports, module); - } else if (sinonGlobal) { - makeApi(sinonGlobal); - } -}(typeof sinon === "object" && sinon || null)); // eslint-disable-line no-undef + named: function named(name) { + this.displayName = name; + return this; + }, -},{"./sandbox":24,"./util/core":31}],28:[function(require,module,exports){ -/** - * @depend util/core.js - * @depend test.js - */ -/** - * Test case, sandboxes all test functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -(function (sinonGlobal) { - "use strict"; + getCall: function getCall(i) { + if (i < 0 || i >= this.callCount) { + return null; + } - function createTest(property, setUp, tearDown) { - return function () { - if (setUp) { - setUp.apply(this, arguments); - } + return sinon.spyCall(this, this.thisValues[i], this.args[i], + this.returnValues[i], this.exceptions[i], + this.callIds[i], this.stacks[i]); + }, - var exception, result; + getCalls: function () { + var calls = []; + var i; - try { - result = property.apply(this, arguments); - } catch (e) { - exception = e; - } + for (i = 0; i < this.callCount; i++) { + calls.push(this.getCall(i)); + } - if (tearDown) { - tearDown.apply(this, arguments); - } + return calls; + }, - if (exception) { - throw exception; - } + calledBefore: function calledBefore(spyFn) { + if (!this.called) { + return false; + } - return result; - }; - } + if (!spyFn.called) { + return true; + } - function makeApi(sinon) { - function testCase(tests, prefix) { - if (!tests || typeof tests !== "object") { - throw new TypeError("sinon.testCase needs an object with test functions"); - } + return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1]; + }, - prefix = prefix || "test"; - var rPrefix = new RegExp("^" + prefix); - var methods = {}; - var setUp = tests.setUp; - var tearDown = tests.tearDown; - var testName, - property, - method; + calledAfter: function calledAfter(spyFn) { + if (!this.called || !spyFn.called) { + return false; + } - for (testName in tests) { - if (tests.hasOwnProperty(testName) && !/^(setUp|tearDown)$/.test(testName)) { - property = tests[testName]; + return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1]; + }, - if (typeof property === "function" && rPrefix.test(testName)) { - method = property; + withArgs: function () { + var args = slice.call(arguments); - if (setUp || tearDown) { - method = createTest(property, setUp, tearDown); - } + if (this.fakes) { + var match = matchingFake(this.fakes, args, true); - methods[testName] = sinon.test(method); - } else { - methods[testName] = tests[testName]; + if (match) { + return match; } + } else { + this.fakes = []; } - } - return methods; - } - - sinon.testCase = testCase; - return testCase; - } + var original = this; + var fake = this.instantiateFake(); + fake.matchingAguments = args; + fake.parent = this; + push.call(this.fakes, fake); - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + fake.withArgs = function () { + return original.withArgs.apply(original, arguments); + }; - function loadDependencies(require, exports, module) { - var core = require("./util/core"); - require("./test"); - module.exports = makeApi(core); - } + for (var i = 0; i < this.args.length; i++) { + if (fake.matches(this.args[i])) { + incrementCallCount.call(fake); + push.call(fake.thisValues, this.thisValues[i]); + push.call(fake.args, this.args[i]); + push.call(fake.returnValues, this.returnValues[i]); + push.call(fake.exceptions, this.exceptions[i]); + push.call(fake.callIds, this.callIds[i]); + } + } + createCallProperties.call(fake); - if (isAMD) { - define(loadDependencies); - return; - } + return fake; + }, - if (isNode) { - loadDependencies(require, module.exports, module); - return; - } + matches: function (args, strict) { + var margs = this.matchingAguments; - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + if (margs.length <= args.length && + sinon.deepEqual(margs, args.slice(0, margs.length))) { + return !strict || margs.length === args.length; + } + }, -},{"./test":27,"./util/core":31}],29:[function(require,module,exports){ -/** - * @depend util/core.js - */ -(function (sinonGlobal) { - "use strict"; + printf: function (format) { + var spyInstance = this; + var args = slice.call(arguments, 1); + var formatter; - function makeApi(sinon) { + return (format || "").replace(/%(.)/g, function (match, specifyer) { + formatter = spyApi.formatters[specifyer]; - function timesInWords(count) { - switch (count) { - case 1: - return "once"; - case 2: - return "twice"; - case 3: - return "thrice"; - default: - return (count || 0) + " times"; + if (typeof formatter === "function") { + return formatter.call(null, spyInstance, args); + } else if (!isNaN(parseInt(specifyer, 10))) { + return sinon.format(args[specifyer - 1]); + } + + return "%" + specifyer; + }); } - } + }; - sinon.timesInWords = timesInWords; - return sinon.timesInWords; - } + function delegateToCalls(method, matchAny, actual, notCalled) { + spyApi[method] = function () { + if (!this.called) { + if (notCalled) { + return notCalled.apply(this, arguments); + } + return false; + } - function loadDependencies(require, exports, module) { - var core = require("./util/core"); - module.exports = makeApi(core); - } + var currentCall; + var matches = 0; - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + for (var i = 0, l = this.callCount; i < l; i += 1) { + currentCall = this.getCall(i); - if (isAMD) { - define(loadDependencies); - return; - } + if (currentCall[actual || method].apply(currentCall, arguments)) { + matches += 1; - if (isNode) { - loadDependencies(require, module.exports, module); - return; - } + if (matchAny) { + return true; + } + } + } - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + return matches === this.callCount; + }; + } -},{"./util/core":31}],30:[function(require,module,exports){ -/** - * @depend util/core.js - */ -/** - * Format functions - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2014 Christian Johansen - */ -(function (sinonGlobal) { - "use strict"; + delegateToCalls("calledOn", true); + delegateToCalls("alwaysCalledOn", false, "calledOn"); + delegateToCalls("calledWith", true); + delegateToCalls("calledWithMatch", true); + delegateToCalls("alwaysCalledWith", false, "calledWith"); + delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch"); + delegateToCalls("calledWithExactly", true); + delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly"); + delegateToCalls("neverCalledWith", false, "notCalledWith", function () { + return true; + }); + delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch", function () { + return true; + }); + delegateToCalls("threw", true); + delegateToCalls("alwaysThrew", false, "threw"); + delegateToCalls("returned", true); + delegateToCalls("alwaysReturned", false, "returned"); + delegateToCalls("calledWithNew", true); + delegateToCalls("alwaysCalledWithNew", false, "calledWithNew"); + delegateToCalls("callArg", false, "callArgWith", function () { + throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); + }); + spyApi.callArgWith = spyApi.callArg; + delegateToCalls("callArgOn", false, "callArgOnWith", function () { + throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); + }); + spyApi.callArgOnWith = spyApi.callArgOn; + delegateToCalls("yield", false, "yield", function () { + throw new Error(this.toString() + " cannot yield since it was not yet invoked."); + }); + // "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode. + spyApi.invokeCallback = spyApi.yield; + delegateToCalls("yieldOn", false, "yieldOn", function () { + throw new Error(this.toString() + " cannot yield since it was not yet invoked."); + }); + delegateToCalls("yieldTo", false, "yieldTo", function (property) { + throw new Error(this.toString() + " cannot yield to '" + property + + "' since it was not yet invoked."); + }); + delegateToCalls("yieldToOn", false, "yieldToOn", function (property) { + throw new Error(this.toString() + " cannot yield to '" + property + + "' since it was not yet invoked."); + }); - function makeApi(sinon) { - function typeOf(value) { - if (value === null) { - return "null"; - } else if (value === undefined) { - return "undefined"; - } - var string = Object.prototype.toString.call(value); - return string.substring(8, string.length - 1).toLowerCase(); - } + spyApi.formatters = { + c: function (spyInstance) { + return sinon.timesInWords(spyInstance.callCount); + }, - sinon.typeOf = typeOf; - return sinon.typeOf; - } + n: function (spyInstance) { + return spyInstance.toString(); + }, - function loadDependencies(require, exports, module) { - var core = require("./util/core"); - module.exports = makeApi(core); - } + C: function (spyInstance) { + var calls = []; - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + for (var i = 0, l = spyInstance.callCount; i < l; ++i) { + var stringifiedCall = " " + spyInstance.getCall(i).toString(); + if (/\n/.test(calls[i - 1])) { + stringifiedCall = "\n" + stringifiedCall; + } + push.call(calls, stringifiedCall); + } - if (isAMD) { - define(loadDependencies); - return; - } + return calls.length > 0 ? "\n" + calls.join("\n") : ""; + }, - if (isNode) { - loadDependencies(require, module.exports, module); - return; - } + t: function (spyInstance) { + var objects = []; - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + for (var i = 0, l = spyInstance.callCount; i < l; ++i) { + push.call(objects, sinon.format(spyInstance.thisValues[i])); + } -},{"./util/core":31}],31:[function(require,module,exports){ -/** - * @depend ../../sinon.js - */ -/** - * Sinon core utilities. For internal use only. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -(function (sinonGlobal) { - "use strict"; + return objects.join(", "); + }, - var div = typeof document !== "undefined" && document.createElement("div"); - var hasOwn = Object.prototype.hasOwnProperty; + "*": function (spyInstance, args) { + var formatted = []; - function isDOMNode(obj) { - var success = false; + for (var i = 0, l = args.length; i < l; ++i) { + push.call(formatted, sinon.format(args[i])); + } - try { - obj.appendChild(div); - success = div.parentNode === obj; - } catch (e) { - return false; - } finally { - try { - obj.removeChild(div); - } catch (e) { - // Remove failed, not much we can do about that + return formatted.join(", "); } - } + }; - return success; - } + sinon.extend(spy, spyApi); - function isElement(obj) { - return div && obj && obj.nodeType === 1 && isDOMNode(obj); + spy.spyCall = sinon.spyCall; + sinon.spy = spy; + + return spy; } - function isFunction(obj) { - return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply); + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + + function loadDependencies(require, exports, module) { + var core = require("./util/core"); + require("./call"); + require("./extend"); + require("./times_in_words"); + require("./format"); + module.exports = makeApi(core); } - function isReallyNaN(val) { - return typeof val === "number" && isNaN(val); + if (isAMD) { + define(loadDependencies); + return; } - function mirrorProperties(target, source) { - for (var prop in source) { - if (!hasOwn.call(target, prop)) { - target[prop] = source[prop]; - } - } + if (isNode) { + loadDependencies(require, module.exports, module); + return; } - function isRestorable(obj) { - return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon; + if (sinonGlobal) { + makeApi(sinonGlobal); } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); - // Cheap way to detect if we have ES5 support. - var hasES5Support = "keys" in Object; +},{"./call":18,"./extend":20,"./format":21,"./times_in_words":30,"./util/core":32}],27:[function(require,module,exports){ +/** + * @depend util/core.js + * @depend extend.js + * @depend spy.js + * @depend behavior.js + * @depend walk.js + */ +/** + * Stub functions + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +(function (sinonGlobal) { + "use strict"; function makeApi(sinon) { - sinon.wrapMethod = function wrapMethod(object, property, method) { - if (!object) { - throw new TypeError("Should wrap property of object"); - } - - if (typeof method !== "function" && typeof method !== "object") { - throw new TypeError("Method wrapper should be a function or a property descriptor"); + function stub(object, property, func) { + if (!!func && typeof func !== "function" && typeof func !== "object") { + throw new TypeError("Custom stub should be a function or a property descriptor"); } - function checkWrappedMethod(wrappedMethod) { - var error; - - if (!isFunction(wrappedMethod)) { - error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + - property + " as function"); - } else if (wrappedMethod.restore && wrappedMethod.restore.sinon) { - error = new TypeError("Attempted to wrap " + property + " which is already wrapped"); - } else if (wrappedMethod.calledBefore) { - var verb = wrappedMethod.returns ? "stubbed" : "spied on"; - error = new TypeError("Attempted to wrap " + property + " which is already " + verb); - } + var wrapper; - if (error) { - if (wrappedMethod && wrappedMethod.stackTrace) { - error.stack += "\n--------------\n" + wrappedMethod.stackTrace; + if (func) { + if (typeof func === "function") { + wrapper = sinon.spy && sinon.spy.create ? sinon.spy.create(func) : func; + } else { + wrapper = func; + if (sinon.spy && sinon.spy.create) { + var types = sinon.objectKeys(wrapper); + for (var i = 0; i < types.length; i++) { + wrapper[types[i]] = sinon.spy.create(wrapper[types[i]]); + } } - throw error; } + } else { + var stubLength = 0; + if (typeof object === "object" && typeof object[property] === "function") { + stubLength = object[property].length; + } + wrapper = stub.create(stubLength); } - var error, wrappedMethod, i; + if (!object && typeof property === "undefined") { + return sinon.stub.create(); + } - // IE 8 does not support hasOwnProperty on the window object and Firefox has a problem - // when using hasOwn.call on objects from other frames. - var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property); + if (typeof property === "undefined" && typeof object === "object") { + sinon.walk(object || {}, function (value, prop, propOwner) { + // we don't want to stub things like toString(), valueOf(), etc. so we only stub if the object + // is not Object.prototype + if ( + propOwner !== Object.prototype && + prop !== "constructor" && + typeof sinon.getPropertyDescriptor(propOwner, prop).value === "function" + ) { + stub(object, prop); + } + }); - if (hasES5Support) { - var methodDesc = (typeof method === "function") ? {value: method} : method; - var wrappedMethodDesc = sinon.getPropertyDescriptor(object, property); + return object; + } - if (!wrappedMethodDesc) { - error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + - property + " as function"); - } else if (wrappedMethodDesc.restore && wrappedMethodDesc.restore.sinon) { - error = new TypeError("Attempted to wrap " + property + " which is already wrapped"); - } - if (error) { - if (wrappedMethodDesc && wrappedMethodDesc.stackTrace) { - error.stack += "\n--------------\n" + wrappedMethodDesc.stackTrace; - } - throw error; - } + return sinon.wrapMethod(object, property, wrapper); + } - var types = sinon.objectKeys(methodDesc); - for (i = 0; i < types.length; i++) { - wrappedMethod = wrappedMethodDesc[types[i]]; - checkWrappedMethod(wrappedMethod); - } - mirrorProperties(methodDesc, wrappedMethodDesc); - for (i = 0; i < types.length; i++) { - mirrorProperties(methodDesc[types[i]], wrappedMethodDesc[types[i]]); - } - Object.defineProperty(object, property, methodDesc); - } else { - wrappedMethod = object[property]; - checkWrappedMethod(wrappedMethod); - object[property] = method; - method.displayName = property; - } + /*eslint-disable no-use-before-define*/ + function getParentBehaviour(stubInstance) { + return (stubInstance.parent && getCurrentBehavior(stubInstance.parent)); + } - method.displayName = property; + function getDefaultBehavior(stubInstance) { + return stubInstance.defaultBehavior || + getParentBehaviour(stubInstance) || + sinon.behavior.create(stubInstance); + } - // Set up a stack trace which can be used later to find what line of - // code the original method was created on. - method.stackTrace = (new Error("Stack Trace for original")).stack; + function getCurrentBehavior(stubInstance) { + var behavior = stubInstance.behaviors[stubInstance.callCount - 1]; + return behavior && behavior.isPresent() ? behavior : getDefaultBehavior(stubInstance); + } + /*eslint-enable no-use-before-define*/ - method.restore = function () { - // For prototype properties try to reset by delete first. - // If this fails (ex: localStorage on mobile safari) then force a reset - // via direct assignment. - if (!owned) { - // In some cases `delete` may throw an error - try { - delete object[property]; - } catch (e) {} // eslint-disable-line no-empty - // For native code functions `delete` fails without throwing an error - // on Chrome < 43, PhantomJS, etc. - } else if (hasES5Support) { - Object.defineProperty(object, property, wrappedMethodDesc); - } + var uuid = 0; - // Use strict equality comparison to check failures then force a reset - // via direct assignment. - if (object[property] === method) { - object[property] = wrappedMethod; - } - }; + var proto = { + create: function create(stubLength) { + var functionStub = function () { + return getCurrentBehavior(functionStub).invoke(this, arguments); + }; - method.restore.sinon = true; + functionStub.id = "stub#" + uuid++; + var orig = functionStub; + functionStub = sinon.spy.create(functionStub, stubLength); + functionStub.func = orig; - if (!hasES5Support) { - mirrorProperties(method, wrappedMethod); - } + sinon.extend(functionStub, stub); + functionStub.instantiateFake = sinon.stub.create; + functionStub.displayName = "stub"; + functionStub.toString = sinon.functionToString; - return method; - }; + functionStub.defaultBehavior = null; + functionStub.behaviors = []; - sinon.create = function create(proto) { - var F = function () {}; - F.prototype = proto; - return new F(); - }; + return functionStub; + }, - sinon.deepEqual = function deepEqual(a, b) { - if (sinon.match && sinon.match.isMatcher(a)) { - return a.test(b); - } + resetBehavior: function () { + var i; - if (typeof a !== "object" || typeof b !== "object") { - return isReallyNaN(a) && isReallyNaN(b) || a === b; - } + this.defaultBehavior = null; + this.behaviors = []; - if (isElement(a) || isElement(b)) { - return a === b; - } + delete this.returnValue; + delete this.returnArgAt; + this.returnThis = false; - if (a === b) { - return true; - } + if (this.fakes) { + for (i = 0; i < this.fakes.length; i++) { + this.fakes[i].resetBehavior(); + } + } + }, - if ((a === null && b !== null) || (a !== null && b === null)) { - return false; - } + onCall: function onCall(index) { + if (!this.behaviors[index]) { + this.behaviors[index] = sinon.behavior.create(this); + } - if (a instanceof RegExp && b instanceof RegExp) { - return (a.source === b.source) && (a.global === b.global) && - (a.ignoreCase === b.ignoreCase) && (a.multiline === b.multiline); - } + return this.behaviors[index]; + }, - var aString = Object.prototype.toString.call(a); - if (aString !== Object.prototype.toString.call(b)) { - return false; - } + onFirstCall: function onFirstCall() { + return this.onCall(0); + }, + + onSecondCall: function onSecondCall() { + return this.onCall(1); + }, - if (aString === "[object Date]") { - return a.valueOf() === b.valueOf(); + onThirdCall: function onThirdCall() { + return this.onCall(2); } + }; - var prop; - var aLength = 0; - var bLength = 0; + function createBehavior(behaviorMethod) { + return function () { + this.defaultBehavior = this.defaultBehavior || sinon.behavior.create(this); + this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments); + return this; + }; + } - if (aString === "[object Array]" && a.length !== b.length) { - return false; + for (var method in sinon.behavior) { + if (sinon.behavior.hasOwnProperty(method) && + !proto.hasOwnProperty(method) && + method !== "create" && + method !== "withArgs" && + method !== "invoke") { + proto[method] = createBehavior(method); } + } - for (prop in a) { - if (hasOwn.call(a, prop)) { - aLength += 1; + sinon.extend(stub, proto); + sinon.stub = stub; - if (!(prop in b)) { - return false; - } + return stub; + } - if (!deepEqual(a[prop], b[prop])) { - return false; - } - } - } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - for (prop in b) { - if (hasOwn.call(b, prop)) { - bLength += 1; - } - } + function loadDependencies(require, exports, module) { + var core = require("./util/core"); + require("./behavior"); + require("./spy"); + require("./extend"); + module.exports = makeApi(core); + } - return aLength === bLength; - }; + if (isAMD) { + define(loadDependencies); + return; + } - sinon.functionName = function functionName(func) { - var name = func.displayName || func.name; + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } - // Use function decomposition as a last resort to get function - // name. Does not rely on function decomposition to work - if it - // doesn't debugging will be slightly less informative - // (i.e. toString will say 'spy' rather than 'myFunc'). - if (!name) { - var matches = func.toString().match(/function ([^\s\(]+)/); - name = matches && matches[1]; - } + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); - return name; - }; +},{"./behavior":17,"./extend":20,"./spy":26,"./util/core":32}],28:[function(require,module,exports){ +/** + * @depend util/core.js + * @depend sandbox.js + */ +/** + * Test function, sandboxes fakes + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +(function (sinonGlobal) { + "use strict"; - sinon.functionToString = function toString() { - if (this.getCall && this.callCount) { - var thisValue, - prop; - var i = this.callCount; + function makeApi(sinon) { + var slice = Array.prototype.slice; - while (i--) { - thisValue = this.getCall(i).thisValue; + function test(callback) { + var type = typeof callback; - for (prop in thisValue) { - if (thisValue[prop] === this) { - return prop; - } - } - } + if (type !== "function") { + throw new TypeError("sinon.test needs to wrap a test function, got " + type); } - return this.displayName || "sinon fake"; - }; - - sinon.objectKeys = function objectKeys(obj) { - if (obj !== Object(obj)) { - throw new TypeError("sinon.objectKeys called on a non-object"); - } + function sinonSandboxedTest() { + var config = sinon.getConfig(sinon.config); + config.injectInto = config.injectIntoThis && this || config.injectInto; + var sandbox = sinon.sandbox.create(config); + var args = slice.call(arguments); + var oldDone = args.length && args[args.length - 1]; + var exception, result; - var keys = []; - var key; - for (key in obj) { - if (hasOwn.call(obj, key)) { - keys.push(key); + if (typeof oldDone === "function") { + args[args.length - 1] = function sinonDone(res) { + if (res) { + sandbox.restore(); + } else { + sandbox.verifyAndRestore(); + } + oldDone(res); + }; } - } - return keys; - }; + try { + result = callback.apply(this, args.concat(sandbox.args)); + } catch (e) { + exception = e; + } - sinon.getPropertyDescriptor = function getPropertyDescriptor(object, property) { - var proto = object; - var descriptor; + if (typeof exception !== "undefined") { + sandbox.restore(); + throw exception; + } else if (typeof oldDone !== "function") { + sandbox.verifyAndRestore(); + } - while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) { - proto = Object.getPrototypeOf(proto); + return result; } - return descriptor; - }; - - sinon.getConfig = function (custom) { - var config = {}; - custom = custom || {}; - var defaults = sinon.defaultConfig; - for (var prop in defaults) { - if (defaults.hasOwnProperty(prop)) { - config[prop] = custom.hasOwnProperty(prop) ? custom[prop] : defaults[prop]; - } + if (callback.length) { + return function sinonAsyncSandboxedTest(done) { // eslint-disable-line no-unused-vars + return sinonSandboxedTest.apply(this, arguments); + }; } - return config; - }; + return sinonSandboxedTest; + } - sinon.defaultConfig = { + test.config = { injectIntoThis: true, injectInto: null, properties: ["spy", "stub", "mock", "clock", "server", "requests"], @@ -5436,62 +5117,117 @@ var sinon = (function () { // eslint-disable-line no-unused-vars useFakeServer: true }; - sinon.timesInWords = function timesInWords(count) { - return count === 1 && "once" || - count === 2 && "twice" || - count === 3 && "thrice" || - (count || 0) + " times"; + sinon.test = test; + return test; + } + + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + + function loadDependencies(require, exports, module) { + var core = require("./util/core"); + require("./sandbox"); + module.exports = makeApi(core); + } + + if (isAMD) { + define(loadDependencies); + } else if (isNode) { + loadDependencies(require, module.exports, module); + } else if (sinonGlobal) { + makeApi(sinonGlobal); + } +}(typeof sinon === "object" && sinon || null)); // eslint-disable-line no-undef + +},{"./sandbox":25,"./util/core":32}],29:[function(require,module,exports){ +/** + * @depend util/core.js + * @depend test.js + */ +/** + * Test case, sandboxes all test functions + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +(function (sinonGlobal) { + "use strict"; + + function createTest(property, setUp, tearDown) { + return function () { + if (setUp) { + setUp.apply(this, arguments); + } + + var exception, result; + + try { + result = property.apply(this, arguments); + } catch (e) { + exception = e; + } + + if (tearDown) { + tearDown.apply(this, arguments); + } + + if (exception) { + throw exception; + } + + return result; }; + } - sinon.calledInOrder = function (spies) { - for (var i = 1, l = spies.length; i < l; i++) { - if (!spies[i - 1].calledBefore(spies[i]) || !spies[i].called) { - return false; - } + function makeApi(sinon) { + function testCase(tests, prefix) { + if (!tests || typeof tests !== "object") { + throw new TypeError("sinon.testCase needs an object with test functions"); } - return true; - }; + prefix = prefix || "test"; + var rPrefix = new RegExp("^" + prefix); + var methods = {}; + var setUp = tests.setUp; + var tearDown = tests.tearDown; + var testName, + property, + method; - sinon.orderByFirstCall = function (spies) { - return spies.sort(function (a, b) { - // uuid, won't ever be equal - var aCall = a.getCall(0); - var bCall = b.getCall(0); - var aId = aCall && aCall.callId || -1; - var bId = bCall && bCall.callId || -1; + for (testName in tests) { + if (tests.hasOwnProperty(testName) && !/^(setUp|tearDown)$/.test(testName)) { + property = tests[testName]; - return aId < bId ? -1 : 1; - }); - }; + if (typeof property === "function" && rPrefix.test(testName)) { + method = property; - sinon.createStubInstance = function (constructor) { - if (typeof constructor !== "function") { - throw new TypeError("The constructor should be a function."); - } - return sinon.stub(sinon.create(constructor.prototype)); - }; + if (setUp || tearDown) { + method = createTest(property, setUp, tearDown); + } - sinon.restore = function (object) { - if (object !== null && typeof object === "object") { - for (var prop in object) { - if (isRestorable(object[prop])) { - object[prop].restore(); + methods[testName] = sinon.test(method); + } else { + methods[testName] = tests[testName]; } } - } else if (isRestorable(object)) { - object.restore(); } - }; - return sinon; + return methods; + } + + sinon.testCase = testCase; + return testCase; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - function loadDependencies(require, exports) { - makeApi(exports); + function loadDependencies(require, exports, module) { + var core = require("./util/core"); + require("./test"); + module.exports = makeApi(core); } if (isAMD) { @@ -5511,1499 +5247,1274 @@ var sinon = (function () { // eslint-disable-line no-unused-vars typeof sinon === "object" && sinon // eslint-disable-line no-undef )); -},{}],32:[function(require,module,exports){ +},{"./test":28,"./util/core":32}],30:[function(require,module,exports){ /** - * Minimal Event interface implementation - * - * Original implementation by Sven Fuchs: https://gist.github.com/995028 - * Modifications and tests by Christian Johansen. - * - * @author Sven Fuchs (svenfuchs@artweb-design.de) - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2011 Sven Fuchs, Christian Johansen + * @depend util/core.js */ -if (typeof sinon === "undefined") { - this.sinon = {}; -} - -(function () { +(function (sinonGlobal) { "use strict"; - var push = [].push; - function makeApi(sinon) { - sinon.Event = function Event(type, bubbles, cancelable, target) { - this.initEvent(type, bubbles, cancelable, target); - }; - - sinon.Event.prototype = { - initEvent: function (type, bubbles, cancelable, target) { - this.type = type; - this.bubbles = bubbles; - this.cancelable = cancelable; - this.target = target; - }, - - stopPropagation: function () {}, - preventDefault: function () { - this.defaultPrevented = true; + function timesInWords(count) { + switch (count) { + case 1: + return "once"; + case 2: + return "twice"; + case 3: + return "thrice"; + default: + return (count || 0) + " times"; } - }; - - sinon.ProgressEvent = function ProgressEvent(type, progressEventRaw, target) { - this.initEvent(type, false, false, target); - this.loaded = typeof progressEventRaw.loaded === "number" ? progressEventRaw.loaded : null; - this.total = typeof progressEventRaw.total === "number" ? progressEventRaw.total : null; - this.lengthComputable = !!progressEventRaw.total; - }; - - sinon.ProgressEvent.prototype = new sinon.Event(); + } - sinon.ProgressEvent.prototype.constructor = sinon.ProgressEvent; + sinon.timesInWords = timesInWords; + return sinon.timesInWords; + } - sinon.CustomEvent = function CustomEvent(type, customData, target) { - this.initEvent(type, false, false, target); - this.detail = customData.detail || null; - }; + function loadDependencies(require, exports, module) { + var core = require("./util/core"); + module.exports = makeApi(core); + } - sinon.CustomEvent.prototype = new sinon.Event(); + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - sinon.CustomEvent.prototype.constructor = sinon.CustomEvent; + if (isAMD) { + define(loadDependencies); + return; + } - sinon.EventTarget = { - addEventListener: function addEventListener(event, listener) { - this.eventListeners = this.eventListeners || {}; - this.eventListeners[event] = this.eventListeners[event] || []; - push.call(this.eventListeners[event], listener); - }, + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } - removeEventListener: function removeEventListener(event, listener) { - var listeners = this.eventListeners && this.eventListeners[event] || []; + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); - for (var i = 0, l = listeners.length; i < l; ++i) { - if (listeners[i] === listener) { - return listeners.splice(i, 1); - } - } - }, +},{"./util/core":32}],31:[function(require,module,exports){ +/** + * @depend util/core.js + */ +/** + * Format functions + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2014 Christian Johansen + */ +(function (sinonGlobal) { + "use strict"; - dispatchEvent: function dispatchEvent(event) { - var type = event.type; - var listeners = this.eventListeners && this.eventListeners[type] || []; + function makeApi(sinon) { + function typeOf(value) { + if (value === null) { + return "null"; + } else if (value === undefined) { + return "undefined"; + } + var string = Object.prototype.toString.call(value); + return string.substring(8, string.length - 1).toLowerCase(); + } - for (var i = 0; i < listeners.length; i++) { - if (typeof listeners[i] === "function") { - listeners[i].call(this, event); - } else { - listeners[i].handleEvent(event); - } - } + sinon.typeOf = typeOf; + return sinon.typeOf; + } - return !!event.defaultPrevented; - } - }; + function loadDependencies(require, exports, module) { + var core = require("./util/core"); + module.exports = makeApi(core); } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - function loadDependencies(require) { - var sinon = require("./core"); - makeApi(sinon); - } - if (isAMD) { define(loadDependencies); - } else if (isNode) { - loadDependencies(require); - } else { - makeApi(sinon); // eslint-disable-line no-undef + return; } -}()); -},{"./core":31}],33:[function(require,module,exports){ + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } + + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); + +},{"./util/core":32}],32:[function(require,module,exports){ /** - * @depend fake_xdomain_request.js - * @depend fake_xml_http_request.js - * @depend ../format.js - * @depend ../log_error.js + * @depend ../../sinon.js */ /** - * The Sinon "server" mimics a web server that receives requests from - * sinon.FakeXMLHttpRequest and provides an API to respond to those requests, - * both synchronously and asynchronously. To respond synchronuously, canned - * answers have to be provided upfront. + * Sinon core utilities. For internal use only. * * @author Christian Johansen (christian@cjohansen.no) * @license BSD * * Copyright (c) 2010-2013 Christian Johansen */ -(function () { +(function (sinonGlobal) { "use strict"; - var push = [].push; - - function responseArray(handler) { - var response = handler; + var div = typeof document !== "undefined" && document.createElement("div"); + var hasOwn = Object.prototype.hasOwnProperty; - if (Object.prototype.toString.call(handler) !== "[object Array]") { - response = [200, {}, handler]; - } + function isDOMNode(obj) { + var success = false; - if (typeof response[2] !== "string") { - throw new TypeError("Fake server response body should be string, but was " + - typeof response[2]); + try { + obj.appendChild(div); + success = div.parentNode === obj; + } catch (e) { + return false; + } finally { + try { + obj.removeChild(div); + } catch (e) { + // Remove failed, not much we can do about that + } } - return response; + return success; } - var wloc = typeof window !== "undefined" ? window.location : {}; - var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host); - - function matchOne(response, reqMethod, reqUrl) { - var rmeth = response.method; - var matchMethod = !rmeth || rmeth.toLowerCase() === reqMethod.toLowerCase(); - var url = response.url; - var matchUrl = !url || url === reqUrl || (typeof url.test === "function" && url.test(reqUrl)); - - return matchMethod && matchUrl; + function isElement(obj) { + return div && obj && obj.nodeType === 1 && isDOMNode(obj); } - function match(response, request) { - var requestUrl = request.url; + function isFunction(obj) { + return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply); + } - if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) { - requestUrl = requestUrl.replace(rCurrLoc, ""); - } + function isReallyNaN(val) { + return typeof val === "number" && isNaN(val); + } - if (matchOne(response, this.getHTTPMethod(request), requestUrl)) { - if (typeof response.response === "function") { - var ru = response.url; - var args = [request].concat(ru && typeof ru.exec === "function" ? ru.exec(requestUrl).slice(1) : []); - return response.response.apply(response, args); + function mirrorProperties(target, source) { + for (var prop in source) { + if (!hasOwn.call(target, prop)) { + target[prop] = source[prop]; } - - return true; } + } - return false; + function isRestorable(obj) { + return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon; } + // Cheap way to detect if we have ES5 support. + var hasES5Support = "keys" in Object; + function makeApi(sinon) { - sinon.fakeServer = { - create: function (config) { - var server = sinon.create(this); - server.configure(config); - if (!sinon.xhr.supportsCORS) { - this.xhr = sinon.useFakeXDomainRequest(); - } else { - this.xhr = sinon.useFakeXMLHttpRequest(); - } - server.requests = []; + sinon.wrapMethod = function wrapMethod(object, property, method) { + if (!object) { + throw new TypeError("Should wrap property of object"); + } - this.xhr.onCreate = function (xhrObj) { - server.addRequest(xhrObj); - }; + if (typeof method !== "function" && typeof method !== "object") { + throw new TypeError("Method wrapper should be a function or a property descriptor"); + } - return server; - }, - configure: function (config) { - var whitelist = { - "autoRespond": true, - "autoRespondAfter": true, - "respondImmediately": true, - "fakeHTTPMethods": true - }; - var setting; + function checkWrappedMethod(wrappedMethod) { + var error; - config = config || {}; - for (setting in config) { - if (whitelist.hasOwnProperty(setting) && config.hasOwnProperty(setting)) { - this[setting] = config[setting]; + if (!isFunction(wrappedMethod)) { + error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + + property + " as function"); + } else if (wrappedMethod.restore && wrappedMethod.restore.sinon) { + error = new TypeError("Attempted to wrap " + property + " which is already wrapped"); + } else if (wrappedMethod.calledBefore) { + var verb = wrappedMethod.returns ? "stubbed" : "spied on"; + error = new TypeError("Attempted to wrap " + property + " which is already " + verb); + } + + if (error) { + if (wrappedMethod && wrappedMethod.stackTrace) { + error.stack += "\n--------------\n" + wrappedMethod.stackTrace; } + throw error; } - }, - addRequest: function addRequest(xhrObj) { - var server = this; - push.call(this.requests, xhrObj); + } - xhrObj.onSend = function () { - server.handleRequest(this); + var error, wrappedMethod, i; - if (server.respondImmediately) { - server.respond(); - } else if (server.autoRespond && !server.responding) { - setTimeout(function () { - server.responding = false; - server.respond(); - }, server.autoRespondAfter || 10); + // IE 8 does not support hasOwnProperty on the window object and Firefox has a problem + // when using hasOwn.call on objects from other frames. + var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property); - server.responding = true; - } - }; - }, + if (hasES5Support) { + var methodDesc = (typeof method === "function") ? {value: method} : method; + var wrappedMethodDesc = sinon.getPropertyDescriptor(object, property); - getHTTPMethod: function getHTTPMethod(request) { - if (this.fakeHTTPMethods && /post/i.test(request.method)) { - var matches = (request.requestBody || "").match(/_method=([^\b;]+)/); - return matches ? matches[1] : request.method; + if (!wrappedMethodDesc) { + error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + + property + " as function"); + } else if (wrappedMethodDesc.restore && wrappedMethodDesc.restore.sinon) { + error = new TypeError("Attempted to wrap " + property + " which is already wrapped"); } - - return request.method; - }, - - handleRequest: function handleRequest(xhr) { - if (xhr.async) { - if (!this.queue) { - this.queue = []; + if (error) { + if (wrappedMethodDesc && wrappedMethodDesc.stackTrace) { + error.stack += "\n--------------\n" + wrappedMethodDesc.stackTrace; } + throw error; + } - push.call(this.queue, xhr); - } else { - this.processRequest(xhr); + var types = sinon.objectKeys(methodDesc); + for (i = 0; i < types.length; i++) { + wrappedMethod = wrappedMethodDesc[types[i]]; + checkWrappedMethod(wrappedMethod); } - }, - log: function log(response, request) { - var str; + mirrorProperties(methodDesc, wrappedMethodDesc); + for (i = 0; i < types.length; i++) { + mirrorProperties(methodDesc[types[i]], wrappedMethodDesc[types[i]]); + } + Object.defineProperty(object, property, methodDesc); + } else { + wrappedMethod = object[property]; + checkWrappedMethod(wrappedMethod); + object[property] = method; + method.displayName = property; + } - str = "Request:\n" + sinon.format(request) + "\n\n"; - str += "Response:\n" + sinon.format(response) + "\n\n"; + method.displayName = property; - sinon.log(str); - }, + // Set up a stack trace which can be used later to find what line of + // code the original method was created on. + method.stackTrace = (new Error("Stack Trace for original")).stack; - respondWith: function respondWith(method, url, body) { - if (arguments.length === 1 && typeof method !== "function") { - this.response = responseArray(method); - return; + method.restore = function () { + // For prototype properties try to reset by delete first. + // If this fails (ex: localStorage on mobile safari) then force a reset + // via direct assignment. + if (!owned) { + // In some cases `delete` may throw an error + try { + delete object[property]; + } catch (e) {} // eslint-disable-line no-empty + // For native code functions `delete` fails without throwing an error + // on Chrome < 43, PhantomJS, etc. + } else if (hasES5Support) { + Object.defineProperty(object, property, wrappedMethodDesc); } - if (!this.responses) { - this.responses = []; + // Use strict equality comparison to check failures then force a reset + // via direct assignment. + if (object[property] === method) { + object[property] = wrappedMethod; } + }; - if (arguments.length === 1) { - body = method; - url = method = null; - } + method.restore.sinon = true; - if (arguments.length === 2) { - body = url; - url = method; - method = null; - } + if (!hasES5Support) { + mirrorProperties(method, wrappedMethod); + } - push.call(this.responses, { - method: method, - url: url, - response: typeof body === "function" ? body : responseArray(body) - }); - }, + return method; + }; - respond: function respond() { - if (arguments.length > 0) { - this.respondWith.apply(this, arguments); - } + sinon.create = function create(proto) { + var F = function () {}; + F.prototype = proto; + return new F(); + }; + + sinon.deepEqual = function deepEqual(a, b) { + if (sinon.match && sinon.match.isMatcher(a)) { + return a.test(b); + } + + if (typeof a !== "object" || typeof b !== "object") { + return isReallyNaN(a) && isReallyNaN(b) || a === b; + } + + if (isElement(a) || isElement(b)) { + return a === b; + } + + if (a === b) { + return true; + } + + if ((a === null && b !== null) || (a !== null && b === null)) { + return false; + } + + if (a instanceof RegExp && b instanceof RegExp) { + return (a.source === b.source) && (a.global === b.global) && + (a.ignoreCase === b.ignoreCase) && (a.multiline === b.multiline); + } + + var aString = Object.prototype.toString.call(a); + if (aString !== Object.prototype.toString.call(b)) { + return false; + } - var queue = this.queue || []; - var requests = queue.splice(0, queue.length); + if (aString === "[object Date]") { + return a.valueOf() === b.valueOf(); + } - for (var i = 0; i < requests.length; i++) { - this.processRequest(requests[i]); - } - }, + var prop; + var aLength = 0; + var bLength = 0; - processRequest: function processRequest(request) { - try { - if (request.aborted) { - return; - } + if (aString === "[object Array]" && a.length !== b.length) { + return false; + } - var response = this.response || [404, {}, ""]; + for (prop in a) { + if (hasOwn.call(a, prop)) { + aLength += 1; - if (this.responses) { - for (var l = this.responses.length, i = l - 1; i >= 0; i--) { - if (match.call(this, this.responses[i], request)) { - response = this.responses[i].response; - break; - } - } + if (!(prop in b)) { + return false; } - if (request.readyState !== 4) { - this.log(response, request); - - request.respond(response[0], response[1], response[2]); + if (!deepEqual(a[prop], b[prop])) { + return false; } - } catch (e) { - sinon.logError("Fake server request processing", e); } - }, + } - restore: function restore() { - return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments); + for (prop in b) { + if (hasOwn.call(b, prop)) { + bLength += 1; + } } - }; - } - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + return aLength === bLength; + }; - function loadDependencies(require, exports, module) { - var sinon = require("./core"); - require("./fake_xdomain_request"); - require("./fake_xml_http_request"); - require("../format"); - makeApi(sinon); - module.exports = sinon; - } + sinon.functionName = function functionName(func) { + var name = func.displayName || func.name; - if (isAMD) { - define(loadDependencies); - } else if (isNode) { - loadDependencies(require, module.exports, module); - } else { - makeApi(sinon); // eslint-disable-line no-undef - } -}()); + // Use function decomposition as a last resort to get function + // name. Does not rely on function decomposition to work - if it + // doesn't debugging will be slightly less informative + // (i.e. toString will say 'spy' rather than 'myFunc'). + if (!name) { + var matches = func.toString().match(/function ([^\s\(]+)/); + name = matches && matches[1]; + } -},{"../format":20,"./core":31,"./fake_xdomain_request":36,"./fake_xml_http_request":37}],34:[function(require,module,exports){ -/** - * @depend fake_server.js - * @depend fake_timers.js - */ -/** - * Add-on for sinon.fakeServer that automatically handles a fake timer along with - * the FakeXMLHttpRequest. The direct inspiration for this add-on is jQuery - * 1.3.x, which does not use xhr object's onreadystatehandler at all - instead, - * it polls the object for completion with setInterval. Dispite the direct - * motivation, there is nothing jQuery-specific in this file, so it can be used - * in any environment where the ajax implementation depends on setInterval or - * setTimeout. - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -(function () { - "use strict"; + return name; + }; - function makeApi(sinon) { - function Server() {} - Server.prototype = sinon.fakeServer; + sinon.functionToString = function toString() { + if (this.getCall && this.callCount) { + var thisValue, + prop; + var i = this.callCount; - sinon.fakeServerWithClock = new Server(); + while (i--) { + thisValue = this.getCall(i).thisValue; - sinon.fakeServerWithClock.addRequest = function addRequest(xhr) { - if (xhr.async) { - if (typeof setTimeout.clock === "object") { - this.clock = setTimeout.clock; - } else { - this.clock = sinon.useFakeTimers(); - this.resetClock = true; + for (prop in thisValue) { + if (thisValue[prop] === this) { + return prop; + } + } } + } - if (!this.longestTimeout) { - var clockSetTimeout = this.clock.setTimeout; - var clockSetInterval = this.clock.setInterval; - var server = this; - - this.clock.setTimeout = function (fn, timeout) { - server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); - - return clockSetTimeout.apply(this, arguments); - }; + return this.displayName || "sinon fake"; + }; - this.clock.setInterval = function (fn, timeout) { - server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); + sinon.objectKeys = function objectKeys(obj) { + if (obj !== Object(obj)) { + throw new TypeError("sinon.objectKeys called on a non-object"); + } - return clockSetInterval.apply(this, arguments); - }; + var keys = []; + var key; + for (key in obj) { + if (hasOwn.call(obj, key)) { + keys.push(key); } } - return sinon.fakeServer.addRequest.call(this, xhr); + return keys; }; - sinon.fakeServerWithClock.respond = function respond() { - var returnVal = sinon.fakeServer.respond.apply(this, arguments); - - if (this.clock) { - this.clock.tick(this.longestTimeout || 0); - this.longestTimeout = 0; + sinon.getPropertyDescriptor = function getPropertyDescriptor(object, property) { + var proto = object; + var descriptor; - if (this.resetClock) { - this.clock.restore(); - this.resetClock = false; - } + while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) { + proto = Object.getPrototypeOf(proto); } - - return returnVal; + return descriptor; }; - sinon.fakeServerWithClock.restore = function restore() { - if (this.clock) { - this.clock.restore(); + sinon.getConfig = function (custom) { + var config = {}; + custom = custom || {}; + var defaults = sinon.defaultConfig; + + for (var prop in defaults) { + if (defaults.hasOwnProperty(prop)) { + config[prop] = custom.hasOwnProperty(prop) ? custom[prop] : defaults[prop]; + } } - return sinon.fakeServer.restore.apply(this, arguments); + return config; }; - } - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + sinon.defaultConfig = { + injectIntoThis: true, + injectInto: null, + properties: ["spy", "stub", "mock", "clock", "server", "requests"], + useFakeTimers: true, + useFakeServer: true + }; - function loadDependencies(require) { - var sinon = require("./core"); - require("./fake_server"); - require("./fake_timers"); - makeApi(sinon); - } + sinon.timesInWords = function timesInWords(count) { + return count === 1 && "once" || + count === 2 && "twice" || + count === 3 && "thrice" || + (count || 0) + " times"; + }; - if (isAMD) { - define(loadDependencies); - } else if (isNode) { - loadDependencies(require); - } else { - makeApi(sinon); // eslint-disable-line no-undef - } -}()); + sinon.calledInOrder = function (spies) { + for (var i = 1, l = spies.length; i < l; i++) { + if (!spies[i - 1].calledBefore(spies[i]) || !spies[i].called) { + return false; + } + } -},{"./core":31,"./fake_server":33,"./fake_timers":35}],35:[function(require,module,exports){ -/** - * Fake timer API - * setTimeout - * setInterval - * clearTimeout - * clearInterval - * tick - * reset - * Date - * - * Inspired by jsUnitMockTimeOut from JsUnit - * - * @author Christian Johansen (christian@cjohansen.no) - * @license BSD - * - * Copyright (c) 2010-2013 Christian Johansen - */ -(function () { - "use strict"; + return true; + }; - function makeApi(s, lol) { - /*global lolex */ - var llx = typeof lolex !== "undefined" ? lolex : lol; + sinon.orderByFirstCall = function (spies) { + return spies.sort(function (a, b) { + // uuid, won't ever be equal + var aCall = a.getCall(0); + var bCall = b.getCall(0); + var aId = aCall && aCall.callId || -1; + var bId = bCall && bCall.callId || -1; - s.useFakeTimers = function () { - var now; - var methods = Array.prototype.slice.call(arguments); + return aId < bId ? -1 : 1; + }); + }; - if (typeof methods[0] === "string") { - now = 0; - } else { - now = methods.shift(); + sinon.createStubInstance = function (constructor) { + if (typeof constructor !== "function") { + throw new TypeError("The constructor should be a function."); } - - var clock = llx.install(now || 0, methods); - clock.restore = clock.uninstall; - return clock; + return sinon.stub(sinon.create(constructor.prototype)); }; - s.clock = { - create: function (now) { - return llx.createClock(now); + sinon.restore = function (object) { + if (object !== null && typeof object === "object") { + for (var prop in object) { + if (isRestorable(object[prop])) { + object[prop].restore(); + } + } + } else if (isRestorable(object)) { + object.restore(); } }; - s.timers = { - setTimeout: setTimeout, - clearTimeout: clearTimeout, - setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined), - clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate : undefined), - setInterval: setInterval, - clearInterval: clearInterval, - Date: Date - }; + return sinon; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - function loadDependencies(require, epxorts, module, lolex) { - var core = require("./core"); - makeApi(core, lolex); - module.exports = core; + function loadDependencies(require, exports) { + makeApi(exports); } if (isAMD) { define(loadDependencies); - } else if (isNode) { - loadDependencies(require, module.exports, module, require("lolex")); - } else { - makeApi(sinon); // eslint-disable-line no-undef + return; } -}()); -},{"./core":31,"lolex":40}],36:[function(require,module,exports){ -(function (global){ -/** - * @depend core.js - * @depend ../extend.js - * @depend event.js - * @depend ../log_error.js - */ -/** - * Fake XDomainRequest object - */ + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } + + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); +},{}],33:[function(require,module,exports){ /** - * Returns the global to prevent assigning values to 'this' when this is undefined. - * This can occur when files are interpreted by node in strict mode. - * @private + * Minimal Event interface implementation + * + * Original implementation by Sven Fuchs: https://gist.github.com/995028 + * Modifications and tests by Christian Johansen. + * + * @author Sven Fuchs (svenfuchs@artweb-design.de) + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2011 Sven Fuchs, Christian Johansen */ -function getGlobal() { - "use strict"; - - return typeof window !== "undefined" ? window : global; -} - if (typeof sinon === "undefined") { - if (typeof this === "undefined") { - getGlobal().sinon = {}; - } else { - this.sinon = {}; - } + this.sinon = {}; } -// wrapper for global -(function (global) { +(function () { "use strict"; - var xdr = { XDomainRequest: global.XDomainRequest }; - xdr.GlobalXDomainRequest = global.XDomainRequest; - xdr.supportsXDR = typeof xdr.GlobalXDomainRequest !== "undefined"; - xdr.workingXDR = xdr.supportsXDR ? xdr.GlobalXDomainRequest : false; + var push = [].push; function makeApi(sinon) { - sinon.xdr = xdr; - - function FakeXDomainRequest() { - this.readyState = FakeXDomainRequest.UNSENT; - this.requestBody = null; - this.requestHeaders = {}; - this.status = 0; - this.timeout = null; - - if (typeof FakeXDomainRequest.onCreate === "function") { - FakeXDomainRequest.onCreate(this); - } - } - - function verifyState(x) { - if (x.readyState !== FakeXDomainRequest.OPENED) { - throw new Error("INVALID_STATE_ERR"); - } - - if (x.sendFlag) { - throw new Error("INVALID_STATE_ERR"); - } - } - - function verifyRequestSent(x) { - if (x.readyState === FakeXDomainRequest.UNSENT) { - throw new Error("Request not sent"); - } - if (x.readyState === FakeXDomainRequest.DONE) { - throw new Error("Request done"); - } - } - - function verifyResponseBodyType(body) { - if (typeof body !== "string") { - var error = new Error("Attempted to respond to fake XDomainRequest with " + - body + ", which is not a string."); - error.name = "InvalidBodyException"; - throw error; - } - } - - sinon.extend(FakeXDomainRequest.prototype, sinon.EventTarget, { - open: function open(method, url) { - this.method = method; - this.url = url; - - this.responseText = null; - this.sendFlag = false; - - this.readyStateChange(FakeXDomainRequest.OPENED); - }, - - readyStateChange: function readyStateChange(state) { - this.readyState = state; - var eventName = ""; - switch (this.readyState) { - case FakeXDomainRequest.UNSENT: - break; - case FakeXDomainRequest.OPENED: - break; - case FakeXDomainRequest.LOADING: - if (this.sendFlag) { - //raise the progress event - eventName = "onprogress"; - } - break; - case FakeXDomainRequest.DONE: - if (this.isTimeout) { - eventName = "ontimeout"; - } else if (this.errorFlag || (this.status < 200 || this.status > 299)) { - eventName = "onerror"; - } else { - eventName = "onload"; - } - break; - } + sinon.Event = function Event(type, bubbles, cancelable, target) { + this.initEvent(type, bubbles, cancelable, target); + }; - // raising event (if defined) - if (eventName) { - if (typeof this[eventName] === "function") { - try { - this[eventName](); - } catch (e) { - sinon.logError("Fake XHR " + eventName + " handler", e); - } - } - } + sinon.Event.prototype = { + initEvent: function (type, bubbles, cancelable, target) { + this.type = type; + this.bubbles = bubbles; + this.cancelable = cancelable; + this.target = target; }, - send: function send(data) { - verifyState(this); - - if (!/^(get|head)$/i.test(this.method)) { - this.requestBody = data; - } - this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8"; - - this.errorFlag = false; - this.sendFlag = true; - this.readyStateChange(FakeXDomainRequest.OPENED); - - if (typeof this.onSend === "function") { - this.onSend(this); - } - }, + stopPropagation: function () {}, - abort: function abort() { - this.aborted = true; - this.responseText = null; - this.errorFlag = true; + preventDefault: function () { + this.defaultPrevented = true; + } + }; - if (this.readyState > sinon.FakeXDomainRequest.UNSENT && this.sendFlag) { - this.readyStateChange(sinon.FakeXDomainRequest.DONE); - this.sendFlag = false; - } - }, + sinon.ProgressEvent = function ProgressEvent(type, progressEventRaw, target) { + this.initEvent(type, false, false, target); + this.loaded = typeof progressEventRaw.loaded === "number" ? progressEventRaw.loaded : null; + this.total = typeof progressEventRaw.total === "number" ? progressEventRaw.total : null; + this.lengthComputable = !!progressEventRaw.total; + }; - setResponseBody: function setResponseBody(body) { - verifyRequestSent(this); - verifyResponseBodyType(body); + sinon.ProgressEvent.prototype = new sinon.Event(); - var chunkSize = this.chunkSize || 10; - var index = 0; - this.responseText = ""; + sinon.ProgressEvent.prototype.constructor = sinon.ProgressEvent; - do { - this.readyStateChange(FakeXDomainRequest.LOADING); - this.responseText += body.substring(index, index + chunkSize); - index += chunkSize; - } while (index < body.length); + sinon.CustomEvent = function CustomEvent(type, customData, target) { + this.initEvent(type, false, false, target); + this.detail = customData.detail || null; + }; - this.readyStateChange(FakeXDomainRequest.DONE); - }, + sinon.CustomEvent.prototype = new sinon.Event(); - respond: function respond(status, contentType, body) { - // content-type ignored, since XDomainRequest does not carry this - // we keep the same syntax for respond(...) as for FakeXMLHttpRequest to ease - // test integration across browsers - this.status = typeof status === "number" ? status : 200; - this.setResponseBody(body || ""); - }, + sinon.CustomEvent.prototype.constructor = sinon.CustomEvent; - simulatetimeout: function simulatetimeout() { - this.status = 0; - this.isTimeout = true; - // Access to this should actually throw an error - this.responseText = undefined; - this.readyStateChange(FakeXDomainRequest.DONE); - } - }); + sinon.EventTarget = { + addEventListener: function addEventListener(event, listener) { + this.eventListeners = this.eventListeners || {}; + this.eventListeners[event] = this.eventListeners[event] || []; + push.call(this.eventListeners[event], listener); + }, - sinon.extend(FakeXDomainRequest, { - UNSENT: 0, - OPENED: 1, - LOADING: 3, - DONE: 4 - }); + removeEventListener: function removeEventListener(event, listener) { + var listeners = this.eventListeners && this.eventListeners[event] || []; - sinon.useFakeXDomainRequest = function useFakeXDomainRequest() { - sinon.FakeXDomainRequest.restore = function restore(keepOnCreate) { - if (xdr.supportsXDR) { - global.XDomainRequest = xdr.GlobalXDomainRequest; + for (var i = 0, l = listeners.length; i < l; ++i) { + if (listeners[i] === listener) { + return listeners.splice(i, 1); + } } + }, - delete sinon.FakeXDomainRequest.restore; + dispatchEvent: function dispatchEvent(event) { + var type = event.type; + var listeners = this.eventListeners && this.eventListeners[type] || []; - if (keepOnCreate !== true) { - delete sinon.FakeXDomainRequest.onCreate; + for (var i = 0; i < listeners.length; i++) { + if (typeof listeners[i] === "function") { + listeners[i].call(this, event); + } else { + listeners[i].handleEvent(event); + } } - }; - if (xdr.supportsXDR) { - global.XDomainRequest = sinon.FakeXDomainRequest; + + return !!event.defaultPrevented; } - return sinon.FakeXDomainRequest; }; - - sinon.FakeXDomainRequest = FakeXDomainRequest; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - function loadDependencies(require, exports, module) { + function loadDependencies(require) { var sinon = require("./core"); - require("../extend"); - require("./event"); - require("../log_error"); makeApi(sinon); - module.exports = sinon; } if (isAMD) { define(loadDependencies); } else if (isNode) { - loadDependencies(require, module.exports, module); + loadDependencies(require); } else { makeApi(sinon); // eslint-disable-line no-undef } -})(typeof global !== "undefined" ? global : self); +}()); -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../extend":19,"../log_error":21,"./core":31,"./event":32}],37:[function(require,module,exports){ -(function (global){ +},{"./core":32}],34:[function(require,module,exports){ /** - * @depend core.js - * @depend ../extend.js - * @depend event.js + * @depend fake_xdomain_request.js + * @depend fake_xml_http_request.js + * @depend ../format.js * @depend ../log_error.js */ /** - * Fake XMLHttpRequest object + * The Sinon "server" mimics a web server that receives requests from + * sinon.FakeXMLHttpRequest and provides an API to respond to those requests, + * both synchronously and asynchronously. To respond synchronuously, canned + * answers have to be provided upfront. * * @author Christian Johansen (christian@cjohansen.no) * @license BSD * * Copyright (c) 2010-2013 Christian Johansen */ -(function (sinonGlobal, global) { +(function () { "use strict"; - function getWorkingXHR(globalScope) { - var supportsXHR = typeof globalScope.XMLHttpRequest !== "undefined"; - if (supportsXHR) { - return globalScope.XMLHttpRequest; + var push = [].push; + + function responseArray(handler) { + var response = handler; + + if (Object.prototype.toString.call(handler) !== "[object Array]") { + response = [200, {}, handler]; } - var supportsActiveX = typeof globalScope.ActiveXObject !== "undefined"; - if (supportsActiveX) { - return function () { - return new globalScope.ActiveXObject("MSXML2.XMLHTTP.3.0"); - }; + if (typeof response[2] !== "string") { + throw new TypeError("Fake server response body should be string, but was " + + typeof response[2]); } - return false; + return response; } - var supportsProgress = typeof ProgressEvent !== "undefined"; - var supportsCustomEvent = typeof CustomEvent !== "undefined"; - var supportsFormData = typeof FormData !== "undefined"; - var supportsArrayBuffer = typeof ArrayBuffer !== "undefined"; - var supportsBlob = (function () { - try { - return !!new Blob(); - } catch (e) { - return false; + var wloc = typeof window !== "undefined" ? window.location : {}; + var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host); + + function matchOne(response, reqMethod, reqUrl) { + var rmeth = response.method; + var matchMethod = !rmeth || rmeth.toLowerCase() === reqMethod.toLowerCase(); + var url = response.url; + var matchUrl = !url || url === reqUrl || (typeof url.test === "function" && url.test(reqUrl)); + + return matchMethod && matchUrl; + } + + function match(response, request) { + var requestUrl = request.url; + + if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) { + requestUrl = requestUrl.replace(rCurrLoc, ""); } - })(); - var sinonXhr = { XMLHttpRequest: global.XMLHttpRequest }; - sinonXhr.GlobalXMLHttpRequest = global.XMLHttpRequest; - sinonXhr.GlobalActiveXObject = global.ActiveXObject; - sinonXhr.supportsActiveX = typeof sinonXhr.GlobalActiveXObject !== "undefined"; - sinonXhr.supportsXHR = typeof sinonXhr.GlobalXMLHttpRequest !== "undefined"; - sinonXhr.workingXHR = getWorkingXHR(global); - sinonXhr.supportsCORS = sinonXhr.supportsXHR && "withCredentials" in (new sinonXhr.GlobalXMLHttpRequest()); - var unsafeHeaders = { - "Accept-Charset": true, - "Accept-Encoding": true, - Connection: true, - "Content-Length": true, - Cookie: true, - Cookie2: true, - "Content-Transfer-Encoding": true, - Date: true, - Expect: true, - Host: true, - "Keep-Alive": true, - Referer: true, - TE: true, - Trailer: true, - "Transfer-Encoding": true, - Upgrade: true, - "User-Agent": true, - Via: true - }; + if (matchOne(response, this.getHTTPMethod(request), requestUrl)) { + if (typeof response.response === "function") { + var ru = response.url; + var args = [request].concat(ru && typeof ru.exec === "function" ? ru.exec(requestUrl).slice(1) : []); + return response.response.apply(response, args); + } - // An upload object is created for each - // FakeXMLHttpRequest and allows upload - // events to be simulated using uploadProgress - // and uploadError. - function UploadProgress() { - this.eventListeners = { - abort: [], - error: [], - load: [], - loadend: [], - progress: [] - }; + return true; + } + + return false; } - UploadProgress.prototype.addEventListener = function addEventListener(event, listener) { - this.eventListeners[event].push(listener); - }; + function makeApi(sinon) { + sinon.fakeServer = { + create: function (config) { + var server = sinon.create(this); + server.configure(config); + if (!sinon.xhr.supportsCORS) { + this.xhr = sinon.useFakeXDomainRequest(); + } else { + this.xhr = sinon.useFakeXMLHttpRequest(); + } + server.requests = []; + + this.xhr.onCreate = function (xhrObj) { + server.addRequest(xhrObj); + }; + + return server; + }, + configure: function (config) { + var whitelist = { + "autoRespond": true, + "autoRespondAfter": true, + "respondImmediately": true, + "fakeHTTPMethods": true + }; + var setting; + + config = config || {}; + for (setting in config) { + if (whitelist.hasOwnProperty(setting) && config.hasOwnProperty(setting)) { + this[setting] = config[setting]; + } + } + }, + addRequest: function addRequest(xhrObj) { + var server = this; + push.call(this.requests, xhrObj); + + xhrObj.onSend = function () { + server.handleRequest(this); + + if (server.respondImmediately) { + server.respond(); + } else if (server.autoRespond && !server.responding) { + setTimeout(function () { + server.responding = false; + server.respond(); + }, server.autoRespondAfter || 10); + + server.responding = true; + } + }; + }, + + getHTTPMethod: function getHTTPMethod(request) { + if (this.fakeHTTPMethods && /post/i.test(request.method)) { + var matches = (request.requestBody || "").match(/_method=([^\b;]+)/); + return matches ? matches[1] : request.method; + } + + return request.method; + }, + + handleRequest: function handleRequest(xhr) { + if (xhr.async) { + if (!this.queue) { + this.queue = []; + } + + push.call(this.queue, xhr); + } else { + this.processRequest(xhr); + } + }, + + log: function log(response, request) { + var str; - UploadProgress.prototype.removeEventListener = function removeEventListener(event, listener) { - var listeners = this.eventListeners[event] || []; + str = "Request:\n" + sinon.format(request) + "\n\n"; + str += "Response:\n" + sinon.format(response) + "\n\n"; - for (var i = 0, l = listeners.length; i < l; ++i) { - if (listeners[i] === listener) { - return listeners.splice(i, 1); - } - } - }; + sinon.log(str); + }, - UploadProgress.prototype.dispatchEvent = function dispatchEvent(event) { - var listeners = this.eventListeners[event.type] || []; + respondWith: function respondWith(method, url, body) { + if (arguments.length === 1 && typeof method !== "function") { + this.response = responseArray(method); + return; + } - for (var i = 0, listener; (listener = listeners[i]) != null; i++) { - listener(event); - } - }; + if (!this.responses) { + this.responses = []; + } - // Note that for FakeXMLHttpRequest to work pre ES5 - // we lose some of the alignment with the spec. - // To ensure as close a match as possible, - // set responseType before calling open, send or respond; - function FakeXMLHttpRequest() { - this.readyState = FakeXMLHttpRequest.UNSENT; - this.requestHeaders = {}; - this.requestBody = null; - this.status = 0; - this.statusText = ""; - this.upload = new UploadProgress(); - this.responseType = ""; - this.response = ""; - if (sinonXhr.supportsCORS) { - this.withCredentials = false; - } + if (arguments.length === 1) { + body = method; + url = method = null; + } - var xhr = this; - var events = ["loadstart", "load", "abort", "error", "loadend"]; + if (arguments.length === 2) { + body = url; + url = method; + method = null; + } - function addEventListener(eventName) { - xhr.addEventListener(eventName, function (event) { - var listener = xhr["on" + eventName]; + push.call(this.responses, { + method: method, + url: url, + response: typeof body === "function" ? body : responseArray(body) + }); + }, - if (listener && typeof listener === "function") { - listener.call(this, event); + respond: function respond() { + if (arguments.length > 0) { + this.respondWith.apply(this, arguments); } - }); - } - for (var i = events.length - 1; i >= 0; i--) { - addEventListener(events[i]); - } + var queue = this.queue || []; + var requests = queue.splice(0, queue.length); - if (typeof FakeXMLHttpRequest.onCreate === "function") { - FakeXMLHttpRequest.onCreate(this); - } - } + for (var i = 0; i < requests.length; i++) { + this.processRequest(requests[i]); + } + }, - function verifyState(xhr) { - if (xhr.readyState !== FakeXMLHttpRequest.OPENED) { - throw new Error("INVALID_STATE_ERR"); - } + processRequest: function processRequest(request) { + try { + if (request.aborted) { + return; + } - if (xhr.sendFlag) { - throw new Error("INVALID_STATE_ERR"); - } - } + var response = this.response || [404, {}, ""]; - function getHeader(headers, header) { - header = header.toLowerCase(); + if (this.responses) { + for (var l = this.responses.length, i = l - 1; i >= 0; i--) { + if (match.call(this, this.responses[i], request)) { + response = this.responses[i].response; + break; + } + } + } - for (var h in headers) { - if (h.toLowerCase() === header) { - return h; - } - } + if (request.readyState !== 4) { + this.log(response, request); - return null; + request.respond(response[0], response[1], response[2]); + } + } catch (e) { + sinon.logError("Fake server request processing", e); + } + }, + + restore: function restore() { + return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments); + } + }; } - // filtering to enable a white-list version of Sinon FakeXhr, - // where whitelisted requests are passed through to real XHR - function each(collection, callback) { - if (!collection) { - return; - } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - for (var i = 0, l = collection.length; i < l; i += 1) { - callback(collection[i]); - } + function loadDependencies(require, exports, module) { + var sinon = require("./core"); + require("./fake_xdomain_request"); + require("./fake_xml_http_request"); + require("../format"); + makeApi(sinon); + module.exports = sinon; } - function some(collection, callback) { - for (var index = 0; index < collection.length; index++) { - if (callback(collection[index]) === true) { - return true; - } - } - return false; + + if (isAMD) { + define(loadDependencies); + } else if (isNode) { + loadDependencies(require, module.exports, module); + } else { + makeApi(sinon); // eslint-disable-line no-undef } - // largest arity in XHR is 5 - XHR#open - var apply = function (obj, method, args) { - switch (args.length) { - case 0: return obj[method](); - case 1: return obj[method](args[0]); - case 2: return obj[method](args[0], args[1]); - case 3: return obj[method](args[0], args[1], args[2]); - case 4: return obj[method](args[0], args[1], args[2], args[3]); - case 5: return obj[method](args[0], args[1], args[2], args[3], args[4]); - } - }; +}()); - FakeXMLHttpRequest.filters = []; - FakeXMLHttpRequest.addFilter = function addFilter(fn) { - this.filters.push(fn); - }; - var IE6Re = /MSIE 6/; - FakeXMLHttpRequest.defake = function defake(fakeXhr, xhrArgs) { - var xhr = new sinonXhr.workingXHR(); // eslint-disable-line new-cap +},{"../format":21,"./core":32,"./fake_xdomain_request":37,"./fake_xml_http_request":38}],35:[function(require,module,exports){ +/** + * @depend fake_server.js + * @depend fake_timers.js + */ +/** + * Add-on for sinon.fakeServer that automatically handles a fake timer along with + * the FakeXMLHttpRequest. The direct inspiration for this add-on is jQuery + * 1.3.x, which does not use xhr object's onreadystatehandler at all - instead, + * it polls the object for completion with setInterval. Dispite the direct + * motivation, there is nothing jQuery-specific in this file, so it can be used + * in any environment where the ajax implementation depends on setInterval or + * setTimeout. + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +(function () { + "use strict"; - each([ - "open", - "setRequestHeader", - "send", - "abort", - "getResponseHeader", - "getAllResponseHeaders", - "addEventListener", - "overrideMimeType", - "removeEventListener" - ], function (method) { - fakeXhr[method] = function () { - return apply(xhr, method, arguments); - }; - }); + function makeApi(sinon) { + function Server() {} + Server.prototype = sinon.fakeServer; - var copyAttrs = function (args) { - each(args, function (attr) { - try { - fakeXhr[attr] = xhr[attr]; - } catch (e) { - if (!IE6Re.test(navigator.userAgent)) { - throw e; - } + sinon.fakeServerWithClock = new Server(); + + sinon.fakeServerWithClock.addRequest = function addRequest(xhr) { + if (xhr.async) { + if (typeof setTimeout.clock === "object") { + this.clock = setTimeout.clock; + } else { + this.clock = sinon.useFakeTimers(); + this.resetClock = true; } - }); - }; - var stateChange = function stateChange() { - fakeXhr.readyState = xhr.readyState; - if (xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) { - copyAttrs(["status", "statusText"]); - } - if (xhr.readyState >= FakeXMLHttpRequest.LOADING) { - copyAttrs(["responseText", "response"]); - } - if (xhr.readyState === FakeXMLHttpRequest.DONE) { - copyAttrs(["responseXML"]); - } - if (fakeXhr.onreadystatechange) { - fakeXhr.onreadystatechange.call(fakeXhr, { target: fakeXhr }); + if (!this.longestTimeout) { + var clockSetTimeout = this.clock.setTimeout; + var clockSetInterval = this.clock.setInterval; + var server = this; + + this.clock.setTimeout = function (fn, timeout) { + server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); + + return clockSetTimeout.apply(this, arguments); + }; + + this.clock.setInterval = function (fn, timeout) { + server.longestTimeout = Math.max(timeout, server.longestTimeout || 0); + + return clockSetInterval.apply(this, arguments); + }; + } } + + return sinon.fakeServer.addRequest.call(this, xhr); }; - if (xhr.addEventListener) { - for (var event in fakeXhr.eventListeners) { - if (fakeXhr.eventListeners.hasOwnProperty(event)) { + sinon.fakeServerWithClock.respond = function respond() { + var returnVal = sinon.fakeServer.respond.apply(this, arguments); - /*eslint-disable no-loop-func*/ - each(fakeXhr.eventListeners[event], function (handler) { - xhr.addEventListener(event, handler); - }); - /*eslint-enable no-loop-func*/ + if (this.clock) { + this.clock.tick(this.longestTimeout || 0); + this.longestTimeout = 0; + + if (this.resetClock) { + this.clock.restore(); + this.resetClock = false; } } - xhr.addEventListener("readystatechange", stateChange); - } else { - xhr.onreadystatechange = stateChange; - } - apply(xhr, "open", xhrArgs); - }; - FakeXMLHttpRequest.useFilters = false; - function verifyRequestOpened(xhr) { - if (xhr.readyState !== FakeXMLHttpRequest.OPENED) { - throw new Error("INVALID_STATE_ERR - " + xhr.readyState); - } - } + return returnVal; + }; - function verifyRequestSent(xhr) { - if (xhr.readyState === FakeXMLHttpRequest.DONE) { - throw new Error("Request done"); - } - } + sinon.fakeServerWithClock.restore = function restore() { + if (this.clock) { + this.clock.restore(); + } - function verifyHeadersReceived(xhr) { - if (xhr.async && xhr.readyState !== FakeXMLHttpRequest.HEADERS_RECEIVED) { - throw new Error("No headers received"); - } + return sinon.fakeServer.restore.apply(this, arguments); + }; } - function verifyResponseBodyType(body) { - if (typeof body !== "string") { - var error = new Error("Attempted to respond to fake XMLHttpRequest with " + - body + ", which is not a string."); - error.name = "InvalidBodyException"; - throw error; - } - } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - function convertToArrayBuffer(body) { - var buffer = new ArrayBuffer(body.length); - var view = new Uint8Array(buffer); - for (var i = 0; i < body.length; i++) { - var charCode = body.charCodeAt(i); - if (charCode >= 256) { - throw new TypeError("arraybuffer or blob responseTypes require binary string, " + - "invalid character " + body[i] + " found."); - } - view[i] = charCode; - } - return buffer; + function loadDependencies(require) { + var sinon = require("./core"); + require("./fake_server"); + require("./fake_timers"); + makeApi(sinon); } - function isXmlContentType(contentType) { - return !contentType || /(text\/xml)|(application\/xml)|(\+xml)/.test(contentType); + if (isAMD) { + define(loadDependencies); + } else if (isNode) { + loadDependencies(require); + } else { + makeApi(sinon); // eslint-disable-line no-undef } +}()); - function convertResponseBody(responseType, contentType, body) { - if (responseType === "" || responseType === "text") { - return body; - } else if (supportsArrayBuffer && responseType === "arraybuffer") { - return convertToArrayBuffer(body); - } else if (responseType === "json") { - try { - return JSON.parse(body); - } catch (e) { - // Return parsing failure as null - return null; - } - } else if (supportsBlob && responseType === "blob") { - var blobOptions = {}; - if (contentType) { - blobOptions.type = contentType; +},{"./core":32,"./fake_server":34,"./fake_timers":36}],36:[function(require,module,exports){ +/** + * Fake timer API + * setTimeout + * setInterval + * clearTimeout + * clearInterval + * tick + * reset + * Date + * + * Inspired by jsUnitMockTimeOut from JsUnit + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +(function () { + "use strict"; + + function makeApi(s, lol) { + /*global lolex */ + var llx = typeof lolex !== "undefined" ? lolex : lol; + + s.useFakeTimers = function () { + var now; + var methods = Array.prototype.slice.call(arguments); + + if (typeof methods[0] === "string") { + now = 0; + } else { + now = methods.shift(); } - return new Blob([convertToArrayBuffer(body)], blobOptions); - } else if (responseType === "document") { - if (isXmlContentType(contentType)) { - return FakeXMLHttpRequest.parseXML(body); + + var clock = llx.install(now || 0, methods); + clock.restore = clock.uninstall; + return clock; + }; + + s.clock = { + create: function (now) { + return llx.createClock(now); } - return null; - } - throw new Error("Invalid responseType " + responseType); - } + }; - function clearResponse(xhr) { - if (xhr.responseType === "" || xhr.responseType === "text") { - xhr.response = xhr.responseText = ""; - } else { - xhr.response = xhr.responseText = null; - } - xhr.responseXML = null; + s.timers = { + setTimeout: setTimeout, + clearTimeout: clearTimeout, + setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined), + clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate : undefined), + setInterval: setInterval, + clearInterval: clearInterval, + Date: Date + }; } - FakeXMLHttpRequest.parseXML = function parseXML(text) { - // Treat empty string as parsing failure - if (text !== "") { - try { - if (typeof DOMParser !== "undefined") { - var parser = new DOMParser(); - return parser.parseFromString(text, "text/xml"); - } - var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM"); - xmlDoc.async = "false"; - xmlDoc.loadXML(text); - return xmlDoc; - } catch (e) { - // Unable to parse XML - no biggie - } - } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - return null; - }; + function loadDependencies(require, epxorts, module, lolex) { + var core = require("./core"); + makeApi(core, lolex); + module.exports = core; + } - FakeXMLHttpRequest.statusCodes = { - 100: "Continue", - 101: "Switching Protocols", - 200: "OK", - 201: "Created", - 202: "Accepted", - 203: "Non-Authoritative Information", - 204: "No Content", - 205: "Reset Content", - 206: "Partial Content", - 207: "Multi-Status", - 300: "Multiple Choice", - 301: "Moved Permanently", - 302: "Found", - 303: "See Other", - 304: "Not Modified", - 305: "Use Proxy", - 307: "Temporary Redirect", - 400: "Bad Request", - 401: "Unauthorized", - 402: "Payment Required", - 403: "Forbidden", - 404: "Not Found", - 405: "Method Not Allowed", - 406: "Not Acceptable", - 407: "Proxy Authentication Required", - 408: "Request Timeout", - 409: "Conflict", - 410: "Gone", - 411: "Length Required", - 412: "Precondition Failed", - 413: "Request Entity Too Large", - 414: "Request-URI Too Long", - 415: "Unsupported Media Type", - 416: "Requested Range Not Satisfiable", - 417: "Expectation Failed", - 422: "Unprocessable Entity", - 500: "Internal Server Error", - 501: "Not Implemented", - 502: "Bad Gateway", - 503: "Service Unavailable", - 504: "Gateway Timeout", - 505: "HTTP Version Not Supported" - }; + if (isAMD) { + define(loadDependencies); + } else if (isNode) { + loadDependencies(require, module.exports, module, require("lolex")); + } else { + makeApi(sinon); // eslint-disable-line no-undef + } +}()); - function makeApi(sinon) { - sinon.xhr = sinonXhr; +},{"./core":32,"lolex":12}],37:[function(require,module,exports){ +(function (global){ +/** + * @depend core.js + * @depend ../extend.js + * @depend event.js + * @depend ../log_error.js + */ +/** + * Fake XDomainRequest object + */ - sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, { - async: true, +/** + * Returns the global to prevent assigning values to 'this' when this is undefined. + * This can occur when files are interpreted by node in strict mode. + * @private + */ +function getGlobal() { + "use strict"; - open: function open(method, url, async, username, password) { - this.method = method; - this.url = url; - this.async = typeof async === "boolean" ? async : true; - this.username = username; - this.password = password; - clearResponse(this); - this.requestHeaders = {}; - this.sendFlag = false; + return typeof window !== "undefined" ? window : global; +} - if (FakeXMLHttpRequest.useFilters === true) { - var xhrArgs = arguments; - var defake = some(FakeXMLHttpRequest.filters, function (filter) { - return filter.apply(this, xhrArgs); - }); - if (defake) { - return FakeXMLHttpRequest.defake(this, arguments); - } - } - this.readyStateChange(FakeXMLHttpRequest.OPENED); - }, +if (typeof sinon === "undefined") { + if (typeof this === "undefined") { + getGlobal().sinon = {}; + } else { + this.sinon = {}; + } +} - readyStateChange: function readyStateChange(state) { - this.readyState = state; +// wrapper for global +(function (global) { + "use strict"; - var readyStateChangeEvent = new sinon.Event("readystatechange", false, false, this); - var event, progress; + var xdr = { XDomainRequest: global.XDomainRequest }; + xdr.GlobalXDomainRequest = global.XDomainRequest; + xdr.supportsXDR = typeof xdr.GlobalXDomainRequest !== "undefined"; + xdr.workingXDR = xdr.supportsXDR ? xdr.GlobalXDomainRequest : false; - if (typeof this.onreadystatechange === "function") { - try { - this.onreadystatechange(readyStateChangeEvent); - } catch (e) { - sinon.logError("Fake XHR onreadystatechange handler", e); - } - } + function makeApi(sinon) { + sinon.xdr = xdr; - if (this.readyState === FakeXMLHttpRequest.DONE) { - // ensure loaded and total are numbers - progress = { - loaded: this.progress || 0, - total: this.progress || 0 - }; + function FakeXDomainRequest() { + this.readyState = FakeXDomainRequest.UNSENT; + this.requestBody = null; + this.requestHeaders = {}; + this.status = 0; + this.timeout = null; - if (this.status === 0) { - event = this.aborted ? "abort" : "error"; - } - else { - event = "load"; - } + if (typeof FakeXDomainRequest.onCreate === "function") { + FakeXDomainRequest.onCreate(this); + } + } - if (supportsProgress) { - this.upload.dispatchEvent(new sinon.ProgressEvent("progress", progress, this)); - this.upload.dispatchEvent(new sinon.ProgressEvent(event, progress, this)); - this.upload.dispatchEvent(new sinon.ProgressEvent("loadend", progress, this)); - } + function verifyState(x) { + if (x.readyState !== FakeXDomainRequest.OPENED) { + throw new Error("INVALID_STATE_ERR"); + } - this.dispatchEvent(new sinon.ProgressEvent("progress", progress, this)); - this.dispatchEvent(new sinon.ProgressEvent(event, progress, this)); - this.dispatchEvent(new sinon.ProgressEvent("loadend", progress, this)); - } + if (x.sendFlag) { + throw new Error("INVALID_STATE_ERR"); + } + } - this.dispatchEvent(readyStateChangeEvent); - }, + function verifyRequestSent(x) { + if (x.readyState === FakeXDomainRequest.UNSENT) { + throw new Error("Request not sent"); + } + if (x.readyState === FakeXDomainRequest.DONE) { + throw new Error("Request done"); + } + } - setRequestHeader: function setRequestHeader(header, value) { - verifyState(this); + function verifyResponseBodyType(body) { + if (typeof body !== "string") { + var error = new Error("Attempted to respond to fake XDomainRequest with " + + body + ", which is not a string."); + error.name = "InvalidBodyException"; + throw error; + } + } - if (unsafeHeaders[header] || /^(Sec-|Proxy-)/.test(header)) { - throw new Error("Refused to set unsafe header \"" + header + "\""); - } + sinon.extend(FakeXDomainRequest.prototype, sinon.EventTarget, { + open: function open(method, url) { + this.method = method; + this.url = url; - if (this.requestHeaders[header]) { - this.requestHeaders[header] += "," + value; - } else { - this.requestHeaders[header] = value; - } - }, + this.responseText = null; + this.sendFlag = false; - // Helps testing - setResponseHeaders: function setResponseHeaders(headers) { - verifyRequestOpened(this); - this.responseHeaders = {}; + this.readyStateChange(FakeXDomainRequest.OPENED); + }, - for (var header in headers) { - if (headers.hasOwnProperty(header)) { - this.responseHeaders[header] = headers[header]; + readyStateChange: function readyStateChange(state) { + this.readyState = state; + var eventName = ""; + switch (this.readyState) { + case FakeXDomainRequest.UNSENT: + break; + case FakeXDomainRequest.OPENED: + break; + case FakeXDomainRequest.LOADING: + if (this.sendFlag) { + //raise the progress event + eventName = "onprogress"; + } + break; + case FakeXDomainRequest.DONE: + if (this.isTimeout) { + eventName = "ontimeout"; + } else if (this.errorFlag || (this.status < 200 || this.status > 299)) { + eventName = "onerror"; + } else { + eventName = "onload"; } + break; } - if (this.async) { - this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED); - } else { - this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED; + // raising event (if defined) + if (eventName) { + if (typeof this[eventName] === "function") { + try { + this[eventName](); + } catch (e) { + sinon.logError("Fake XHR " + eventName + " handler", e); + } + } } }, - // Currently treats ALL data as a DOMString (i.e. no Document) send: function send(data) { verifyState(this); if (!/^(get|head)$/i.test(this.method)) { - var contentType = getHeader(this.requestHeaders, "Content-Type"); - if (this.requestHeaders[contentType]) { - var value = this.requestHeaders[contentType].split(";"); - this.requestHeaders[contentType] = value[0] + ";charset=utf-8"; - } else if (supportsFormData && !(data instanceof FormData)) { - this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8"; - } - this.requestBody = data; } + this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8"; this.errorFlag = false; - this.sendFlag = this.async; - clearResponse(this); - this.readyStateChange(FakeXMLHttpRequest.OPENED); + this.sendFlag = true; + this.readyStateChange(FakeXDomainRequest.OPENED); if (typeof this.onSend === "function") { this.onSend(this); } - - this.dispatchEvent(new sinon.Event("loadstart", false, false, this)); }, abort: function abort() { this.aborted = true; - clearResponse(this); - this.errorFlag = true; - this.requestHeaders = {}; - this.responseHeaders = {}; - - if (this.readyState > FakeXMLHttpRequest.UNSENT && this.sendFlag) { - this.readyStateChange(FakeXMLHttpRequest.DONE); - this.sendFlag = false; - } - - this.readyState = FakeXMLHttpRequest.UNSENT; - }, - - error: function error() { - clearResponse(this); + this.responseText = null; this.errorFlag = true; - this.requestHeaders = {}; - this.responseHeaders = {}; - - this.readyStateChange(FakeXMLHttpRequest.DONE); - }, - - getResponseHeader: function getResponseHeader(header) { - if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { - return null; - } - - if (/^Set-Cookie2?$/i.test(header)) { - return null; - } - - header = getHeader(this.responseHeaders, header); - - return this.responseHeaders[header] || null; - }, - - getAllResponseHeaders: function getAllResponseHeaders() { - if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { - return ""; - } - - var headers = ""; - for (var header in this.responseHeaders) { - if (this.responseHeaders.hasOwnProperty(header) && - !/^Set-Cookie2?$/i.test(header)) { - headers += header + ": " + this.responseHeaders[header] + "\r\n"; - } + if (this.readyState > sinon.FakeXDomainRequest.UNSENT && this.sendFlag) { + this.readyStateChange(sinon.FakeXDomainRequest.DONE); + this.sendFlag = false; } - - return headers; }, setResponseBody: function setResponseBody(body) { verifyRequestSent(this); - verifyHeadersReceived(this); verifyResponseBodyType(body); - var contentType = this.getResponseHeader("Content-Type"); - - var isTextResponse = this.responseType === "" || this.responseType === "text"; - clearResponse(this); - if (this.async) { - var chunkSize = this.chunkSize || 10; - var index = 0; - - do { - this.readyStateChange(FakeXMLHttpRequest.LOADING); - if (isTextResponse) { - this.responseText = this.response += body.substring(index, index + chunkSize); - } - index += chunkSize; - } while (index < body.length); - } + var chunkSize = this.chunkSize || 10; + var index = 0; + this.responseText = ""; - this.response = convertResponseBody(this.responseType, contentType, body); - if (isTextResponse) { - this.responseText = this.response; - } + do { + this.readyStateChange(FakeXDomainRequest.LOADING); + this.responseText += body.substring(index, index + chunkSize); + index += chunkSize; + } while (index < body.length); - if (this.responseType === "document") { - this.responseXML = this.response; - } else if (this.responseType === "" && isXmlContentType(contentType)) { - this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText); - } - this.progress = body.length; - this.readyStateChange(FakeXMLHttpRequest.DONE); + this.readyStateChange(FakeXDomainRequest.DONE); }, - respond: function respond(status, headers, body) { + respond: function respond(status, contentType, body) { + // content-type ignored, since XDomainRequest does not carry this + // we keep the same syntax for respond(...) as for FakeXMLHttpRequest to ease + // test integration across browsers this.status = typeof status === "number" ? status : 200; - this.statusText = FakeXMLHttpRequest.statusCodes[this.status]; - this.setResponseHeaders(headers || {}); this.setResponseBody(body || ""); }, - uploadProgress: function uploadProgress(progressEventRaw) { - if (supportsProgress) { - this.upload.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw)); - } - }, - - downloadProgress: function downloadProgress(progressEventRaw) { - if (supportsProgress) { - this.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw)); - } - }, - - uploadError: function uploadError(error) { - if (supportsCustomEvent) { - this.upload.dispatchEvent(new sinon.CustomEvent("error", {detail: error})); - } + simulatetimeout: function simulatetimeout() { + this.status = 0; + this.isTimeout = true; + // Access to this should actually throw an error + this.responseText = undefined; + this.readyStateChange(FakeXDomainRequest.DONE); } }); - sinon.extend(FakeXMLHttpRequest, { + sinon.extend(FakeXDomainRequest, { UNSENT: 0, OPENED: 1, - HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4 }); - sinon.useFakeXMLHttpRequest = function () { - FakeXMLHttpRequest.restore = function restore(keepOnCreate) { - if (sinonXhr.supportsXHR) { - global.XMLHttpRequest = sinonXhr.GlobalXMLHttpRequest; - } - - if (sinonXhr.supportsActiveX) { - global.ActiveXObject = sinonXhr.GlobalActiveXObject; + sinon.useFakeXDomainRequest = function useFakeXDomainRequest() { + sinon.FakeXDomainRequest.restore = function restore(keepOnCreate) { + if (xdr.supportsXDR) { + global.XDomainRequest = xdr.GlobalXDomainRequest; } - delete FakeXMLHttpRequest.restore; + delete sinon.FakeXDomainRequest.restore; if (keepOnCreate !== true) { - delete FakeXMLHttpRequest.onCreate; + delete sinon.FakeXDomainRequest.onCreate; } }; - if (sinonXhr.supportsXHR) { - global.XMLHttpRequest = FakeXMLHttpRequest; - } - - if (sinonXhr.supportsActiveX) { - global.ActiveXObject = function ActiveXObject(objId) { - if (objId === "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) { - - return new FakeXMLHttpRequest(); - } - - return new sinonXhr.GlobalActiveXObject(objId); - }; + if (xdr.supportsXDR) { + global.XDomainRequest = sinon.FakeXDomainRequest; } - - return FakeXMLHttpRequest; + return sinon.FakeXDomainRequest; }; - sinon.FakeXMLHttpRequest = FakeXMLHttpRequest; + sinon.FakeXDomainRequest = FakeXDomainRequest; } var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; @@ -7020,1246 +6531,1436 @@ if (typeof sinon === "undefined") { if (isAMD) { define(loadDependencies); - return; - } - - if (isNode) { + } else if (isNode) { loadDependencies(require, module.exports, module); - return; - } - - if (sinonGlobal) { - makeApi(sinonGlobal); + } else { + makeApi(sinon); // eslint-disable-line no-undef } -}( - typeof sinon === "object" && sinon, // eslint-disable-line no-undef - typeof global !== "undefined" ? global : self -)); +})(typeof global !== "undefined" ? global : self); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../extend":19,"../log_error":21,"./core":31,"./event":32}],38:[function(require,module,exports){ +},{"../extend":20,"../log_error":22,"./core":32,"./event":33}],38:[function(require,module,exports){ +(function (global){ /** - * @depend util/core.js + * @depend core.js + * @depend ../extend.js + * @depend event.js + * @depend ../log_error.js */ -(function (sinonGlobal) { +/** + * Fake XMLHttpRequest object + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +(function (sinonGlobal, global) { "use strict"; - function makeApi(sinon) { - function walkInternal(obj, iterator, context, originalObj, seen) { - var proto, prop; - - if (typeof Object.getOwnPropertyNames !== "function") { - // We explicitly want to enumerate through all of the prototype's properties - // in this case, therefore we deliberately leave out an own property check. - /* eslint-disable guard-for-in */ - for (prop in obj) { - iterator.call(context, obj[prop], prop, obj); - } - /* eslint-enable guard-for-in */ - - return; - } - - Object.getOwnPropertyNames(obj).forEach(function (k) { - if (!seen[k]) { - seen[k] = true; - var target = typeof Object.getOwnPropertyDescriptor(obj, k).get === "function" ? - originalObj : obj; - iterator.call(context, target[k], k, target); - } - }); - - proto = Object.getPrototypeOf(obj); - if (proto) { - walkInternal(proto, iterator, context, originalObj, seen); - } + function getWorkingXHR(globalScope) { + var supportsXHR = typeof globalScope.XMLHttpRequest !== "undefined"; + if (supportsXHR) { + return globalScope.XMLHttpRequest; } - /* Public: walks the prototype chain of an object and iterates over every own property - * name encountered. The iterator is called in the same fashion that Array.prototype.forEach - * works, where it is passed the value, key, and own object as the 1st, 2nd, and 3rd positional - * argument, respectively. In cases where Object.getOwnPropertyNames is not available, walk will - * default to using a simple for..in loop. - * - * obj - The object to walk the prototype chain for. - * iterator - The function to be called on each pass of the walk. - * context - (Optional) When given, the iterator will be called with this object as the receiver. - */ - function walk(obj, iterator, context) { - return walkInternal(obj, iterator, context, obj, {}); + var supportsActiveX = typeof globalScope.ActiveXObject !== "undefined"; + if (supportsActiveX) { + return function () { + return new globalScope.ActiveXObject("MSXML2.XMLHTTP.3.0"); + }; } - sinon.walk = walk; - return sinon.walk; - } - - function loadDependencies(require, exports, module) { - var sinon = require("./util/core"); - module.exports = makeApi(sinon); + return false; } - var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; - var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; + var supportsProgress = typeof ProgressEvent !== "undefined"; + var supportsCustomEvent = typeof CustomEvent !== "undefined"; + var supportsFormData = typeof FormData !== "undefined"; + var supportsArrayBuffer = typeof ArrayBuffer !== "undefined"; + var supportsBlob = (function () { + try { + return !!new Blob(); + } catch (e) { + return false; + } + })(); + var sinonXhr = { XMLHttpRequest: global.XMLHttpRequest }; + sinonXhr.GlobalXMLHttpRequest = global.XMLHttpRequest; + sinonXhr.GlobalActiveXObject = global.ActiveXObject; + sinonXhr.supportsActiveX = typeof sinonXhr.GlobalActiveXObject !== "undefined"; + sinonXhr.supportsXHR = typeof sinonXhr.GlobalXMLHttpRequest !== "undefined"; + sinonXhr.workingXHR = getWorkingXHR(global); + sinonXhr.supportsCORS = sinonXhr.supportsXHR && "withCredentials" in (new sinonXhr.GlobalXMLHttpRequest()); - if (isAMD) { - define(loadDependencies); - return; - } + var unsafeHeaders = { + "Accept-Charset": true, + "Accept-Encoding": true, + Connection: true, + "Content-Length": true, + Cookie: true, + Cookie2: true, + "Content-Transfer-Encoding": true, + Date: true, + Expect: true, + Host: true, + "Keep-Alive": true, + Referer: true, + TE: true, + Trailer: true, + "Transfer-Encoding": true, + Upgrade: true, + "User-Agent": true, + Via: true + }; - if (isNode) { - loadDependencies(require, module.exports, module); - return; + // An upload object is created for each + // FakeXMLHttpRequest and allows upload + // events to be simulated using uploadProgress + // and uploadError. + function UploadProgress() { + this.eventListeners = { + abort: [], + error: [], + load: [], + loadend: [], + progress: [] + }; } - if (sinonGlobal) { - makeApi(sinonGlobal); - } -}( - typeof sinon === "object" && sinon // eslint-disable-line no-undef -)); + UploadProgress.prototype.addEventListener = function addEventListener(event, listener) { + this.eventListeners[event].push(listener); + }; -},{"./util/core":31}],39:[function(require,module,exports){ -(function (global){ -((typeof define === "function" && define.amd && function (m) { - define("formatio", ["samsam"], m); -}) || (typeof module === "object" && function (m) { - module.exports = m(require("samsam")); -}) || function (m) { this.formatio = m(this.samsam); } -)(function (samsam) { - "use strict"; + UploadProgress.prototype.removeEventListener = function removeEventListener(event, listener) { + var listeners = this.eventListeners[event] || []; - var formatio = { - excludeConstructors: ["Object", /^.$/], - quoteStrings: true, - limitChildrenCount: 0 + for (var i = 0, l = listeners.length; i < l; ++i) { + if (listeners[i] === listener) { + return listeners.splice(i, 1); + } + } }; - var hasOwn = Object.prototype.hasOwnProperty; + UploadProgress.prototype.dispatchEvent = function dispatchEvent(event) { + var listeners = this.eventListeners[event.type] || []; - var specialObjects = []; - if (typeof global !== "undefined") { - specialObjects.push({ object: global, value: "[object global]" }); - } - if (typeof document !== "undefined") { - specialObjects.push({ - object: document, - value: "[object HTMLDocument]" - }); - } - if (typeof window !== "undefined") { - specialObjects.push({ object: window, value: "[object Window]" }); - } + for (var i = 0, listener; (listener = listeners[i]) != null; i++) { + listener(event); + } + }; - function functionName(func) { - if (!func) { return ""; } - if (func.displayName) { return func.displayName; } - if (func.name) { return func.name; } - var matches = func.toString().match(/function\s+([^\(]+)/m); - return (matches && matches[1]) || ""; - } + // Note that for FakeXMLHttpRequest to work pre ES5 + // we lose some of the alignment with the spec. + // To ensure as close a match as possible, + // set responseType before calling open, send or respond; + function FakeXMLHttpRequest() { + this.readyState = FakeXMLHttpRequest.UNSENT; + this.requestHeaders = {}; + this.requestBody = null; + this.status = 0; + this.statusText = ""; + this.upload = new UploadProgress(); + this.responseType = ""; + this.response = ""; + if (sinonXhr.supportsCORS) { + this.withCredentials = false; + } - function constructorName(f, object) { - var name = functionName(object && object.constructor); - var excludes = f.excludeConstructors || - formatio.excludeConstructors || []; + var xhr = this; + var events = ["loadstart", "load", "abort", "error", "loadend"]; - var i, l; - for (i = 0, l = excludes.length; i < l; ++i) { - if (typeof excludes[i] === "string" && excludes[i] === name) { - return ""; - } else if (excludes[i].test && excludes[i].test(name)) { - return ""; - } + function addEventListener(eventName) { + xhr.addEventListener(eventName, function (event) { + var listener = xhr["on" + eventName]; + + if (listener && typeof listener === "function") { + listener.call(this, event); + } + }); } - return name; - } + for (var i = events.length - 1; i >= 0; i--) { + addEventListener(events[i]); + } - function isCircular(object, objects) { - if (typeof object !== "object") { return false; } - var i, l; - for (i = 0, l = objects.length; i < l; ++i) { - if (objects[i] === object) { return true; } + if (typeof FakeXMLHttpRequest.onCreate === "function") { + FakeXMLHttpRequest.onCreate(this); } - return false; } - function ascii(f, object, processed, indent) { - if (typeof object === "string") { - var qs = f.quoteStrings; - var quote = typeof qs !== "boolean" || qs; - return processed || quote ? '"' + object + '"' : object; + function verifyState(xhr) { + if (xhr.readyState !== FakeXMLHttpRequest.OPENED) { + throw new Error("INVALID_STATE_ERR"); } - if (typeof object === "function" && !(object instanceof RegExp)) { - return ascii.func(object); + if (xhr.sendFlag) { + throw new Error("INVALID_STATE_ERR"); } + } - processed = processed || []; - - if (isCircular(object, processed)) { return "[Circular]"; } + function getHeader(headers, header) { + header = header.toLowerCase(); - if (Object.prototype.toString.call(object) === "[object Array]") { - return ascii.array.call(f, object, processed); + for (var h in headers) { + if (h.toLowerCase() === header) { + return h; + } } - if (!object) { return String((1/object) === -Infinity ? "-0" : object); } - if (samsam.isElement(object)) { return ascii.element(object); } + return null; + } - if (typeof object.toString === "function" && - object.toString !== Object.prototype.toString) { - return object.toString(); + // filtering to enable a white-list version of Sinon FakeXhr, + // where whitelisted requests are passed through to real XHR + function each(collection, callback) { + if (!collection) { + return; } - var i, l; - for (i = 0, l = specialObjects.length; i < l; i++) { - if (object === specialObjects[i].object) { - return specialObjects[i].value; + for (var i = 0, l = collection.length; i < l; i += 1) { + callback(collection[i]); + } + } + function some(collection, callback) { + for (var index = 0; index < collection.length; index++) { + if (callback(collection[index]) === true) { + return true; } } - - return ascii.object.call(f, object, processed, indent); + return false; } - - ascii.func = function (func) { - return "function " + functionName(func) + "() {}"; + // largest arity in XHR is 5 - XHR#open + var apply = function (obj, method, args) { + switch (args.length) { + case 0: return obj[method](); + case 1: return obj[method](args[0]); + case 2: return obj[method](args[0], args[1]); + case 3: return obj[method](args[0], args[1], args[2]); + case 4: return obj[method](args[0], args[1], args[2], args[3]); + case 5: return obj[method](args[0], args[1], args[2], args[3], args[4]); + } }; - ascii.array = function (array, processed) { - processed = processed || []; - processed.push(array); - var pieces = []; - var i, l; - l = (this.limitChildrenCount > 0) ? - Math.min(this.limitChildrenCount, array.length) : array.length; - - for (i = 0; i < l; ++i) { - pieces.push(ascii(this, array[i], processed)); - } + FakeXMLHttpRequest.filters = []; + FakeXMLHttpRequest.addFilter = function addFilter(fn) { + this.filters.push(fn); + }; + var IE6Re = /MSIE 6/; + FakeXMLHttpRequest.defake = function defake(fakeXhr, xhrArgs) { + var xhr = new sinonXhr.workingXHR(); // eslint-disable-line new-cap - if(l < array.length) - pieces.push("[... " + (array.length - l) + " more elements]"); + each([ + "open", + "setRequestHeader", + "send", + "abort", + "getResponseHeader", + "getAllResponseHeaders", + "addEventListener", + "overrideMimeType", + "removeEventListener" + ], function (method) { + fakeXhr[method] = function () { + return apply(xhr, method, arguments); + }; + }); - return "[" + pieces.join(", ") + "]"; - }; + var copyAttrs = function (args) { + each(args, function (attr) { + try { + fakeXhr[attr] = xhr[attr]; + } catch (e) { + if (!IE6Re.test(navigator.userAgent)) { + throw e; + } + } + }); + }; - ascii.object = function (object, processed, indent) { - processed = processed || []; - processed.push(object); - indent = indent || 0; - var pieces = [], properties = samsam.keys(object).sort(); - var length = 3; - var prop, str, obj, i, k, l; - l = (this.limitChildrenCount > 0) ? - Math.min(this.limitChildrenCount, properties.length) : properties.length; + var stateChange = function stateChange() { + fakeXhr.readyState = xhr.readyState; + if (xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) { + copyAttrs(["status", "statusText"]); + } + if (xhr.readyState >= FakeXMLHttpRequest.LOADING) { + copyAttrs(["responseText", "response"]); + } + if (xhr.readyState === FakeXMLHttpRequest.DONE) { + copyAttrs(["responseXML"]); + } + if (fakeXhr.onreadystatechange) { + fakeXhr.onreadystatechange.call(fakeXhr, { target: fakeXhr }); + } + }; - for (i = 0; i < l; ++i) { - prop = properties[i]; - obj = object[prop]; + if (xhr.addEventListener) { + for (var event in fakeXhr.eventListeners) { + if (fakeXhr.eventListeners.hasOwnProperty(event)) { - if (isCircular(obj, processed)) { - str = "[Circular]"; - } else { - str = ascii(this, obj, processed, indent + 2); + /*eslint-disable no-loop-func*/ + each(fakeXhr.eventListeners[event], function (handler) { + xhr.addEventListener(event, handler); + }); + /*eslint-enable no-loop-func*/ + } } - - str = (/\s/.test(prop) ? '"' + prop + '"' : prop) + ": " + str; - length += str.length; - pieces.push(str); + xhr.addEventListener("readystatechange", stateChange); + } else { + xhr.onreadystatechange = stateChange; } + apply(xhr, "open", xhrArgs); + }; + FakeXMLHttpRequest.useFilters = false; - var cons = constructorName(this, object); - var prefix = cons ? "[" + cons + "] " : ""; - var is = ""; - for (i = 0, k = indent; i < k; ++i) { is += " "; } + function verifyRequestOpened(xhr) { + if (xhr.readyState !== FakeXMLHttpRequest.OPENED) { + throw new Error("INVALID_STATE_ERR - " + xhr.readyState); + } + } - if(l < properties.length) - pieces.push("[... " + (properties.length - l) + " more elements]"); + function verifyRequestSent(xhr) { + if (xhr.readyState === FakeXMLHttpRequest.DONE) { + throw new Error("Request done"); + } + } - if (length + indent > 80) { - return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" + - is + "}"; + function verifyHeadersReceived(xhr) { + if (xhr.async && xhr.readyState !== FakeXMLHttpRequest.HEADERS_RECEIVED) { + throw new Error("No headers received"); } - return prefix + "{ " + pieces.join(", ") + " }"; - }; + } - ascii.element = function (element) { - var tagName = element.tagName.toLowerCase(); - var attrs = element.attributes, attr, pairs = [], attrName, i, l, val; + function verifyResponseBodyType(body) { + if (typeof body !== "string") { + var error = new Error("Attempted to respond to fake XMLHttpRequest with " + + body + ", which is not a string."); + error.name = "InvalidBodyException"; + throw error; + } + } - for (i = 0, l = attrs.length; i < l; ++i) { - attr = attrs.item(i); - attrName = attr.nodeName.toLowerCase().replace("html:", ""); - val = attr.nodeValue; - if (attrName !== "contenteditable" || val !== "inherit") { - if (!!val) { pairs.push(attrName + "=\"" + val + "\""); } + function convertToArrayBuffer(body) { + var buffer = new ArrayBuffer(body.length); + var view = new Uint8Array(buffer); + for (var i = 0; i < body.length; i++) { + var charCode = body.charCodeAt(i); + if (charCode >= 256) { + throw new TypeError("arraybuffer or blob responseTypes require binary string, " + + "invalid character " + body[i] + " found."); } + view[i] = charCode; } + return buffer; + } - var formatted = "<" + tagName + (pairs.length > 0 ? " " : ""); - var content = element.innerHTML; + function isXmlContentType(contentType) { + return !contentType || /(text\/xml)|(application\/xml)|(\+xml)/.test(contentType); + } - if (content.length > 20) { - content = content.substr(0, 20) + "[...]"; + function convertResponseBody(responseType, contentType, body) { + if (responseType === "" || responseType === "text") { + return body; + } else if (supportsArrayBuffer && responseType === "arraybuffer") { + return convertToArrayBuffer(body); + } else if (responseType === "json") { + try { + return JSON.parse(body); + } catch (e) { + // Return parsing failure as null + return null; + } + } else if (supportsBlob && responseType === "blob") { + var blobOptions = {}; + if (contentType) { + blobOptions.type = contentType; + } + return new Blob([convertToArrayBuffer(body)], blobOptions); + } else if (responseType === "document") { + if (isXmlContentType(contentType)) { + return FakeXMLHttpRequest.parseXML(body); + } + return null; } + throw new Error("Invalid responseType " + responseType); + } - var res = formatted + pairs.join(" ") + ">" + content + - ""; + function clearResponse(xhr) { + if (xhr.responseType === "" || xhr.responseType === "text") { + xhr.response = xhr.responseText = ""; + } else { + xhr.response = xhr.responseText = null; + } + xhr.responseXML = null; + } - return res.replace(/ contentEditable="inherit"/, ""); + FakeXMLHttpRequest.parseXML = function parseXML(text) { + // Treat empty string as parsing failure + if (text !== "") { + try { + if (typeof DOMParser !== "undefined") { + var parser = new DOMParser(); + return parser.parseFromString(text, "text/xml"); + } + var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM"); + xmlDoc.async = "false"; + xmlDoc.loadXML(text); + return xmlDoc; + } catch (e) { + // Unable to parse XML - no biggie + } + } + + return null; }; - function Formatio(options) { - for (var opt in options) { - this[opt] = options[opt]; - } - } + FakeXMLHttpRequest.statusCodes = { + 100: "Continue", + 101: "Switching Protocols", + 200: "OK", + 201: "Created", + 202: "Accepted", + 203: "Non-Authoritative Information", + 204: "No Content", + 205: "Reset Content", + 206: "Partial Content", + 207: "Multi-Status", + 300: "Multiple Choice", + 301: "Moved Permanently", + 302: "Found", + 303: "See Other", + 304: "Not Modified", + 305: "Use Proxy", + 307: "Temporary Redirect", + 400: "Bad Request", + 401: "Unauthorized", + 402: "Payment Required", + 403: "Forbidden", + 404: "Not Found", + 405: "Method Not Allowed", + 406: "Not Acceptable", + 407: "Proxy Authentication Required", + 408: "Request Timeout", + 409: "Conflict", + 410: "Gone", + 411: "Length Required", + 412: "Precondition Failed", + 413: "Request Entity Too Large", + 414: "Request-URI Too Long", + 415: "Unsupported Media Type", + 416: "Requested Range Not Satisfiable", + 417: "Expectation Failed", + 422: "Unprocessable Entity", + 500: "Internal Server Error", + 501: "Not Implemented", + 502: "Bad Gateway", + 503: "Service Unavailable", + 504: "Gateway Timeout", + 505: "HTTP Version Not Supported" + }; - Formatio.prototype = { - functionName: functionName, + function makeApi(sinon) { + sinon.xhr = sinonXhr; - configure: function (options) { - return new Formatio(options); - }, + sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, { + async: true, - constructorName: function (object) { - return constructorName(this, object); - }, + open: function open(method, url, async, username, password) { + this.method = method; + this.url = url; + this.async = typeof async === "boolean" ? async : true; + this.username = username; + this.password = password; + clearResponse(this); + this.requestHeaders = {}; + this.sendFlag = false; - ascii: function (object, processed, indent) { - return ascii(this, object, processed, indent); - } - }; + if (FakeXMLHttpRequest.useFilters === true) { + var xhrArgs = arguments; + var defake = some(FakeXMLHttpRequest.filters, function (filter) { + return filter.apply(this, xhrArgs); + }); + if (defake) { + return FakeXMLHttpRequest.defake(this, arguments); + } + } + this.readyStateChange(FakeXMLHttpRequest.OPENED); + }, - return Formatio.prototype; -}); + readyStateChange: function readyStateChange(state) { + this.readyState = state; -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"samsam":41}],40:[function(require,module,exports){ -(function (global){ -/*global global, window*/ -/** - * @author Christian Johansen (christian@cjohansen.no) and contributors - * @license BSD - * - * Copyright (c) 2010-2014 Christian Johansen - */ + var readyStateChangeEvent = new sinon.Event("readystatechange", false, false, this); + var event, progress; -(function (global) { - "use strict"; + if (typeof this.onreadystatechange === "function") { + try { + this.onreadystatechange(readyStateChangeEvent); + } catch (e) { + sinon.logError("Fake XHR onreadystatechange handler", e); + } + } - // Make properties writable in IE, as per - // http://www.adequatelygood.com/Replacing-setTimeout-Globally.html - // JSLint being anal - var glbl = global; + if (this.readyState === FakeXMLHttpRequest.DONE) { + // ensure loaded and total are numbers + progress = { + loaded: this.progress || 0, + total: this.progress || 0 + }; - global.setTimeout = glbl.setTimeout; - global.clearTimeout = glbl.clearTimeout; - global.setInterval = glbl.setInterval; - global.clearInterval = glbl.clearInterval; - global.Date = glbl.Date; + if (this.status === 0) { + event = this.aborted ? "abort" : "error"; + } + else { + event = "load"; + } - // setImmediate is not a standard function - // avoid adding the prop to the window object if not present - if('setImmediate' in global) { - global.setImmediate = glbl.setImmediate; - global.clearImmediate = glbl.clearImmediate; - } + if (supportsProgress) { + this.upload.dispatchEvent(new sinon.ProgressEvent("progress", progress, this)); + this.upload.dispatchEvent(new sinon.ProgressEvent(event, progress, this)); + this.upload.dispatchEvent(new sinon.ProgressEvent("loadend", progress, this)); + } - // node expects setTimeout/setInterval to return a fn object w/ .ref()/.unref() - // browsers, a number. - // see https://github.com/cjohansen/Sinon.JS/pull/436 + this.dispatchEvent(new sinon.ProgressEvent("progress", progress, this)); + this.dispatchEvent(new sinon.ProgressEvent(event, progress, this)); + this.dispatchEvent(new sinon.ProgressEvent("loadend", progress, this)); + } - var NOOP = function () { return undefined; }; - var timeoutResult = setTimeout(NOOP, 0); - var addTimerReturnsObject = typeof timeoutResult === "object"; - clearTimeout(timeoutResult); + this.dispatchEvent(readyStateChangeEvent); + }, - var NativeDate = Date; - var uniqueTimerId = 1; + setRequestHeader: function setRequestHeader(header, value) { + verifyState(this); - /** - * Parse strings like "01:10:00" (meaning 1 hour, 10 minutes, 0 seconds) into - * number of milliseconds. This is used to support human-readable strings passed - * to clock.tick() - */ - function parseTime(str) { - if (!str) { - return 0; - } + if (unsafeHeaders[header] || /^(Sec-|Proxy-)/.test(header)) { + throw new Error("Refused to set unsafe header \"" + header + "\""); + } - var strings = str.split(":"); - var l = strings.length, i = l; - var ms = 0, parsed; + if (this.requestHeaders[header]) { + this.requestHeaders[header] += "," + value; + } else { + this.requestHeaders[header] = value; + } + }, - if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) { - throw new Error("tick only understands numbers and 'h:m:s'"); - } + // Helps testing + setResponseHeaders: function setResponseHeaders(headers) { + verifyRequestOpened(this); + this.responseHeaders = {}; - while (i--) { - parsed = parseInt(strings[i], 10); + for (var header in headers) { + if (headers.hasOwnProperty(header)) { + this.responseHeaders[header] = headers[header]; + } + } - if (parsed >= 60) { - throw new Error("Invalid time " + str); - } + if (this.async) { + this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED); + } else { + this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED; + } + }, - ms += parsed * Math.pow(60, (l - i - 1)); - } + // Currently treats ALL data as a DOMString (i.e. no Document) + send: function send(data) { + verifyState(this); - return ms * 1000; - } + if (!/^(get|head)$/i.test(this.method)) { + var contentType = getHeader(this.requestHeaders, "Content-Type"); + if (this.requestHeaders[contentType]) { + var value = this.requestHeaders[contentType].split(";"); + this.requestHeaders[contentType] = value[0] + ";charset=utf-8"; + } else if (supportsFormData && !(data instanceof FormData)) { + this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8"; + } - /** - * Used to grok the `now` parameter to createClock. - */ - function getEpoch(epoch) { - if (!epoch) { return 0; } - if (typeof epoch.getTime === "function") { return epoch.getTime(); } - if (typeof epoch === "number") { return epoch; } - throw new TypeError("now should be milliseconds since UNIX epoch"); - } + this.requestBody = data; + } - function inRange(from, to, timer) { - return timer && timer.callAt >= from && timer.callAt <= to; - } + this.errorFlag = false; + this.sendFlag = this.async; + clearResponse(this); + this.readyStateChange(FakeXMLHttpRequest.OPENED); - function mirrorDateProperties(target, source) { - var prop; - for (prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } + if (typeof this.onSend === "function") { + this.onSend(this); + } - // set special now implementation - if (source.now) { - target.now = function now() { - return target.clock.now; - }; - } else { - delete target.now; - } + this.dispatchEvent(new sinon.Event("loadstart", false, false, this)); + }, - // set special toSource implementation - if (source.toSource) { - target.toSource = function toSource() { - return source.toSource(); - }; - } else { - delete target.toSource; - } + abort: function abort() { + this.aborted = true; + clearResponse(this); + this.errorFlag = true; + this.requestHeaders = {}; + this.responseHeaders = {}; - // set special toString implementation - target.toString = function toString() { - return source.toString(); - }; + if (this.readyState > FakeXMLHttpRequest.UNSENT && this.sendFlag) { + this.readyStateChange(FakeXMLHttpRequest.DONE); + this.sendFlag = false; + } - target.prototype = source.prototype; - target.parse = source.parse; - target.UTC = source.UTC; - target.prototype.toUTCString = source.prototype.toUTCString; + this.readyState = FakeXMLHttpRequest.UNSENT; + }, - return target; - } + error: function error() { + clearResponse(this); + this.errorFlag = true; + this.requestHeaders = {}; + this.responseHeaders = {}; - function createDate() { - function ClockDate(year, month, date, hour, minute, second, ms) { - // Defensive and verbose to avoid potential harm in passing - // explicit undefined when user does not pass argument - switch (arguments.length) { - case 0: - return new NativeDate(ClockDate.clock.now); - case 1: - return new NativeDate(year); - case 2: - return new NativeDate(year, month); - case 3: - return new NativeDate(year, month, date); - case 4: - return new NativeDate(year, month, date, hour); - case 5: - return new NativeDate(year, month, date, hour, minute); - case 6: - return new NativeDate(year, month, date, hour, minute, second); - default: - return new NativeDate(year, month, date, hour, minute, second, ms); - } - } + this.readyStateChange(FakeXMLHttpRequest.DONE); + }, - return mirrorDateProperties(ClockDate, NativeDate); - } + getResponseHeader: function getResponseHeader(header) { + if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { + return null; + } - function addTimer(clock, timer) { - if (timer.func === undefined) { - throw new Error("Callback must be provided to timer calls"); - } + if (/^Set-Cookie2?$/i.test(header)) { + return null; + } - if (!clock.timers) { - clock.timers = {}; - } + header = getHeader(this.responseHeaders, header); - timer.id = uniqueTimerId++; - timer.createdAt = clock.now; - timer.callAt = clock.now + (timer.delay || (clock.duringTick ? 1 : 0)); + return this.responseHeaders[header] || null; + }, - clock.timers[timer.id] = timer; + getAllResponseHeaders: function getAllResponseHeaders() { + if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { + return ""; + } - if (addTimerReturnsObject) { - return { - id: timer.id, - ref: NOOP, - unref: NOOP - }; - } + var headers = ""; - return timer.id; - } + for (var header in this.responseHeaders) { + if (this.responseHeaders.hasOwnProperty(header) && + !/^Set-Cookie2?$/i.test(header)) { + headers += header + ": " + this.responseHeaders[header] + "\r\n"; + } + } + return headers; + }, - function compareTimers(a, b) { - // Sort first by absolute timing - if (a.callAt < b.callAt) { - return -1; - } - if (a.callAt > b.callAt) { - return 1; - } + setResponseBody: function setResponseBody(body) { + verifyRequestSent(this); + verifyHeadersReceived(this); + verifyResponseBodyType(body); + var contentType = this.getResponseHeader("Content-Type"); - // Sort next by immediate, immediate timers take precedence - if (a.immediate && !b.immediate) { - return -1; - } - if (!a.immediate && b.immediate) { - return 1; - } + var isTextResponse = this.responseType === "" || this.responseType === "text"; + clearResponse(this); + if (this.async) { + var chunkSize = this.chunkSize || 10; + var index = 0; - // Sort next by creation time, earlier-created timers take precedence - if (a.createdAt < b.createdAt) { - return -1; - } - if (a.createdAt > b.createdAt) { - return 1; - } + do { + this.readyStateChange(FakeXMLHttpRequest.LOADING); - // Sort next by id, lower-id timers take precedence - if (a.id < b.id) { - return -1; - } - if (a.id > b.id) { - return 1; - } + if (isTextResponse) { + this.responseText = this.response += body.substring(index, index + chunkSize); + } + index += chunkSize; + } while (index < body.length); + } - // As timer ids are unique, no fallback `0` is necessary - } + this.response = convertResponseBody(this.responseType, contentType, body); + if (isTextResponse) { + this.responseText = this.response; + } - function firstTimerInRange(clock, from, to) { - var timers = clock.timers, - timer = null, - id, - isInRange; + if (this.responseType === "document") { + this.responseXML = this.response; + } else if (this.responseType === "" && isXmlContentType(contentType)) { + this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText); + } + this.progress = body.length; + this.readyStateChange(FakeXMLHttpRequest.DONE); + }, - for (id in timers) { - if (timers.hasOwnProperty(id)) { - isInRange = inRange(from, to, timers[id]); + respond: function respond(status, headers, body) { + this.status = typeof status === "number" ? status : 200; + this.statusText = FakeXMLHttpRequest.statusCodes[this.status]; + this.setResponseHeaders(headers || {}); + this.setResponseBody(body || ""); + }, - if (isInRange && (!timer || compareTimers(timer, timers[id]) === 1)) { - timer = timers[id]; + uploadProgress: function uploadProgress(progressEventRaw) { + if (supportsProgress) { + this.upload.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw)); + } + }, + + downloadProgress: function downloadProgress(progressEventRaw) { + if (supportsProgress) { + this.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw)); + } + }, + + uploadError: function uploadError(error) { + if (supportsCustomEvent) { + this.upload.dispatchEvent(new sinon.CustomEvent("error", {detail: error})); } } - } + }); - return timer; - } + sinon.extend(FakeXMLHttpRequest, { + UNSENT: 0, + OPENED: 1, + HEADERS_RECEIVED: 2, + LOADING: 3, + DONE: 4 + }); - function callTimer(clock, timer) { - var exception; + sinon.useFakeXMLHttpRequest = function () { + FakeXMLHttpRequest.restore = function restore(keepOnCreate) { + if (sinonXhr.supportsXHR) { + global.XMLHttpRequest = sinonXhr.GlobalXMLHttpRequest; + } - if (typeof timer.interval === "number") { - clock.timers[timer.id].callAt += timer.interval; - } else { - delete clock.timers[timer.id]; - } + if (sinonXhr.supportsActiveX) { + global.ActiveXObject = sinonXhr.GlobalActiveXObject; + } - try { - if (typeof timer.func === "function") { - timer.func.apply(null, timer.args); - } else { - eval(timer.func); - } - } catch (e) { - exception = e; - } + delete FakeXMLHttpRequest.restore; - if (!clock.timers[timer.id]) { - if (exception) { - throw exception; + if (keepOnCreate !== true) { + delete FakeXMLHttpRequest.onCreate; + } + }; + if (sinonXhr.supportsXHR) { + global.XMLHttpRequest = FakeXMLHttpRequest; } - return; - } - - if (exception) { - throw exception; - } - } - function timerType(timer) { - if (timer.immediate) { - return "Immediate"; - } else if (typeof timer.interval !== "undefined") { - return "Interval"; - } else { - return "Timeout"; - } - } + if (sinonXhr.supportsActiveX) { + global.ActiveXObject = function ActiveXObject(objId) { + if (objId === "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) { - function clearTimer(clock, timerId, ttype) { - if (!timerId) { - // null appears to be allowed in most browsers, and appears to be - // relied upon by some libraries, like Bootstrap carousel - return; - } + return new FakeXMLHttpRequest(); + } - if (!clock.timers) { - clock.timers = []; - } + return new sinonXhr.GlobalActiveXObject(objId); + }; + } - // in Node, timerId is an object with .ref()/.unref(), and - // its .id field is the actual timer id. - if (typeof timerId === "object") { - timerId = timerId.id; - } + return FakeXMLHttpRequest; + }; - if (clock.timers.hasOwnProperty(timerId)) { - // check that the ID matches a timer of the correct type - var timer = clock.timers[timerId]; - if (timerType(timer) === ttype) { - delete clock.timers[timerId]; - } else { - throw new Error("Cannot clear timer: timer created with set" + ttype + "() but cleared with clear" + timerType(timer) + "()"); - } - } + sinon.FakeXMLHttpRequest = FakeXMLHttpRequest; } - function uninstall(clock, target) { - var method, - i, - l; + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - for (i = 0, l = clock.methods.length; i < l; i++) { - method = clock.methods[i]; + function loadDependencies(require, exports, module) { + var sinon = require("./core"); + require("../extend"); + require("./event"); + require("../log_error"); + makeApi(sinon); + module.exports = sinon; + } - if (target[method].hadOwnProperty) { - target[method] = clock["_" + method]; - } else { - try { - delete target[method]; - } catch (ignore) {} - } - } + if (isAMD) { + define(loadDependencies); + return; + } - // Prevent multiple executions which will completely remove these props - clock.methods = []; + if (isNode) { + loadDependencies(require, module.exports, module); + return; } - function hijackMethod(target, method, clock) { - var prop; + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon, // eslint-disable-line no-undef + typeof global !== "undefined" ? global : self +)); - clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(target, method); - clock["_" + method] = target[method]; +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../extend":20,"../log_error":22,"./core":32,"./event":33}],39:[function(require,module,exports){ +/** + * @depend util/core.js + */ +(function (sinonGlobal) { + "use strict"; - if (method === "Date") { - var date = mirrorDateProperties(clock[method], target[method]); - target[method] = date; - } else { - target[method] = function () { - return clock[method].apply(clock, arguments); - }; + function makeApi(sinon) { + function walkInternal(obj, iterator, context, originalObj, seen) { + var proto, prop; - for (prop in clock[method]) { - if (clock[method].hasOwnProperty(prop)) { - target[method][prop] = clock[method][prop]; + if (typeof Object.getOwnPropertyNames !== "function") { + // We explicitly want to enumerate through all of the prototype's properties + // in this case, therefore we deliberately leave out an own property check. + /* eslint-disable guard-for-in */ + for (prop in obj) { + iterator.call(context, obj[prop], prop, obj); + } + /* eslint-enable guard-for-in */ + + return; + } + + Object.getOwnPropertyNames(obj).forEach(function (k) { + if (!seen[k]) { + seen[k] = true; + var target = typeof Object.getOwnPropertyDescriptor(obj, k).get === "function" ? + originalObj : obj; + iterator.call(context, target[k], k, target); } + }); + + proto = Object.getPrototypeOf(obj); + if (proto) { + walkInternal(proto, iterator, context, originalObj, seen); } } - target[method].clock = clock; + /* Public: walks the prototype chain of an object and iterates over every own property + * name encountered. The iterator is called in the same fashion that Array.prototype.forEach + * works, where it is passed the value, key, and own object as the 1st, 2nd, and 3rd positional + * argument, respectively. In cases where Object.getOwnPropertyNames is not available, walk will + * default to using a simple for..in loop. + * + * obj - The object to walk the prototype chain for. + * iterator - The function to be called on each pass of the walk. + * context - (Optional) When given, the iterator will be called with this object as the receiver. + */ + function walk(obj, iterator, context) { + return walkInternal(obj, iterator, context, obj, {}); + } + + sinon.walk = walk; + return sinon.walk; } - var timers = { - setTimeout: setTimeout, - clearTimeout: clearTimeout, - setImmediate: global.setImmediate, - clearImmediate: global.clearImmediate, - setInterval: setInterval, - clearInterval: clearInterval, - Date: Date - }; - - var keys = Object.keys || function (obj) { - var ks = [], - key; + function loadDependencies(require, exports, module) { + var sinon = require("./util/core"); + module.exports = makeApi(sinon); + } - for (key in obj) { - if (obj.hasOwnProperty(key)) { - ks.push(key); - } - } + var isNode = typeof module !== "undefined" && module.exports && typeof require === "function"; + var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd; - return ks; - }; + if (isAMD) { + define(loadDependencies); + return; + } - exports.timers = timers; + if (isNode) { + loadDependencies(require, module.exports, module); + return; + } - function createClock(now) { - var clock = { - now: getEpoch(now), - timeouts: {}, - Date: createDate() - }; + if (sinonGlobal) { + makeApi(sinonGlobal); + } +}( + typeof sinon === "object" && sinon // eslint-disable-line no-undef +)); - clock.Date.clock = clock; +},{"./util/core":32}],40:[function(require,module,exports){ +module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; +} +},{}],41:[function(require,module,exports){ +(function (process,global){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - clock.setTimeout = function setTimeout(func, timeout) { - return addTimer(clock, { - func: func, - args: Array.prototype.slice.call(arguments, 2), - delay: timeout - }); - }; +var formatRegExp = /%[sdj%]/g; +exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } - clock.clearTimeout = function clearTimeout(timerId) { - return clearTimer(clock, timerId, "Timeout"); - }; + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; +}; - clock.setInterval = function setInterval(func, timeout) { - return addTimer(clock, { - func: func, - args: Array.prototype.slice.call(arguments, 2), - delay: timeout, - interval: timeout - }); - }; - clock.clearInterval = function clearInterval(timerId) { - return clearTimer(clock, timerId, "Interval"); - }; +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } - clock.setImmediate = function setImmediate(func) { - return addTimer(clock, { - func: func, - args: Array.prototype.slice.call(arguments, 1), - immediate: true - }); - }; + if (process.noDeprecation === true) { + return fn; + } - clock.clearImmediate = function clearImmediate(timerId) { - return clearTimer(clock, timerId, "Immediate"); - }; + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } - clock.tick = function tick(ms) { - ms = typeof ms === "number" ? ms : parseTime(ms); - var tickFrom = clock.now, tickTo = clock.now + ms, previous = clock.now; - var timer = firstTimerInRange(clock, tickFrom, tickTo); - var oldNow; + return deprecated; +}; - clock.duringTick = true; - var firstException; - while (timer && tickFrom <= tickTo) { - if (clock.timers[timer.id]) { - tickFrom = clock.now = timer.callAt; - try { - oldNow = clock.now; - callTimer(clock, timer); - // compensate for any setSystemTime() call during timer callback - if (oldNow !== clock.now) { - tickFrom += clock.now - oldNow; - tickTo += clock.now - oldNow; - previous += clock.now - oldNow; - } - } catch (e) { - firstException = firstException || e; - } - } +var debugs = {}; +var debugEnviron; +exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = process.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; +}; - timer = firstTimerInRange(clock, previous, tickTo); - previous = tickFrom; - } - clock.duringTick = false; - clock.now = tickTo; +/** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); + } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); +} +exports.inspect = inspect; - if (firstException) { - throw firstException; - } - return clock.now; - }; +// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] +}; - clock.reset = function reset() { - clock.timers = {}; - }; +// Don't use 'blue' not visible on cmd.exe +inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' +}; - clock.setSystemTime = function setSystemTime(now) { - // determine time difference - var newNow = getEpoch(now); - var difference = newNow - clock.now; - // update 'system clock' - clock.now = newNow; +function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; - // update timers and intervals to keep them stable - for (var id in clock.timers) { - if (clock.timers.hasOwnProperty(id)) { - var timer = clock.timers[id]; - timer.createdAt += difference; - timer.callAt += difference; - } - } - }; + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } +} - return clock; - } - exports.createClock = createClock; - exports.install = function install(target, now, toFake) { - var i, - l; +function stylizeNoColor(str, styleType) { + return str; +} - if (typeof target === "number") { - toFake = now; - now = target; - target = null; - } - if (!target) { - target = global; - } +function arrayToHash(array) { + var hash = {}; - var clock = createClock(now); + array.forEach(function(val, idx) { + hash[val] = true; + }); - clock.uninstall = function () { - uninstall(clock, target); - }; + return hash; +} - clock.methods = toFake || []; - if (clock.methods.length === 0) { - clock.methods = keys(timers); - } +function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; + } - for (i = 0, l = clock.methods.length; i < l; i++) { - hijackMethod(target, clock.methods[i], clock); - } + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } - return clock; - }; + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); -}(global || this)); + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],41:[function(require,module,exports){ -((typeof define === "function" && define.amd && function (m) { define("samsam", m); }) || - (typeof module === "object" && - function (m) { module.exports = m(); }) || // Node - function (m) { this.samsam = m(); } // Browser globals -)(function () { - var o = Object.prototype; - var div = typeof document !== "undefined" && document.createElement("div"); + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } - function isNaN(value) { - // Unlike global isNaN, this avoids type coercion - // typeof check avoids IE host object issues, hat tip to - // lodash - var val = value; // JsLint thinks value !== value is "weird" - return typeof value === "number" && value !== val; + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); } - - function getClass(value) { - // Returns the internal [[Class]] by calling Object.prototype.toString - // with the provided value as this. Return value is a string, naming the - // internal class, e.g. "Array" - return o.toString.call(value).split(/[ \]]/)[1]; + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); } - - /** - * @name samsam.isArguments - * @param Object object - * - * Returns ``true`` if ``object`` is an ``arguments`` object, - * ``false`` otherwise. - */ - function isArguments(object) { - if (getClass(object) === 'Arguments') { return true; } - if (typeof object !== "object" || typeof object.length !== "number" || - getClass(object) === "Array") { - return false; - } - if (typeof object.callee == "function") { return true; } - try { - object[object.length] = 6; - delete object[object.length]; - } catch (e) { - return true; - } - return false; + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); } - - /** - * @name samsam.isElement - * @param Object object - * - * Returns ``true`` if ``object`` is a DOM element node. Unlike - * Underscore.js/lodash, this function will return ``false`` if ``object`` - * is an *element-like* object, i.e. a regular object with a ``nodeType`` - * property that holds the value ``1``. - */ - function isElement(object) { - if (!object || object.nodeType !== 1 || !div) { return false; } - try { - object.appendChild(div); - object.removeChild(div); - } catch (e) { - return false; - } - return true; + if (isError(value)) { + return formatError(value); } + } - /** - * @name samsam.keys - * @param Object object - * - * Return an array of own property names. - */ - function keys(object) { - var ks = [], prop; - for (prop in object) { - if (o.hasOwnProperty.call(object, prop)) { ks.push(prop); } - } - return ks; - } + var base = '', array = false, braces = ['{', '}']; - /** - * @name samsam.isDate - * @param Object value - * - * Returns true if the object is a ``Date``, or *date-like*. Duck typing - * of date objects work by checking that the object has a ``getTime`` - * function whose return value equals the return value from the object's - * ``valueOf``. - */ - function isDate(value) { - return typeof value.getTime == "function" && - value.getTime() == value.valueOf(); - } + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } + + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } + + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } + + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } - /** - * @name samsam.isNegZero - * @param Object value - * - * Returns ``true`` if ``value`` is ``-0``. - */ - function isNegZero(value) { - return value === 0 && 1 / value === -Infinity; - } + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } - /** - * @name samsam.equal - * @param Object obj1 - * @param Object obj2 - * - * Returns ``true`` if two objects are strictly equal. Compared to - * ``===`` there are two exceptions: - * - * - NaN is considered equal to NaN - * - -0 and +0 are not considered equal - */ - function identical(obj1, obj2) { - if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) { - return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2); - } + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } + + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); } + } + ctx.seen.push(value); - /** - * @name samsam.deepEqual - * @param Object obj1 - * @param Object obj2 - * - * Deep equal comparison. Two values are "deep equal" if: - * - * - They are equal, according to samsam.identical - * - They are both date objects representing the same time - * - They are both arrays containing elements that are all deepEqual - * - They are objects with the same set of properties, and each property - * in ``obj1`` is deepEqual to the corresponding property in ``obj2`` - * - * Supports cyclic objects. - */ - function deepEqualCyclic(obj1, obj2) { + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } - // used for cyclic comparison - // contain already visited objects - var objects1 = [], - objects2 = [], - // contain pathes (position in the object structure) - // of the already visited objects - // indexes same as in objects arrays - paths1 = [], - paths2 = [], - // contains combinations of already compared objects - // in the manner: { "$1['ref']$2['ref']": true } - compared = {}; + ctx.seen.pop(); - /** - * used to check, if the value of a property is an object - * (cyclic logic is only needed for objects) - * only needed for cyclic logic - */ - function isObject(value) { + return reduceToSingleString(output, base, braces); +} - if (typeof value === 'object' && value !== null && - !(value instanceof Boolean) && - !(value instanceof Date) && - !(value instanceof Number) && - !(value instanceof RegExp) && - !(value instanceof String)) { - return true; - } +function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); +} - return false; - } - /** - * returns the index of the given object in the - * given objects array, -1 if not contained - * only needed for cyclic logic - */ - function getIndex(objects, obj) { +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} - var i; - for (i = 0; i < objects.length; i++) { - if (objects[i] === obj) { - return i; - } - } - return -1; - } +function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; +} - // does the recursion for the deep equal check - return (function deepEqual(obj1, obj2, path1, path2) { - var type1 = typeof obj1; - var type2 = typeof obj2; - // == null also matches undefined - if (obj1 === obj2 || - isNaN(obj1) || isNaN(obj2) || - obj1 == null || obj2 == null || - type1 !== "object" || type2 !== "object") { +function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } - return identical(obj1, obj2); - } + return name + ': ' + str; +} - // Elements are only equal if identical(expected, actual) - if (isElement(obj1) || isElement(obj2)) { return false; } - var isDate1 = isDate(obj1), isDate2 = isDate(obj2); - if (isDate1 || isDate2) { - if (!isDate1 || !isDate2 || obj1.getTime() !== obj2.getTime()) { - return false; - } - } +function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); - if (obj1 instanceof RegExp && obj2 instanceof RegExp) { - if (obj1.toString() !== obj2.toString()) { return false; } - } + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + } - var class1 = getClass(obj1); - var class2 = getClass(obj2); - var keys1 = keys(obj1); - var keys2 = keys(obj2); + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +} - if (isArguments(obj1) || isArguments(obj2)) { - if (obj1.length !== obj2.length) { return false; } - } else { - if (type1 !== type2 || class1 !== class2 || - keys1.length !== keys2.length) { - return false; - } - } - var key, i, l, - // following vars are used for the cyclic logic - value1, value2, - isObject1, isObject2, - index1, index2, - newPath1, newPath2; +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; - for (i = 0, l = keys1.length; i < l; i++) { - key = keys1[i]; - if (!o.hasOwnProperty.call(obj2, key)) { - return false; - } +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; - // Start of the cyclic logic +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; - value1 = obj1[key]; - value2 = obj2[key]; +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; - isObject1 = isObject(value1); - isObject2 = isObject(value2); +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; - // determine, if the objects were already visited - // (it's faster to check for isObject first, than to - // get -1 from getIndex for non objects) - index1 = isObject1 ? getIndex(objects1, value1) : -1; - index2 = isObject2 ? getIndex(objects2, value2) : -1; +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; - // determine the new pathes of the objects - // - for non cyclic objects the current path will be extended - // by current property name - // - for cyclic objects the stored path is taken - newPath1 = index1 !== -1 - ? paths1[index1] - : path1 + '[' + JSON.stringify(key) + ']'; - newPath2 = index2 !== -1 - ? paths2[index2] - : path2 + '[' + JSON.stringify(key) + ']'; +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; - // stop recursion if current objects are already compared - if (compared[newPath1 + newPath2]) { - return true; - } +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; - // remember the current objects and their pathes - if (index1 === -1 && isObject1) { - objects1.push(value1); - paths1.push(newPath1); - } - if (index2 === -1 && isObject2) { - objects2.push(value2); - paths2.push(newPath2); - } +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; - // remember that the current objects are already compared - if (isObject1 && isObject2) { - compared[newPath1 + newPath2] = true; - } +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; - // End of cyclic logic +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; - // neither value1 nor value2 is a cycle - // continue with next level - if (!deepEqual(value1, value2, newPath1, newPath2)) { - return false; - } - } +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; - return true; +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; - }(obj1, obj2, '$1', '$2')); - } +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; - var match; +exports.isBuffer = require('./support/isBuffer'); - function arrayContains(array, subset) { - if (subset.length === 0) { return true; } - var i, l, j, k; - for (i = 0, l = array.length; i < l; ++i) { - if (match(array[i], subset[0])) { - for (j = 0, k = subset.length; j < k; ++j) { - if (!match(array[i + j], subset[j])) { return false; } - } - return true; - } - } - return false; - } +function objectToString(o) { + return Object.prototype.toString.call(o); +} - /** - * @name samsam.match - * @param Object object - * @param Object matcher - * - * Compare arbitrary value ``object`` with matcher. - */ - match = function match(object, matcher) { - if (matcher && typeof matcher.test === "function") { - return matcher.test(object); - } - if (typeof matcher === "function") { - return matcher(object) === true; - } +function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} - if (typeof matcher === "string") { - matcher = matcher.toLowerCase(); - var notNull = typeof object === "string" || !!object; - return notNull && - (String(object)).toLowerCase().indexOf(matcher) >= 0; - } - if (typeof matcher === "number") { - return matcher === object; - } +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; - if (typeof matcher === "boolean") { - return matcher === object; - } +// 26 Feb 16:19:34 +function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); +} - if (typeof(matcher) === "undefined") { - return typeof(object) === "undefined"; - } - if (matcher === null) { - return object === null; - } +// log is just a thin wrapper to console.log that prepends a timestamp +exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +}; - if (getClass(object) === "Array" && getClass(matcher) === "Array") { - return arrayContains(object, matcher); - } - if (matcher && typeof matcher === "object") { - if (matcher === object) { - return true; - } - var prop; - for (prop in matcher) { - var value = object[prop]; - if (typeof value === "undefined" && - typeof object.getAttribute === "function") { - value = object.getAttribute(prop); - } - if (matcher[prop] === null || typeof matcher[prop] === 'undefined') { - if (value !== matcher[prop]) { - return false; - } - } else if (typeof value === "undefined" || !match(value, matcher[prop])) { - return false; - } - } - return true; - } +/** + * Inherit the prototype methods from one constructor into another. + * + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). + * + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. + */ +exports.inherits = require('inherits'); - throw new Error("Matcher was not a string, a number, a " + - "function, a boolean or an object"); - }; +exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; - return { - isArguments: isArguments, - isElement: isElement, - isDate: isDate, - isNegZero: isNegZero, - identical: identical, - deepEqual: deepEqualCyclic, - match: match, - keys: keys - }; -}); + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; +}; + +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} -},{}],42:[function(require,module,exports){ +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./support/isBuffer":40,"_process":13,"inherits":11}],42:[function(require,module,exports){ (function (global){ require('sinon') if (typeof window === 'undefined') { @@ -8350,7 +8051,7 @@ require('../') window.barometer.url = 'https://localhost:16006' }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../":1,"sinon":14}],43:[function(require,module,exports){ +},{"../":1,"sinon":15}],43:[function(require,module,exports){ 'use strict' var assert = require('assert') var sinon = require('sinon') @@ -8395,7 +8096,7 @@ describe('Testing event', function () { }) }) -},{"../lib/event.js":2,"./_fakeDom.js":42,"assert":9,"sinon":14}],44:[function(require,module,exports){ +},{"../lib/event.js":2,"./_fakeDom.js":42,"assert":9,"sinon":15}],44:[function(require,module,exports){ /* global window */ 'use strict' var sinon = require('sinon') @@ -8445,7 +8146,7 @@ describe('Testing pageChange', function () { }) }) -},{"../lib/pageChange.js":3,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],45:[function(require,module,exports){ +},{"../lib/pageChange.js":3,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":15}],45:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8489,7 +8190,7 @@ describe('Testing pageLoadStats', function () { }) }) -},{"../lib/pageLoadStats.js":4,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],46:[function(require,module,exports){ +},{"../lib/pageLoadStats.js":4,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":15}],46:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8579,7 +8280,7 @@ describe('Testing pageResources', function () { }) }) -},{"../lib/pageChange.js":3,"../lib/pageResources.js":5,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],48:[function(require,module,exports){ +},{"../lib/pageChange.js":3,"../lib/pageResources.js":5,"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":15}],48:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8690,7 +8391,7 @@ describe('Testing transport', function () { }) }) -},{"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":14}],49:[function(require,module,exports){ +},{"../lib/transport.js":6,"./_fakeDom.js":42,"assert":9,"sinon":15}],49:[function(require,module,exports){ /* global window */ 'use strict' var assert = require('assert') @@ -8752,4 +8453,4 @@ describe('Testing xhrStats', function () { }) }) -},{"../lib/transport.js":6,"../lib/xhrStats.js":8,"./_fakeDom.js":42,"sinon":14}]},{},[42,43,44,45,46,47,48,49,50]); +},{"../lib/transport.js":6,"../lib/xhrStats.js":8,"./_fakeDom.js":42,"sinon":15}]},{},[42,43,44,45,46,47,48,49,50]); diff --git a/dist/barometer.min.js b/dist/barometer.min.js index ec83ad2..6267679 100644 --- a/dist/barometer.min.js +++ b/dist/barometer.min.js @@ -1,7 +1,2 @@ -<<<<<<< 43fdfde7ecd48b6ed6c264b20b9d4c6c38fb47cf /*! barometer v1.1.0 */ -_='!e´ t(an¡) n¡;r=n¡={²:{id:a,“ed:!1}; e¡.call(r,r,r,tr.“ed¤r}n={}; t.m=¢.c=n,t.p="",t(0)}([¢,ne1)=Z@r2o6~n(7n(3n(8¯=¥,a =r ,=r.,a=o,#=o.#@r3o1~¯="XXXXX",eW={¦s:{ers:{}Ž=0e(„=„||0,„++,",e)a ,t™=™||[],™.”(t¦",¢)};i=¥;tWiKŽ<100K˜ii=£n,5e3)n0žŽKo.¯iK(˜ii=¥~±;e(~n=o.¯;‹)‹(n,‚~else{u=new r.a;u.op("POST",n,!eu.£R*Header("C`tt-Type","applici`/js`"u.sd(‚u.timeout=4e3}}…a=’;u=["UNSENT","OPENED","HEADERS_RECEIVED","LOADING","DONE"];r"xhrQeo,t,na={¨:n}r•e)"_"žr[0]K0že°K(a°=e°-t~ ait,n,r=i(¯u=o(FTimes,off£,¨)s•u)t="timing‰› (n,u[s]~t="µs.(nt="size (n,(r*.µText©.‡)’We=new a;try{±{n=op,o=sd;op=o,itry{s=;r(e,"readystec§",t[u[F]]=}r(e,"“d",n i({–:o,¯:i,FTimes:t,off£:s,¨:-s,r*:e})})}c—c} n,sdW o}c—i} e,n†?†(t,n,!1):œKœ("`"+t,n)n=(e©$.ƒ^€ -\\/~(t©.m—/\\?/)K(n+=t$.slice(1) -\\/)n},r,o,i@u4s7c2f=0,g=[];i.uWc (r,-a)i.sWc.(ªvisits")aKi.u(f++;e=,t=f,n=0,u=[9,9,9,9,9],l=!1,p=25,d=ªdynamic"vW˜wo¤a=,r=ªgagemt"~±125;c (d,-e-t)n=0;nnK(n=r!ltžf) v(~uŠu.”(r)o=0,i=0;i<5;i++)o+=u[i]; o<5Kn>25?v():void £m,p)}p)};m()i.s( ?(u(,"popste",i.see±·;·W i.s(t}}( )):u(,"hashc§",i.sig.”(e)i.#o) e(~±!1;i(t||(t¤e())})…o{n=®;e=toJSON()a•e)"®"žaK0že¡K(t¡=e¡-n~ tri(ref,ash~"page“Qt+"Qe -)fW¢= .timing||{n=o(t)r•n)e=r(ro (e,n°~i=( .Yi`||{}).¬Count||0;e=r("¬s"o (e,i)"object"==–of K("complete"===documt.F?f():r(,"“",f)),r@o6i2u=0,s=0;‘š(e~tK³(¢)šZ.rs;tfor(nŠro=0;o>>>>>> Track barometer request times +_='!e¸ t(an¢) n¢;r=n¢={¶:{id:a,–ed:!1}; e¢.call(r,r,r,tr.–ed¥r}n={}; t.m=£.c=n,t.p="",t(0)}([£,ne1)=@r2o3~n(5n(7n(8³=¦,a =r ,c=r.c,a=o,$=o.$@r1~³="XXXXX",eY={¨s:{cers:{}Š=0,­=0e(c‚=‚||0,‚++,t(Š++,­c",e)a ,t›=›||[],›.—(tt(Š¨",£)};o=¦;tYoKŠ<100Kšoo=¤n,5e3)n0•ŠK1•­Kr.³oK(šoo=¦~µ;e(~n=r.³§)(n,†~else{i=new ƒ;op#("POST",n,!e¤RHeader("C`t#t-Type","applici`/js`"s#d(†timeout=4e3}}},r,o,i@u4s5c2f=0,g=[];aYc (r,-a)rYc.c(ªvisits")aKa(f++;e=,t=f,n=0,u=[9,9,9,9,9],l=!1,p=25,d=ªdynamic"vYšwo¥a=,r=ª#gagem#t"~µ125;c (d,-e-t)n=0;nnK(n=r!lt•f) v(~uŽu.—(r)o=0,i=0;i<5;i++)o+=u[i]; o<5Kn>25?v():void ¤m,p)}p)};m()r(±?(u‹popste",reeµº;ºY r(t}}(±)):u‹hashc©",rig.—(e)$o) e(~µ!1;i(t||(t¥e())})}”,nˆ?ˆ(t,n,!1):žKž("`"+t,n)‡i’{n=²;e=toJSON()a Q e)"²"•aK0•e¢K(t¢=e¢-n~ to’i(¡ref,¡ash~"page–Wt+"We -)uY£= .timQg||{n=i(t)®n)e=o(ro (e,n´~i=( .Zi`||{}).¯C||0;e=o("¯s"o (e,i)"object"==˜of K("complete"===docum#t.F?u():r‹–",u))”n=(e«%.…^€ -\\/~(t«.m™/\\?/)K(n+=t%.slice(1) -\\/)n‡s=ƒ;u=["UNSENT","OPENED","HEADERS_RECEIVED","LOADING","DONE"];o"xhrWei,t,na={¬:n}®e)"_"•r[0]K0•e´K(a´=e´-t~ aft,n,r=i(³u=i(FTimes,off¤,¬)s Q u)t="timQgŒ (n,u[s]~t="¹s.c(nt="size (n,(r.¹Text«.‰)ƒYe=new s;try{µ{n=op#,o=s#d;op#=o,itry{s=;r(e,"readystec©",t[u[F]]=}r(e,"–#d",n f({˜:o,³:i,FTimes:t,off¤:s,¬:-s,r:e})})}c™c} n,s#dY o}c™i} e},r@o3i2u=0,s=0;“’Ÿ(e~tK·(£)Ÿ’.r„s§tfor(nŽrœo=0;o