purescript-httpurple/test/Test/HTTPurple/TestHelpers.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

import { Readable } from "stream";
export const mockRequestImpl = httpVersion => method => url => body => headers => () => {
const stream = new Readable({
read: function (size) {
this.push(body);
this.push(null);
}
});
stream.method = method;
stream.url = url;
stream.headers = headers;
stream.httpVersion = httpVersion;
return stream;
2017-07-18 05:25:14 +00:00
};
export const mockResponse = () => ({
2017-07-20 22:48:59 +00:00
body: "",
headers: {},
write: function (str, encoding, callback) {
this.body = this.body + str;
if (callback) {
callback();
}
},
end: function (str, encoding, callback) {
if (callback) {
callback();
}
2017-07-20 22:48:59 +00:00
},
on: function () {},
once: function () {},
emit: function () {},
setHeader: function (header, val) {
this.headers[header] = val;
},
});
export const stringToStream = str => {
const stream = new Readable();
stream._read = function () {};
stream.push(str);
stream.push(null);
return stream;
}