purescript-httpurple/test/Test/HTTPure/TestHelpers.js
Connor Prussin 1adbcecaaa
Chunked responses (#107)
* Chunked responses

* Remove Chunked newtype wrapper around Streams

* Use child process instead of ffi stream for chunked example

* Rename additionalHeaders to defaultHeaders

* Add History.md entry

* General cleanup
2018-08-30 15:01:49 -07:00

52 lines
1.0 KiB
JavaScript

"use strict";
exports.mockRequestImpl = function(method) {
return function(url) {
return function(body) {
return function(headers) {
return function() {
var stream = new require('stream').Readable({
read: function(size) {
this.push(body);
this.push(null);
}
});
stream.method = method;
stream.url = url;
stream.headers = headers;
return stream;
};
};
};
};
};
exports.mockResponse = function() {
return {
body: "",
headers: {},
write: function(str) {
this.body = this.body + str;
},
end: function() { },
on: function() { },
once: function() { },
emit: function() { },
setHeader: function(header, val) {
this.headers[header] = val;
}
};
};
exports.stringToStream = function (str) {
var stream = new require('stream').Readable();
stream._read = function () {};
stream.push(str);
stream.push(null);
return stream;
}