The main problem with using node.js is that it does not provide everything that the browser will provide ... including XMLHttpRequest.
I am developing a library (proprietary, for internal use only) that I am trying to test with node.js.
My work on the lack of XHR support is to use this XHR implementation in conjunction with some Microsoft-provided code to add backward compatibility for standard XHR to old IE .
If you are using jQuery, you probably need to change it, since jQuery adds its own compatibility later for old IE.
The result is as follows:
var XMLHttpRequest; if (typeof window !== 'undefined') { XMLHttpRequest = window.XMLHttpRequest; } if (typeof XMLHttpRequest === "undefined") { console.log("Undefined"); (function() { try { XMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {} try { XMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {} try { XMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} try { XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; } catch(e) {} //Microsoft.XMLHTTP points to Msxml2.XMLHTTP and is redundant if (typeof XMLHttpRequest === "undefined") { throw new Error("This browser does not support XMLHttpRequest."); } })(); };
Also, starting a simple HTTP server in your test suite is a common approach for this kind of problem. I have not yet implemented it, and I'm working on httpd running on a test server.
source share