From 00410a8322f75c0b05659409b749a65f53a3865a Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 6 Mar 2014 04:15:01 +0100 Subject: [PATCH] Update SinonJS to v1.9.0 Source: * http://sinonjs.org/releases/sinon-1.9.0.js * http://sinonjs.org/releases/sinon-ie-1.9.0.js Changelog: * http://sinonjs.org/Changelog.txt Change-Id: I754ec906c2fc61b0e55bb61876fc7aafe2b3a67c --- .../{sinon-1.8.1.js => sinon-1.9.0.js} | 99 ++++++++++++++++--- .../{sinon-ie-1.8.1.js => sinon-ie-1.9.0.js} | 4 +- tests/qunit/QUnitTestResources.php | 4 +- 3 files changed, 90 insertions(+), 17 deletions(-) rename resources/sinonjs/{sinon-1.8.1.js => sinon-1.9.0.js} (97%) rename resources/sinonjs/{sinon-ie-1.8.1.js => sinon-ie-1.9.0.js} (97%) diff --git a/resources/sinonjs/sinon-1.8.1.js b/resources/sinonjs/sinon-1.9.0.js similarity index 97% rename from resources/sinonjs/sinon-1.8.1.js rename to resources/sinonjs/sinon-1.9.0.js index 3e9865ebc4..428b729b64 100644 --- a/resources/sinonjs/sinon-1.8.1.js +++ b/resources/sinonjs/sinon-1.9.0.js @@ -1,12 +1,12 @@ /** - * Sinon.JS 1.8.1, 2014/02/02 + * Sinon.JS 1.9.0, 2014/03/05 * * @author Christian Johansen (christian@cjohansen.no) * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS * * (The BSD License) * - * Copyright (c) 2010-2013, Christian Johansen, christian@cjohansen.no + * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -772,6 +772,11 @@ var sinon = (function (formatio) { 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; @@ -1047,8 +1052,10 @@ var sinon = (function (formatio) { } matcher.or = function (m2) { - if (!isMatcher(m2)) { + if (!arguments.length) { throw new TypeError("Matcher expected"); + } else if (!isMatcher(m2)) { + m2 = match(m2); } var m1 = this; var or = sinon.create(matcher); @@ -1060,8 +1067,10 @@ var sinon = (function (formatio) { }; matcher.and = function (m2) { - if (!isMatcher(m2)) { + if (!arguments.length) { throw new TypeError("Matcher expected"); + } else if (!isMatcher(m2)) { + m2 = match(m2); } var m1 = this; var and = sinon.create(matcher); @@ -1312,7 +1321,7 @@ var sinon = (function (formatio) { }, calledWithNew: function calledWithNew() { - return this.thisValue instanceof this.proxy; + return this.proxy.prototype && this.thisValue instanceof this.proxy; }, calledBefore: function (other) { @@ -3348,6 +3357,25 @@ if (typeof sinon == "undefined") { } }; + sinon.ProgressEvent = function ProgressEvent(type, progressEventRaw, target) { + this.initEvent(type, false, false, target); + this.loaded = progressEventRaw.loaded || null; + this.total = progressEventRaw.total || null; + }; + + sinon.ProgressEvent.prototype = new sinon.Event(); + + sinon.ProgressEvent.prototype.constructor = sinon.ProgressEvent; + + sinon.CustomEvent = function CustomEvent(type, customData, target) { + this.initEvent(type, false, false, target); + this.detail = customData.detail || null; + }; + + sinon.CustomEvent.prototype = new sinon.Event(); + + sinon.CustomEvent.prototype.constructor = sinon.CustomEvent; + sinon.EventTarget = { addEventListener: function addEventListener(event, listener) { this.eventListeners = this.eventListeners || {}; @@ -3399,12 +3427,13 @@ if (typeof sinon == "undefined") { // wrapper for global (function(global) { - if (typeof sinon === "undefined") { global.sinon = {}; } - sinon.xhr = { XMLHttpRequest: global.XMLHttpRequest }; + var supportsProgress = typeof ProgressEvent !== "undefined"; + var supportsCustomEvent = typeof CustomEvent !== "undefined"; + sinon.xhr = { XMLHttpRequest: global.XMLHttpRequest }; var xhr = sinon.xhr; xhr.GlobalXMLHttpRequest = global.XMLHttpRequest; xhr.GlobalActiveXObject = global.ActiveXObject; @@ -3457,7 +3486,7 @@ if (typeof sinon == "undefined") { var listener = xhr["on" + eventName]; if (listener && typeof listener == "function") { - listener(event); + listener.call(this, event); } }); } @@ -3596,6 +3625,12 @@ if (typeof sinon == "undefined") { }; FakeXMLHttpRequest.useFilters = false; + function verifyRequestOpened(xhr) { + if (xhr.readyState != FakeXMLHttpRequest.OPENED) { + throw new Error("INVALID_STATE_ERR - " + xhr.readyState); + } + } + function verifyRequestSent(xhr) { if (xhr.readyState == FakeXMLHttpRequest.DONE) { throw new Error("Request done"); @@ -3660,7 +3695,9 @@ if (typeof sinon == "undefined") { this.dispatchEvent(new sinon.Event("load", false, false, this)); this.dispatchEvent(new sinon.Event("loadend", false, false, this)); this.upload.dispatchEvent(new sinon.Event("load", false, false, this)); - this.upload.dispatchEvent(new ProgressEvent("progress", {loaded: 100, total: 100})); + if (supportsProgress) { + this.upload.dispatchEvent(new sinon.ProgressEvent('progress', {loaded: 100, total: 100})); + } break; } }, @@ -3681,6 +3718,7 @@ if (typeof sinon == "undefined") { // Helps testing setResponseHeaders: function setResponseHeaders(headers) { + verifyRequestOpened(this); this.responseHeaders = {}; for (var header in headers) { @@ -3818,18 +3856,22 @@ if (typeof sinon == "undefined") { }, respond: function respond(status, headers, body) { - this.setResponseHeaders(headers || {}); this.status = typeof status == "number" ? status : 200; this.statusText = FakeXMLHttpRequest.statusCodes[this.status]; + this.setResponseHeaders(headers || {}); this.setResponseBody(body || ""); }, uploadProgress: function uploadProgress(progressEventRaw) { - this.upload.dispatchEvent(new ProgressEvent("progress", progressEventRaw)); + if (supportsProgress) { + this.upload.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw)); + } }, uploadError: function uploadError(error) { - this.upload.dispatchEvent(new CustomEvent("error", {"detail": error})); + if (supportsCustomEvent) { + this.upload.dispatchEvent(new sinon.CustomEvent("error", {"detail": error})); + } } }); @@ -4269,8 +4311,9 @@ if (typeof module !== 'undefined' && module.exports) { return; } - if (config.injectInto && !(key in config.injectInto) ) { + if (config.injectInto && !(key in config.injectInto)) { config.injectInto[key] = value; + sandbox.injectedKeys.push(key); } else { push.call(sandbox.args, value); } @@ -4333,6 +4376,20 @@ if (typeof module !== 'undefined' && module.exports) { return obj; }, + restore: function () { + sinon.collection.restore.apply(this, arguments); + this.restoreContext(); + }, + + restoreContext: function () { + if (this.injectedKeys) { + for (var i = 0, j = this.injectedKeys.length; i < j; i++) { + delete this.injectInto[this.injectedKeys[i]]; + } + this.injectedKeys = []; + } + }, + create: function (config) { if (!config) { return sinon.create(sinon.sandbox); @@ -4340,6 +4397,8 @@ if (typeof module !== 'undefined' && module.exports) { var sandbox = prepareSandboxFromConfig(config); sandbox.args = sandbox.args || []; + sandbox.injectedKeys = []; + sandbox.injectInto = config.injectInto; var prop, value, exposed = sandbox.inject({}); if (config.properties) { @@ -4687,6 +4746,20 @@ if (typeof module !== 'undefined' && module.exports) { } 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")); + } } }; diff --git a/resources/sinonjs/sinon-ie-1.8.1.js b/resources/sinonjs/sinon-ie-1.9.0.js similarity index 97% rename from resources/sinonjs/sinon-ie-1.8.1.js rename to resources/sinonjs/sinon-ie-1.9.0.js index f92e9dba3a..c9fbd9da2e 100644 --- a/resources/sinonjs/sinon-ie-1.8.1.js +++ b/resources/sinonjs/sinon-ie-1.9.0.js @@ -1,12 +1,12 @@ /** - * Sinon.JS 1.8.1, 2014/02/02 + * Sinon.JS 1.9.0, 2014/03/05 * * @author Christian Johansen (christian@cjohansen.no) * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS * * (The BSD License) * - * Copyright (c) 2010-2013, Christian Johansen, christian@cjohansen.no + * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php index f6748198e6..8a4e862dc4 100644 --- a/tests/qunit/QUnitTestResources.php +++ b/tests/qunit/QUnitTestResources.php @@ -8,8 +8,8 @@ return array( 'test.sinonjs' => array( 'scripts' => array( - 'resources/sinonjs/sinon-1.8.1.js', - 'resources/sinonjs/sinon-ie-1.8.1.js', + 'resources/sinonjs/sinon-1.9.0.js', + 'resources/sinonjs/sinon-ie-1.9.0.js', ), 'targets' => array( 'desktop', 'mobile' ), ), -- 2.20.1