pax_global_header00006660000000000000000000000064142652616500014521gustar00rootroot0000000000000052 comment=07ece79927bb2deb6f3b9a73d6894298f664dcff responselike-2.0.1/000077500000000000000000000000001426526165000142245ustar00rootroot00000000000000responselike-2.0.1/.gitignore000066400000000000000000000020161426526165000162130ustar00rootroot00000000000000## Node # Logs logs *.log npm-debug.log* # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # node-waf configuration .lock-wscript # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules jspm_packages # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history ## OS X *.DS_Store .AppleDouble .LSOverride # Icon must end with two \r Icon # Thumbnails ._* # Files that might appear in the root of a volume .DocumentRevisions-V100 .fseventsd .Spotlight-V100 .TemporaryItems .Trashes .VolumeIcon.icns .com.apple.timemachine.donotpresent # Directories potentially created on remote AFP share .AppleDB .AppleDesktop Network Trash Folder Temporary Items .apdisk responselike-2.0.1/.npmignore000066400000000000000000000000071426526165000162200ustar00rootroot00000000000000* !src responselike-2.0.1/.travis.yml000066400000000000000000000002131426526165000163310ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' script: npm test after_success: npm run coverage notifications: email: on_success: never responselike-2.0.1/LICENSE000066400000000000000000000020371426526165000152330ustar00rootroot00000000000000Copyright (c) 2017 Luke Childs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. responselike-2.0.1/README.md000066400000000000000000000036041426526165000155060ustar00rootroot00000000000000# responselike > A response-like object for mocking a Node.js HTTP response stream [![Build Status](https://travis-ci.org/lukechilds/responselike.svg?branch=master)](https://travis-ci.org/lukechilds/responselike) [![Coverage Status](https://coveralls.io/repos/github/lukechilds/responselike/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/responselike?branch=master) [![npm](https://img.shields.io/npm/dm/responselike.svg)](https://www.npmjs.com/package/responselike) [![npm](https://img.shields.io/npm/v/responselike.svg)](https://www.npmjs.com/package/responselike) Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage). Useful for formatting cached responses so they can be consumed by code expecting a real response. ## Install ```shell npm install --save responselike ``` Or if you're just using for testing you'll want: ```shell npm install --save-dev responselike ``` ## Usage ```js const Response = require('responselike'); const response = new Response(200, { foo: 'bar' }, Buffer.from('Hi!'), 'https://example.com'); response.statusCode; // 200 response.headers; // { foo: 'bar' } response.body; // response.url; // 'https://example.com' response.pipe(process.stdout); // Hi! ``` ## API ### new Response(statusCode, headers, body, url) Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage). #### statusCode Type: `number` HTTP response status code. #### headers Type: `object` HTTP headers object. Keys will be automatically lowercased. #### body Type: `buffer` A Buffer containing the response body. The Buffer contents will be streamable but is also exposed directly as `response.body`. #### url Type: `string` Request URL string. ## License MIT © Luke Childs responselike-2.0.1/package.json000066400000000000000000000015631426526165000165170ustar00rootroot00000000000000{ "name": "responselike", "version": "2.0.1", "description": "A response-like object for mocking a Node.js HTTP response stream", "funding": "https://github.com/sponsors/sindresorhus", "main": "src/index.js", "scripts": { "test": "xo && nyc ava", "coverage": "nyc report --reporter=text-lcov | coveralls" }, "xo": { "extends": "xo-lukechilds" }, "keywords": [ "http", "https", "response", "mock", "request", "responselike" ], "repository": { "type": "git", "url": "https://github.com/sindresorhus/responselike.git" }, "author": "lukechilds", "license": "MIT", "devDependencies": { "ava": "^0.25.0", "coveralls": "^3.0.0", "eslint-config-xo-lukechilds": "^1.0.0", "get-stream": "^3.0.0", "nyc": "^11.8.0", "xo": "^0.19.0" }, "dependencies": { "lowercase-keys": "^2.0.0" } } responselike-2.0.1/src/000077500000000000000000000000001426526165000150135ustar00rootroot00000000000000responselike-2.0.1/src/index.js000066400000000000000000000014671426526165000164700ustar00rootroot00000000000000'use strict'; const Readable = require('stream').Readable; const lowercaseKeys = require('lowercase-keys'); class Response extends Readable { constructor(statusCode, headers, body, url) { if (typeof statusCode !== 'number') { throw new TypeError('Argument `statusCode` should be a number'); } if (typeof headers !== 'object') { throw new TypeError('Argument `headers` should be an object'); } if (!(body instanceof Buffer)) { throw new TypeError('Argument `body` should be a buffer'); } if (typeof url !== 'string') { throw new TypeError('Argument `url` should be a string'); } super(); this.statusCode = statusCode; this.headers = lowercaseKeys(headers); this.body = body; this.url = url; } _read() { this.push(this.body); this.push(null); } } module.exports = Response; responselike-2.0.1/test/000077500000000000000000000000001426526165000152035ustar00rootroot00000000000000responselike-2.0.1/test/fixtures/000077500000000000000000000000001426526165000170545ustar00rootroot00000000000000responselike-2.0.1/test/fixtures/index.js000066400000000000000000000003371426526165000205240ustar00rootroot00000000000000const statusCode = 200; const headers = { Foo: "Bar"}; const bodyText = 'Hi.'; const body = Buffer.from(bodyText); const url = 'https://example.com'; module.exports = { statusCode, headers, bodyText, body, url } responselike-2.0.1/test/responselike.js000066400000000000000000000037641426526165000202560ustar00rootroot00000000000000import test from 'ava'; import lowercaseKeys from 'lowercase-keys'; import getStream from 'get-stream'; import Response from '../'; import f from './fixtures'; test('Response is a function', t => { t.is(typeof Response, 'function'); }); test('Response cannot be invoked without \'new\'', t => { t.throws(() => Response(f.statusCode, f.headers, f.body, f.url)); // eslint-disable-line new-cap t.notThrows(() => new Response(f.statusCode, f.headers, f.body, f.url)); }); test('new Response() throws on invalid statusCode', t => { const error = t.throws(() => new Response(undefined, f.headers, f.body, f.url)); t.is(error.message, 'Argument `statusCode` should be a number'); }); test('new Response() throws on invalid headers', t => { const error = t.throws(() => new Response(f.statusCode, undefined, f.body, f.url)); t.is(error.message, 'Argument `headers` should be an object'); }); test('new Response() throws on invalid body', t => { const error = t.throws(() => new Response(f.statusCode, f.headers, undefined, f.url)); t.is(error.message, 'Argument `body` should be a buffer'); }); test('new Response() throws on invalid url', t => { const error = t.throws(() => new Response(f.statusCode, f.headers, f.body, undefined)); t.is(error.message, 'Argument `url` should be a string'); }); test('response has expected properties', t => { const response = new Response(f.statusCode, f.headers, f.body, f.url); t.is(response.statusCode, f.statusCode); t.deepEqual(response.headers, lowercaseKeys(f.headers)); t.is(response.body, f.body); t.is(response.url, f.url); }); test('response headers have lowercase keys', t => { const response = new Response(f.statusCode, f.headers, f.body, f.url); t.not(JSON.stringify(f.headers), response.headers); t.deepEqual(response.headers, lowercaseKeys(f.headers)); }); test('response streams body', async t => { const response = new Response(f.statusCode, f.headers, f.body, f.url); const responseStream = await getStream(response); t.is(responseStream, f.bodyText); });