Comparing version 1.7.0 to 2.0.1
@@ -13,3 +13,3 @@ # API Reference | ||
- `method` - a string specifying the HTTP request method, defaulting to `'GET'`. | ||
- `authority` - a string specifying the HTTP HOST header value is no header is provided and the `url` | ||
- `authority` - a string specifying the HTTP HOST header value to be used if no header is provided, and the `url` | ||
does not include an authority component. Defaults to `'localhost'`. | ||
@@ -28,3 +28,3 @@ - `headers` - an optional object containing request headers. | ||
- `req` - the simulated request object. | ||
- `req` - the simulated response object. | ||
- `res` - the simulated response object. | ||
- `headers` - an object containing the response headers. | ||
@@ -31,0 +31,0 @@ - `statusCode` - the HTTP status code. |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Http = require('http'); | ||
var Shot = require('..'); | ||
const Shot = require('..'); | ||
@@ -9,3 +10,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -15,5 +16,5 @@ | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
var reply = 'Hello World'; | ||
const reply = 'Hello World'; | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
@@ -23,8 +24,4 @@ res.end(reply); | ||
var server = Http.createServer(dispatch); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
// server.listen(1337, '127.0.0.1'); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
console.log(res.payload); | ||
@@ -31,0 +28,0 @@ }); |
141
lib/index.js
@@ -0,8 +1,10 @@ | ||
'use strict'; | ||
// Load modules | ||
var Http = require('http'); | ||
var Stream = require('stream'); | ||
var Util = require('util'); | ||
var Url = require('url'); | ||
var Hoek = require('hoek'); | ||
const Http = require('http'); | ||
const Stream = require('stream'); | ||
const Util = require('util'); | ||
const Url = require('url'); | ||
const Hoek = require('hoek'); | ||
@@ -12,3 +14,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -18,4 +20,2 @@ | ||
var self = this; | ||
Stream.Readable.call(this); | ||
@@ -25,3 +25,3 @@ | ||
var url = options.url; | ||
let url = options.url; | ||
@@ -32,3 +32,3 @@ if (typeof url === 'object') { | ||
var uri = Url.parse(url); | ||
const uri = Url.parse(url); | ||
this.url = uri.path; | ||
@@ -40,7 +40,7 @@ | ||
this.headers = {}; | ||
var headers = options.headers || {}; | ||
var fields = Object.keys(headers); | ||
fields.forEach(function (field) { | ||
const headers = options.headers || {}; | ||
const fields = Object.keys(headers); | ||
fields.forEach((field) => { | ||
self.headers[field.toLowerCase()] = headers[field]; | ||
this.headers[field.toLowerCase()] = headers[field]; | ||
}); | ||
@@ -57,3 +57,3 @@ | ||
var payload = options.payload || null; | ||
let payload = options.payload || null; | ||
if (payload && | ||
@@ -89,9 +89,7 @@ typeof payload !== 'string' && | ||
var self = this; | ||
setImmediate(() => { | ||
setImmediate(function () { | ||
if (self._shot.isDone) { | ||
if (self._shot.simulate.end !== false) { // 'end' defaults to true | ||
self.push(null); | ||
if (this._shot.isDone) { | ||
if (this._shot.simulate.end !== false) { // 'end' defaults to true | ||
this.push(null); | ||
} | ||
@@ -102,24 +100,24 @@ | ||
self._shot.isDone = true; | ||
this._shot.isDone = true; | ||
if (self._shot.payload) { | ||
if (self._shot.simulate.split) { | ||
self.push(self._shot.payload.slice(0, 1)); | ||
self.push(self._shot.payload.slice(1)); | ||
if (this._shot.payload) { | ||
if (this._shot.simulate.split) { | ||
this.push(this._shot.payload.slice(0, 1)); | ||
this.push(this._shot.payload.slice(1)); | ||
} | ||
else { | ||
self.push(self._shot.payload); | ||
this.push(this._shot.payload); | ||
} | ||
} | ||
if (self._shot.simulate.error) { | ||
self.emit('error', new Error('Simulated')); | ||
if (this._shot.simulate.error) { | ||
this.emit('error', new Error('Simulated')); | ||
} | ||
if (self._shot.simulate.close) { | ||
self.emit('close'); | ||
if (this._shot.simulate.close) { | ||
this.emit('close'); | ||
} | ||
if (self._shot.simulate.end !== false) { // 'end' defaults to true | ||
self.push(null); | ||
if (this._shot.simulate.end !== false) { // 'end' defaults to true | ||
this.push(null); | ||
} | ||
@@ -149,10 +147,8 @@ }); | ||
var self = this; | ||
const headers = ((arguments.length === 2 && typeof arguments[1] === 'object') ? arguments[1] : (arguments.length === 3 ? arguments[2] : {})); | ||
const result = Http.ServerResponse.prototype.writeHead.apply(this, arguments); | ||
var headers = ((arguments.length === 2 && typeof arguments[1] === 'object') ? arguments[1] : (arguments.length === 3 ? arguments[2] : {})); | ||
var result = Http.ServerResponse.prototype.writeHead.apply(this, arguments); | ||
this._headers = this._headers || {}; | ||
var keys = Object.keys(headers); | ||
for (var i = 0, il = keys.length; i < il; ++i) { | ||
const keys = Object.keys(headers); | ||
for (let i = 0; i < keys.length; ++i) { | ||
this._headers[keys[i]] = headers[keys[i]]; | ||
@@ -163,8 +159,8 @@ } | ||
['Date', 'Connection', 'Transfer-Encoding'].forEach(function (name) { | ||
['Date', 'Connection', 'Transfer-Encoding'].forEach((name) => { | ||
var regex = new RegExp('\\r\\n' + name + ': ([^\\r]*)\\r\\n'); | ||
var field = self._header.match(regex); | ||
const regex = new RegExp('\\r\\n' + name + ': ([^\\r]*)\\r\\n'); | ||
const field = this._header.match(regex); | ||
if (field) { | ||
self._headers[name.toLowerCase()] = field[1]; | ||
this._headers[name.toLowerCase()] = field[1]; | ||
} | ||
@@ -202,3 +198,3 @@ }); | ||
var res = { | ||
const res = { | ||
raw: { | ||
@@ -214,3 +210,3 @@ req: req, | ||
process.nextTick(function () { | ||
process.nextTick(() => { | ||
@@ -222,11 +218,11 @@ onEnd(res); | ||
var raw = []; | ||
var rawLength = 0; | ||
for (var i = 0, il = response.output.length; i < il; ++i) { | ||
var chunk = (response.output[i] instanceof Buffer ? response.output[i] : new Buffer(response.output[i], response.outputEncodings[i])); | ||
const raw = []; | ||
let rawLength = 0; | ||
for (let i = 0; i < response.output.length; ++i) { | ||
const chunk = (response.output[i] instanceof Buffer ? response.output[i] : new Buffer(response.output[i], response.outputEncodings[i])); | ||
raw.push(chunk); | ||
rawLength += chunk.length; | ||
rawLength = rawLength + chunk.length; | ||
} | ||
var rawBuffer = Buffer.concat(raw, rawLength); | ||
const rawBuffer = Buffer.concat(raw, rawLength); | ||
@@ -236,6 +232,6 @@ // Parse payload | ||
var CRLF = '\r\n'; | ||
var sep = new Buffer(CRLF + CRLF); | ||
var parts = internals.splitBufferInTwo(rawBuffer, sep); | ||
var payloadBuffer = parts[1]; | ||
const CRLF = '\r\n'; | ||
const sep = new Buffer(CRLF + CRLF); | ||
const parts = internals.splitBufferInTwo(rawBuffer, sep); | ||
const payloadBuffer = parts[1]; | ||
@@ -248,9 +244,10 @@ if (!res.headers['transfer-encoding']) { | ||
var CRLFBuffer = new Buffer(CRLF); | ||
var rest = payloadBuffer; | ||
var payloadBytes = []; | ||
const CRLFBuffer = new Buffer(CRLF); | ||
let rest = payloadBuffer; | ||
let payloadBytes = []; | ||
let size; | ||
do { | ||
var payloadParts = internals.splitBufferInTwo(rest, CRLFBuffer); | ||
var next = payloadParts[1]; | ||
var size = parseInt(payloadParts[0].toString(), 16); | ||
const payloadParts = internals.splitBufferInTwo(rest, CRLFBuffer); | ||
const next = payloadParts[1]; | ||
size = parseInt(payloadParts[0].toString(), 16); | ||
if (size === 0) { | ||
@@ -260,3 +257,3 @@ rest = next; | ||
else { | ||
var nextData = next.slice(0, size); | ||
const nextData = next.slice(0, size); | ||
payloadBytes = payloadBytes.concat(Array.prototype.slice.call(nextData, 0)); | ||
@@ -270,6 +267,6 @@ rest = next.slice(size + 2); | ||
res.payload = res.rawPayload.toString('utf8'); | ||
var headers = rest.toString().split(CRLF); | ||
headers.forEach(function (header) { | ||
const headers = rest.toString().split(CRLF); | ||
headers.forEach((header) => { | ||
var headerParts = header.split(':'); | ||
const headerParts = header.split(':'); | ||
if (headerParts.length === 2) { | ||
@@ -285,6 +282,6 @@ response._headers[headerParts[0].trim().toLowerCase()] = headerParts[1].trim(); | ||
for (var i = 0, max = buffer.length - seperator.length; i < max; ++i) { | ||
for (let i = 0; i < buffer.length - seperator.length; ++i) { | ||
if (internals.bufferEqual(buffer.slice(i, i + seperator.length), seperator)) { | ||
var part1 = buffer.slice(0, i); | ||
var part2 = buffer.slice(i + seperator.length); | ||
const part1 = buffer.slice(0, i); | ||
const part2 = buffer.slice(i + seperator.length); | ||
return [part1, part2]; | ||
@@ -301,6 +298,6 @@ } | ||
options = (typeof options === 'string' ? { url: options } : options); | ||
var settings = Hoek.applyToDefaults({ method: 'GET' }, options); | ||
const settings = Hoek.applyToDefaults({ method: 'GET' }, options); | ||
var req = new internals.Request(settings); | ||
var res = new internals.Response(req, callback); | ||
const req = new internals.Request(settings); | ||
const res = new internals.Response(req, callback); | ||
dispatchFunc(req, res); | ||
@@ -318,3 +315,3 @@ }; | ||
for (var i = 0, il = a.length; i < il; ++i) { | ||
for (let i = 0; i < a.length; ++i) { | ||
if (a[i] !== b[i]) { | ||
@@ -321,0 +318,0 @@ return false; |
{ | ||
"name": "shot", | ||
"description": "Injects a fake HTTP request/response into a node HTTP server", | ||
"version": "1.7.0", | ||
"version": "2.0.1", | ||
"repository": "git://github.com/hapijs/shot", | ||
@@ -14,10 +14,10 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.10.40" | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"hoek": "2.x.x" | ||
"hoek": "3.x.x" | ||
}, | ||
"devDependencies": { | ||
"lab": "5.x.x", | ||
"code": "1.x.x" | ||
"code": "2.x.x", | ||
"lab": "7.x.x" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
@@ -0,14 +1,16 @@ | ||
'use strict'; | ||
// Load modules | ||
var Util = require('util'); | ||
var Stream = require('stream'); | ||
var Fs = require('fs'); | ||
var Zlib = require('zlib'); | ||
var Lab = require('lab'); | ||
var Shot = require('../lib'); | ||
var Code = require('code'); | ||
const Util = require('util'); | ||
const Stream = require('stream'); | ||
const Fs = require('fs'); | ||
const Zlib = require('zlib'); | ||
const Lab = require('lab'); | ||
const Shot = require('../lib'); | ||
const Code = require('code'); | ||
// Declare internals | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -18,15 +20,15 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
const expect = Code.expect; | ||
describe('inject()', function () { | ||
describe('inject()', () => { | ||
it('returns non-chunked payload', function (done) { | ||
it('returns non-chunked payload', (done) => { | ||
var output = 'example.com:8080|/hello'; | ||
const output = 'example.com:8080|/hello'; | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -37,3 +39,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': output.length }); | ||
Shot.inject(dispatch, 'http://example.com:8080/hello', function (res) { | ||
Shot.inject(dispatch, 'http://example.com:8080/hello', (res) => { | ||
@@ -49,5 +51,5 @@ expect(res.headers.date).to.exist(); | ||
it('returns single buffer payload', function (done) { | ||
it('returns single buffer payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -58,3 +60,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { url: 'http://example.com:8080/hello' }, function (res) { | ||
Shot.inject(dispatch, { url: 'http://example.com:8080/hello' }, (res) => { | ||
@@ -70,5 +72,5 @@ expect(res.headers.date).to.exist(); | ||
it('passes headers', function (done) { | ||
it('passes headers', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -79,3 +81,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello', headers: { Super: 'duper' } }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello', headers: { Super: 'duper' } }, (res) => { | ||
@@ -87,5 +89,5 @@ expect(res.payload).to.equal('duper'); | ||
it('passes remote address', function (done) { | ||
it('passes remote address', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -96,3 +98,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello', remoteAddress: '1.2.3.4' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello', remoteAddress: '1.2.3.4' }, (res) => { | ||
@@ -104,5 +106,5 @@ expect(res.payload).to.equal('1.2.3.4'); | ||
it('passes localhost as default remote address', function (done) { | ||
it('passes localhost as default remote address', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -113,3 +115,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello' }, (res) => { | ||
@@ -121,5 +123,5 @@ expect(res.payload).to.equal('127.0.0.1'); | ||
it('passes host option as host header', function (done) { | ||
it('passes host option as host header', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -130,3 +132,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'get', url: '/hello', headers: { host: 'test.example.com' } }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/hello', headers: { host: 'test.example.com' } }, (res) => { | ||
@@ -138,5 +140,5 @@ expect(res.payload).to.equal('test.example.com'); | ||
it('passes localhost as default host header', function (done) { | ||
it('passes localhost as default host header', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -147,3 +149,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'get', url: '/hello' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/hello' }, (res) => { | ||
@@ -155,5 +157,5 @@ expect(res.payload).to.equal('localhost'); | ||
it('passes authority as host header', function (done) { | ||
it('passes authority as host header', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -164,3 +166,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'get', url: '/hello', authority: 'something' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/hello', authority: 'something' }, (res) => { | ||
@@ -172,5 +174,5 @@ expect(res.payload).to.equal('something'); | ||
it('passes uri host as host header', function (done) { | ||
it('passes uri host as host header', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -181,3 +183,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello' }, (res) => { | ||
@@ -189,7 +191,7 @@ expect(res.payload).to.equal('example.com:8080'); | ||
it('optionally accepts an object as url', function (done) { | ||
it('optionally accepts an object as url', (done) => { | ||
var output = 'example.com:8080|/hello?test=1234'; | ||
const output = 'example.com:8080|/hello?test=1234'; | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -200,3 +202,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': output.length }); | ||
var url = { | ||
const url = { | ||
protocol: 'http', | ||
@@ -211,3 +213,3 @@ hostname: 'example.com', | ||
Shot.inject(dispatch, { url: url }, function (res) { | ||
Shot.inject(dispatch, { url: url }, (res) => { | ||
@@ -222,5 +224,5 @@ expect(res.headers.date).to.exist(); | ||
it('leaves user-agent unmodified', function (done) { | ||
it('leaves user-agent unmodified', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -231,3 +233,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello', headers: { 'user-agent': 'duper' } }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello', headers: { 'user-agent': 'duper' } }, (res) => { | ||
@@ -239,5 +241,5 @@ expect(res.payload).to.equal('duper'); | ||
it('returns chunked payload', function (done) { | ||
it('returns chunked payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -250,3 +252,3 @@ res.writeHead(200, 'OK'); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -261,5 +263,5 @@ expect(res.headers.date).to.exist(); | ||
it('returns chunked payload with trailer', function (done) { | ||
it('returns chunked payload with trailer', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -275,3 +277,3 @@ res.setHeader('Trailer', 'Server-Authorization'); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -284,16 +286,16 @@ expect(res.payload).to.equal('ab'); | ||
it('parses zipped payload', function (done) { | ||
it('parses zipped payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
res.writeHead(200, 'OK'); | ||
var stream = Fs.createReadStream('./package.json'); | ||
const stream = Fs.createReadStream('./package.json'); | ||
stream.pipe(Zlib.createGzip()).pipe(res); | ||
}; | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
Fs.readFile('./package.json', { encoding: 'utf-8' }, function (err, file) { | ||
Fs.readFile('./package.json', { encoding: 'utf-8' }, (err, file) => { | ||
Zlib.unzip(res.rawPayload, function (err, unzipped) { | ||
Zlib.unzip(res.rawPayload, (err, unzipped) => { | ||
@@ -308,5 +310,5 @@ expect(err).to.not.exist(); | ||
it('returns multi buffer payload', function (done) { | ||
it('returns multi buffer payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -319,3 +321,3 @@ res.writeHead(200); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -327,5 +329,5 @@ expect(res.payload).to.equal('ab'); | ||
it('returns null payload', function (done) { | ||
it('returns null payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -336,3 +338,3 @@ res.writeHead(200, { 'Content-Length': 0 }); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -344,5 +346,5 @@ expect(res.payload).to.equal(''); | ||
it('allows ending twice', function (done) { | ||
it('allows ending twice', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -354,3 +356,3 @@ res.writeHead(200, { 'Content-Length': 0 }); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -362,5 +364,5 @@ expect(res.payload).to.equal(''); | ||
it('identifies injection object', function (done) { | ||
it('identifies injection object', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -374,3 +376,3 @@ expect(Shot.isInjection(req)).to.equal(true); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -381,5 +383,5 @@ done(); | ||
it('pipes response', function (done) { | ||
it('pipes response', (done) => { | ||
var Read = function () { | ||
const Read = function () { | ||
@@ -397,9 +399,9 @@ Stream.Readable.call(this); | ||
var finished = false; | ||
var dispatch = function (req, res) { | ||
let finished = false; | ||
const dispatch = function (req, res) { | ||
res.writeHead(200); | ||
var stream = new Read(); | ||
const stream = new Read(); | ||
res.on('finish', function () { | ||
res.on('finish', () => { | ||
@@ -412,3 +414,3 @@ finished = true; | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -421,5 +423,5 @@ expect(finished).to.equal(true); | ||
it('pipes response with old stream', function (done) { | ||
it('pipes response with old stream', (done) => { | ||
var Read = function () { | ||
const Read = function () { | ||
@@ -437,12 +439,12 @@ Stream.Readable.call(this); | ||
var finished = false; | ||
var dispatch = function (req, res) { | ||
let finished = false; | ||
const dispatch = function (req, res) { | ||
res.writeHead(200); | ||
var stream = new Read(); | ||
const stream = new Read(); | ||
stream.pause(); | ||
var stream2 = new Stream.Readable().wrap(stream); | ||
const stream2 = new Stream.Readable().wrap(stream); | ||
stream.resume(); | ||
res.on('finish', function () { | ||
res.on('finish', () => { | ||
@@ -455,3 +457,3 @@ finished = true; | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -464,5 +466,5 @@ expect(finished).to.equal(true); | ||
it('echos object payload', function (done) { | ||
it('echos object payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -473,3 +475,3 @@ res.writeHead(200, { 'content-type': req.headers['content-type'] }); | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: { a: 1 } }, function (res) { | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: { a: 1 } }, (res) => { | ||
@@ -482,5 +484,5 @@ expect(res.headers['content-type']).to.equal('application/json'); | ||
it('echos buffer payload', function (done) { | ||
it('echos buffer payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -491,3 +493,3 @@ res.writeHead(200, { 'content-type': req.headers['content-type'] }); | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: new Buffer('test!') }, function (res) { | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: new Buffer('test!') }, (res) => { | ||
@@ -499,5 +501,5 @@ expect(res.payload).to.equal('test!'); | ||
it('echos object payload with non-english utf-8 string', function (done) { | ||
it('echos object payload with non-english utf-8 string', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -508,3 +510,3 @@ res.writeHead(200, { 'content-type': req.headers['content-type'] }); | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: { a: '½½א' } }, function (res) { | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: { a: '½½א' } }, (res) => { | ||
@@ -517,5 +519,5 @@ expect(res.headers['content-type']).to.equal('application/json'); | ||
it('echos object payload without payload', function (done) { | ||
it('echos object payload without payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -526,3 +528,3 @@ res.writeHead(200); | ||
Shot.inject(dispatch, { method: 'post', url: '/test' }, function (res) { | ||
Shot.inject(dispatch, { method: 'post', url: '/test' }, (res) => { | ||
@@ -534,5 +536,5 @@ expect(res.payload).to.equal(''); | ||
it('retains content-type header', function (done) { | ||
it('retains content-type header', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -543,3 +545,3 @@ res.writeHead(200, { 'content-type': req.headers['content-type'] }); | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: { a: 1 }, headers: { 'content-type': 'something' } }, function (res) { | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: { a: 1 }, headers: { 'content-type': 'something' } }, (res) => { | ||
@@ -552,5 +554,5 @@ expect(res.headers['content-type']).to.equal('something'); | ||
it('adds a content-length header if none set when payload specified', function (done) { | ||
it('adds a content-length header if none set when payload specified', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -561,3 +563,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: { a: 1 } }, function (res) { | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: { a: 1 } }, (res) => { | ||
@@ -570,5 +572,5 @@ expect(res.payload).to.equal('{"a":1}'.length.toString()); | ||
it('retains a content-length header when payload specified', function (done) { | ||
it('retains a content-length header when payload specified', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
@@ -579,3 +581,3 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: '', headers: { 'content-length': '10' } }, function (res) { | ||
Shot.inject(dispatch, { method: 'post', url: '/test', payload: '', headers: { 'content-length': '10' } }, (res) => { | ||
@@ -589,8 +591,8 @@ expect(res.payload).to.equal('10'); | ||
describe('writeHead()', function () { | ||
describe('writeHead()', () => { | ||
it('returns single buffer payload', function (done) { | ||
it('returns single buffer payload', (done) => { | ||
var reply = 'Hello World'; | ||
var dispatch = function (req, res) { | ||
const reply = 'Hello World'; | ||
const dispatch = function (req, res) { | ||
@@ -601,3 +603,3 @@ res.writeHead(200, 'OK', { 'Content-Type': 'text/plain', 'Content-Length': reply.length }); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { | ||
@@ -610,21 +612,21 @@ expect(res.payload).to.equal(reply); | ||
describe('_read()', function () { | ||
describe('_read()', () => { | ||
it('plays payload', function (done) { | ||
it('plays payload', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
var buffer = ''; | ||
req.on('readable', function () { | ||
let buffer = ''; | ||
req.on('readable', () => { | ||
buffer += req.read() || ''; | ||
buffer = buffer + (req.read() || ''); | ||
}); | ||
req.on('error', function (err) { | ||
req.on('error', (err) => { | ||
}); | ||
req.on('close', function () { | ||
req.on('close', () => { | ||
}); | ||
req.on('end', function () { | ||
req.on('end', () => { | ||
@@ -637,4 +639,4 @@ res.writeHead(200, { 'Content-Length': 0 }); | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body }, function (res) { | ||
const body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body }, (res) => { | ||
@@ -646,19 +648,19 @@ expect(res.payload).to.equal(body); | ||
it('simulates split', function (done) { | ||
it('simulates split', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
var buffer = ''; | ||
req.on('readable', function () { | ||
let buffer = ''; | ||
req.on('readable', () => { | ||
buffer += req.read() || ''; | ||
buffer = buffer + (req.read() || ''); | ||
}); | ||
req.on('error', function (err) { | ||
req.on('error', (err) => { | ||
}); | ||
req.on('close', function () { | ||
req.on('close', () => { | ||
}); | ||
req.on('end', function () { | ||
req.on('end', () => { | ||
@@ -671,4 +673,4 @@ res.writeHead(200, { 'Content-Length': 0 }); | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { split: true } }, function (res) { | ||
const body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { split: true } }, (res) => { | ||
@@ -680,10 +682,10 @@ expect(res.payload).to.equal(body); | ||
it('simulates error', function (done) { | ||
it('simulates error', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
req.on('readable', function () { | ||
req.on('readable', () => { | ||
}); | ||
req.on('error', function (err) { | ||
req.on('error', (err) => { | ||
@@ -695,4 +697,4 @@ res.writeHead(200, { 'Content-Length': 0 }); | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { error: true } }, function (res) { | ||
const body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { error: true } }, (res) => { | ||
@@ -704,9 +706,9 @@ expect(res.payload).to.equal('error'); | ||
it('simulates no end without payload', function (done) { | ||
it('simulates no end without payload', (done) => { | ||
var end = false; | ||
var dispatch = function (req, res) { | ||
let end = false; | ||
const dispatch = function (req, res) { | ||
req.resume(); | ||
req.on('end', function () { | ||
req.on('end', () => { | ||
@@ -717,4 +719,4 @@ end = true; | ||
var replied = false; | ||
Shot.inject(dispatch, { method: 'get', url: '/', simulate: { end: false } }, function (res) { | ||
let replied = false; | ||
Shot.inject(dispatch, { method: 'get', url: '/', simulate: { end: false } }, (res) => { | ||
@@ -724,3 +726,3 @@ replied = true; | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
@@ -733,9 +735,9 @@ expect(end).to.equal(false); | ||
it('simulates no end with payload', function (done) { | ||
it('simulates no end with payload', (done) => { | ||
var end = false; | ||
var dispatch = function (req, res) { | ||
let end = false; | ||
const dispatch = function (req, res) { | ||
req.resume(); | ||
req.on('end', function () { | ||
req.on('end', () => { | ||
@@ -746,4 +748,4 @@ end = true; | ||
var replied = false; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: '1234567', simulate: { end: false } }, function (res) { | ||
let replied = false; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: '1234567', simulate: { end: false } }, (res) => { | ||
@@ -753,3 +755,3 @@ replied = true; | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
@@ -762,16 +764,16 @@ expect(end).to.equal(false); | ||
it('simulates close', function (done) { | ||
it('simulates close', (done) => { | ||
var dispatch = function (req, res) { | ||
const dispatch = function (req, res) { | ||
var buffer = ''; | ||
req.on('readable', function () { | ||
let buffer = ''; | ||
req.on('readable', () => { | ||
buffer += req.read() || ''; | ||
buffer = buffer + (req.read() || ''); | ||
}); | ||
req.on('error', function (err) { | ||
req.on('error', (err) => { | ||
}); | ||
req.on('close', function () { | ||
req.on('close', () => { | ||
@@ -782,8 +784,8 @@ res.writeHead(200, { 'Content-Length': 0 }); | ||
req.on('end', function () { | ||
req.on('end', () => { | ||
}); | ||
}; | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { close: true } }, function (res) { | ||
const body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { close: true } }, (res) => { | ||
@@ -790,0 +792,0 @@ expect(res.payload).to.equal('close'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
72705
721
+ Addedhoek@3.0.4(transitive)
- Removedhoek@2.16.3(transitive)
Updatedhoek@3.x.x