Comparing version 1.0.1 to 1.1.0
@@ -37,2 +37,4 @@ "use strict"; | ||
sinonXhr.workingXHR = getWorkingXHR(global); | ||
sinonXhr.supportsTimeout = | ||
(sinonXhr.supportsXHR && "timeout" in (new sinonXhr.GlobalXMLHttpRequest())); | ||
sinonXhr.supportsCORS = isReactNative || | ||
@@ -97,2 +99,7 @@ (sinonXhr.supportsXHR && "withCredentials" in (new sinonXhr.GlobalXMLHttpRequest())); | ||
this.logError = configureLogError(config); | ||
if (sinonXhr.supportsTimeout) { | ||
this.timeout = 0; | ||
} | ||
if (sinonXhr.supportsCORS) { | ||
@@ -275,2 +282,19 @@ this.withCredentials = false; | ||
/** | ||
* Steps to follow when there is an error, according to: | ||
* https://xhr.spec.whatwg.org/#request-error-steps | ||
*/ | ||
function requestErrorSteps(xhr) { | ||
clearResponse(xhr); | ||
xhr.errorFlag = true; | ||
xhr.requestHeaders = {}; | ||
xhr.responseHeaders = {}; | ||
if (xhr.readyState !== FakeXMLHttpRequest.UNSENT && xhr.sendFlag | ||
&& xhr.readyState !== FakeXMLHttpRequest.DONE) { | ||
xhr.readyStateChange(FakeXMLHttpRequest.DONE); | ||
xhr.sendFlag = false; | ||
} | ||
} | ||
FakeXMLHttpRequest.parseXML = function parseXML(text) { | ||
@@ -382,5 +406,5 @@ // Treat empty string as parsing failure | ||
if (this.readyState === FakeXMLHttpRequest.DONE) { | ||
if (this.aborted || this.status === 0) { | ||
if (this.timedOut || this.aborted || this.status === 0) { | ||
progress = {loaded: 0, total: 0}; | ||
event = this.aborted ? "abort" : "error"; | ||
event = (this.timedOut && "timeout") || (this.aborted && "abort") || "error"; | ||
} else { | ||
@@ -474,2 +498,28 @@ progress = {loaded: 100, total: 100}; | ||
// Only listen if setInterval and Date are a stubbed. | ||
if (sinonXhr.supportsTimeout && typeof setInterval.clock === "object" && typeof Date.clock === "object") { | ||
var initiatedTime = Date.now(); | ||
var self = this; | ||
// Listen to any possible tick by fake timers and check to see if timeout has | ||
// been exceeded. It's important to note that timeout can be changed while a request | ||
// is in flight, so we must check anytime the end user forces a clock tick to make | ||
// sure timeout hasn't changed. | ||
// https://xhr.spec.whatwg.org/#dfnReturnLink-2 | ||
var clearIntervalId = setInterval(function () { | ||
// Check if the readyState has been reset or is done. If this is the case, there | ||
// should be no timeout. This will also prevent aborted requests and | ||
// fakeServerWithClock from triggering unnecessary responses. | ||
if (self.readyState === FakeXMLHttpRequest.UNSENT | ||
|| self.readyState === FakeXMLHttpRequest.DONE) { | ||
clearInterval(clearIntervalId); | ||
} else if (typeof self.timeout === "number" && self.timeout > 0) { | ||
if (Date.now() >= (initiatedTime + self.timeout)) { | ||
self.triggerTimeout(); | ||
clearInterval(clearIntervalId); | ||
} | ||
} | ||
}, 1); | ||
} | ||
this.dispatchEvent(new sinonEvent.Event("loadstart", false, false, this)); | ||
@@ -480,13 +530,3 @@ }, | ||
this.aborted = true; | ||
clearResponse(this); | ||
this.errorFlag = true; | ||
this.requestHeaders = {}; | ||
this.responseHeaders = {}; | ||
if (this.readyState !== FakeXMLHttpRequest.UNSENT && this.sendFlag | ||
&& this.readyState !== FakeXMLHttpRequest.DONE) { | ||
this.readyStateChange(FakeXMLHttpRequest.DONE); | ||
this.sendFlag = false; | ||
} | ||
requestErrorSteps(this); | ||
this.readyState = FakeXMLHttpRequest.UNSENT; | ||
@@ -504,2 +544,9 @@ }, | ||
triggerTimeout: function triggerTimeout() { | ||
if (sinonXhr.supportsTimeout) { | ||
this.timedOut = true; | ||
requestErrorSteps(this); | ||
} | ||
}, | ||
getResponseHeader: function getResponseHeader(header) { | ||
@@ -506,0 +553,0 @@ if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) { |
{ | ||
"name": "nise", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Fake XHR and server", | ||
@@ -23,3 +23,5 @@ "keywords": [ | ||
"test": "mocha 'lib/**/*.test.js'", | ||
"test:coverage": "nyc --reporter=lcov --reporter=text --all npm test -- --reporter dot" | ||
"test:coverage": "nyc --reporter=lcov --reporter=text --all npm test -- --reporter dot", | ||
"precommit": "npm run lint -- --fix && npm run test", | ||
"prepush": "npm run lint && npm run test" | ||
}, | ||
@@ -57,5 +59,6 @@ "author": "", | ||
"browserify": "^14.4.0", | ||
"eslint": "^3.19.0", | ||
"eslint": "^4.5.0", | ||
"eslint-config-sinon": "^1.0.1", | ||
"eslint-plugin-mocha": "^4.9.0", | ||
"husky": "^0.14.3", | ||
"jsdom": "11.0.0", | ||
@@ -65,3 +68,2 @@ "jsdom-global": "3.0.2", | ||
"nyc": "^11.0.2", | ||
"pre-commit": "^1.2.2", | ||
"proxyquire": "^1.8.0", | ||
@@ -76,4 +78,5 @@ "referee": "^1.2.0", | ||
"lolex": "^1.6.0", | ||
"path-to-regexp": "^1.7.0" | ||
"path-to-regexp": "^1.7.0", | ||
"text-encoding": "^0.6.4" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
774923
8533
5
2
+ Addedtext-encoding@^0.6.4
+ Addedtext-encoding@0.6.4(transitive)