-
Notifications
You must be signed in to change notification settings - Fork 48
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
Utilities are not bundled into standalone browser build #80
Comments
Related issue: #54 I'm open to ideas! Potentially we could export a WDYT? Would you be interested in contributing this enhancement? |
The same affects the Yes, either bundling the utilities in The file (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ?
module.exports = factory(require('xhr-mock')) :
typeof define === 'function' && define.amd ?
define(['xhr-mock'], factory) :
(global.XHRMockProxy= factory(XHRMock));
}(this, (function (mock) { 'use strict';
function parseHeaders(string) {
var headers = {};
var lines = string.split('\r\n');
lines.forEach(function (line) {
var parts = line.split(':', 2), name = parts[0], value = parts[1];
if (name && value) {
headers[name] = value.replace(/^\s*/g, '').replace(/\s*$/g, '');
}
});
return headers;
}
function proxy(req, res) {
return new Promise(function (resolve, reject) {
var xhr = new mock.RealXMLHttpRequest();
// TODO: reject with the correct type of error
xhr.onerror = function (event) { return reject(event.error); };
xhr.onloadend = function () {
res
.status(xhr.status)
.reason(xhr.statusText)
.headers(parseHeaders(xhr.getAllResponseHeaders()))
.body(xhr.response);
resolve(res);
};
xhr.open(req.method(), req.url().toString());
var headers = req.headers();
Object.keys(headers).forEach(function (name) {
var value = headers[name];
xhr.setRequestHeader(name, value);
});
xhr.send(req.body());
});
}
return proxy;
}))); The same could be done with the utilities as a workaround. However, they have module dependencies, in comparison to the |
This issue will be resolved in |
The once and delay utilities added in #65 are super-helpful. Unfortunately they are not included in the standalone browser build produced in dist/xhr-mock.js , as seen, for example, at https://unpkg.com/[email protected]/dist/xhr-mock.js as referenced in the docs section "Without a bundler".
The text was updated successfully, but these errors were encountered: