-
-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sinon.fakeServer does not work under Node.js because its file isn't wrapped properly #319
Comments
The Fake XHR/server stuff wasn't intended to work on Node when it was written. Feel free to submit a patch for this, and I'll happily pull. |
Kay, so how do you envision this? With help from I'd argue for presenting the complete Sinon on Node without messing with global variables and explicit requires, but initializing the server stuff only when explicitly required. Which is how it works in the browser as well, I guess. |
Maybe this is something we could address properly in Sinon 2.0 by moving the XHR stuff into a separate module. Not sure whether @moll's |
Well, what I did was hack to get Sinon's fake server code from the outside to use the global reference of XMLHttpRequest as it doesn't use the global reference there even if it exists. JSDOM itself uses Node's Moving Sinon's XHR stuff to a proper module that would take the real XHR reference and return a fake one, or something equivalent, would be indeed better. |
@cjohansen I'm currently running into a similar issue using Sinon with https://github.com/substack/node-browserify. Since I'm using the npm version of Sinon and Browserify loads everything as CommonJS modules, it looks like Sinon is leaving out all of the HTTP mocking methods (even though I'm in a browser environment). Is there some other way to check environments that would allow me to use |
Same issue as @cjohansen using browserify. |
Same issue when used with karma and phantomjs: TypeError: Fake server request processing threw exception: '[object ProgressEventConstructor]' is not a constructor (evaluating 'new ProgressEvent("progress", {loaded: 100, total: 100})')
at /Users/roblevin/labs/ember/testing-tutsplus/js/libs/sinon-1.8.1.js:3663
PhantomJS 1.9.7 (Mac OS X) Ajax tests Display error message when server responds with error FAILED
TypeError: Fake server request processing threw exception: '[object ProgressEventConstructor]' is not a constructor (evaluating 'new ProgressEvent("progress", {loaded: 100, total: 100})')
/Users/roblevin/labs/ember/testing-tutsplus/js/libs/sinon-1.8.1.js:3663
PhantomJS 1.9.7 (Mac OS X): Executed 1 of 0 (1 FAILED) ERROR (0.371 secs / 0.117 secs) |
Is this an issue with PhantomJS? Using the following script: var page = require('webpage').create();
page.evaluate(function(){
new ProgressEvent("progress", {loaded: 50, total: 100});
}); I get this output from running
update: I hacked my way around this issue by commenting out this line: switch (this.readyState) {
case FakeXMLHttpRequest.DONE:
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}));
break;
} update 2: @nyk0r's suggestion below is a better approach |
I'm having the same "'[object ProgressEventConstructor]' is not a constructor" issue using grunt-mocha and PhantomJS on my Windows 8 machine. It seems to fall on every second call to the fake XHR. Currently hacked this issue by adding the following code before running the specs. if (navigator.userAgent.indexOf('PhantomJS') !== -1){
window.ProgressEvent = function (type, params) {
params = params || {};
this.lengthComputable = params.lengthComputable || false;
this.loaded = params.loaded || 0;
this.total = params.total || 0;
};
} |
Also have the same problem with Karma + Chrome, Firefox, & Safari. |
I was able to solve this problem in Karma by installing the |
Node-workable fake server is a goal for 2.0 #600 |
that's cool, because it doesn't work in the browser either |
The
fake_xml_http_request.js
file has an iffy wrapping it for properglobal
access. Thefake_server.js
file does not and with the following "check" in its header it never has a chance to get a reference to the globalsinon
because thevar sinon
declaration is hoisted to the top of the scope:The text was updated successfully, but these errors were encountered: