purescript-httpurple/test/Test/HTTPurple/TestHelpers.js
2022-05-22 12:48:32 +01:00

51 lines
1.1 KiB
JavaScript

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;
};
export const mockResponse = () => ({
body: "",
headers: {},
write: function (str, encoding, callback) {
this.body = this.body + str;
if (callback) {
callback();
}
},
end: function (str, encoding, callback) {
if (callback) {
callback();
}
},
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;
}