artsy / benv

Stub a browser environment in node.js and headlessly test your client-side code.
MIT License
73 stars 19 forks source link

Need to set URL as JSdom started to check CORS #29

Closed vbraun closed 8 years ago

vbraun commented 8 years ago

I just updated to the latest benv and all XMLHttpRequests error out because jsdom now checks CORS, but benv doesn't supply the URL to jsdom.env. Since the origin then mismatches everything is a CORS violation. The fix is to supply jsdom with the URL to check against:

module.exports.setup = function(callback) {
  if (typeof window != 'undefined') return callback && callback();
  jsdom.env({
    url: 'http://localhost:8080',       // <-------- add URL here
    html: "<html><body></body></html>",
    done: function(errs, w) {
      global.window = w;
      domGlobals.forEach(function(varName) {
        global[varName] = w[varName] || function(){};
      });
      if (callback) callback();
    }
  })
}

Seems that we need a way to supply additional parameters to jsdom.env in the setup() call. Optional second argument perhaps?

vbraun commented 8 years ago

jsdom 8.2.0 changelog: Updated our XMLHttpRequest implementation with a variety of fixes and features, including preliminary CORS support. (nicolashenry)