purescript-httpurple/test/Test/HTTPure/TestHelpers.js
Thomas Honeyman 42bf4475e0
Update for PureScript 0.15 (#194)
* Update shell and packages

* Fix code for 0.15

* Fix tests

* Format

* Add check-pulp command

* Generate bowerfile

* Add check-pulp to CI

* Add nixfmt to formatting

* Fixup test helpers

* Take 2

* PR comments (#1)

* Nix cleanup from PR

* Use arrows functions

* Remove unnecessary step

Co-authored-by: Connor Prussin <connor@prussin.net>
2022-05-04 14:02:29 -07: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;
}