Comparing version 0.1.2 to 0.1.3
@@ -0,0 +0,0 @@ // Load modules |
{ | ||
"name": "shot", | ||
"description": "Injects a fake HTTP request/response into a node HTTP server", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -22,11 +22,7 @@ "contributors":[ | ||
"devDependencies": { | ||
"mocha": "1.x.x", | ||
"chai": "1.x.x", | ||
"blanket": "1.0.x", | ||
"travis-cov": "0.2.x" | ||
"lab": "0.0.x", | ||
"complexity-report": "0.x.x" | ||
}, | ||
"scripts": { | ||
"test": "make test && make test-cov", | ||
"blanket": { "pattern": "//^((?!\/node_modules\/)(?!\/test\/).)*$/ig", "onlyCwd": true, "data-cover-flags": { "branchTracking": true } }, | ||
"travis-cov": { "threshold": 100 } | ||
"test": "make test-cov" | ||
}, | ||
@@ -33,0 +29,0 @@ "licenses": [ |
// Load modules | ||
var Chai = require('chai'); | ||
var Lab = require('lab'); | ||
var Shot = require('../lib'); | ||
@@ -14,3 +14,7 @@ | ||
var expect = Chai.expect; | ||
var expect = Lab.expect; | ||
var before = Lab.before; | ||
var after = Lab.after; | ||
var describe = Lab.experiment; | ||
var it = Lab.test; | ||
@@ -42,3 +46,3 @@ | ||
res.writeHead(200); | ||
res.writeHead(200, 'OK'); | ||
res.write('a'); | ||
@@ -120,172 +124,191 @@ res.write('b'); | ||
}); | ||
}); | ||
describe('#play', function () { | ||
describe('#writeHead', function () { | ||
it('plays payload', function (done) { | ||
it('returns single buffer payload', function (done) { | ||
var dispatch = function (req, res) { | ||
var reply = 'Hello World'; | ||
var dispatch = function (req, res) { | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
res.writeHead(200, 'OK', { 'Content-Type': 'text/plain', 'Content-Length': reply.length }); | ||
res.end(reply); | ||
}; | ||
buffer += chunk; | ||
}); | ||
Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) { | ||
req.on('error', function (err) { | ||
}); | ||
expect(res.payload).to.equal(reply); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
req.on('close', function () { | ||
}); | ||
describe('#play', function () { | ||
req.on('end', function () { | ||
it('plays payload', function (done) { | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end(buffer); | ||
req.destroy(); | ||
}); | ||
}; | ||
var dispatch = function (req, res) { | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body }, function (res) { | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
expect(res.payload).to.equal(body); | ||
done(); | ||
buffer += chunk; | ||
}); | ||
req.on('error', function (err) { | ||
}); | ||
req.on('close', function () { | ||
}); | ||
req.on('end', function () { | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end(buffer); | ||
req.destroy(); | ||
}); | ||
}; | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body }, function (res) { | ||
expect(res.payload).to.equal(body); | ||
done(); | ||
}); | ||
}); | ||
it('plays payload with pause', function (done) { | ||
it('plays payload with pause', function (done) { | ||
var dispatch = function (req, res) { | ||
var dispatch = function (req, res) { | ||
req.pause(); | ||
req.pause(); | ||
req.pause(); | ||
req.pause(); | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
buffer += chunk; | ||
}); | ||
buffer += chunk; | ||
}); | ||
req.on('error', function (err) { | ||
}); | ||
req.on('error', function (err) { | ||
}); | ||
req.on('close', function () { | ||
}); | ||
req.on('close', function () { | ||
}); | ||
req.on('end', function () { | ||
req.on('end', function () { | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end(buffer); | ||
req.destroy(); | ||
}); | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end(buffer); | ||
req.destroy(); | ||
}); | ||
req.resume(); | ||
req.resume(); | ||
}; | ||
req.resume(); | ||
req.resume(); | ||
}; | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body }, function (res) { | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body }, function (res) { | ||
expect(res.payload).to.equal(body); | ||
done(); | ||
}); | ||
expect(res.payload).to.equal(body); | ||
done(); | ||
}); | ||
}); | ||
it('plays payload with nextTick', function (done) { | ||
it('plays payload with nextTick', function (done) { | ||
var dispatch = function (req, res) { | ||
var dispatch = function (req, res) { | ||
req.pause(); | ||
req.pause(); | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
buffer += chunk; | ||
}); | ||
buffer += chunk; | ||
}); | ||
req.on('error', function (err) { | ||
}); | ||
req.on('error', function (err) { | ||
}); | ||
req.on('close', function () { | ||
}); | ||
req.on('close', function () { | ||
}); | ||
req.on('end', function () { | ||
req.on('end', function () { | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end(buffer); | ||
req.destroy(); | ||
}); | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end(buffer); | ||
req.destroy(); | ||
}); | ||
process.nextTick(function () { | ||
process.nextTick(function () { | ||
req.resume(); | ||
}); | ||
}; | ||
req.resume(); | ||
}); | ||
}; | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body }, function (res) { | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body }, function (res) { | ||
expect(res.payload).to.equal(body); | ||
done(); | ||
}); | ||
expect(res.payload).to.equal(body); | ||
done(); | ||
}); | ||
}); | ||
it('simulates error', function (done) { | ||
it('simulates error', function (done) { | ||
var dispatch = function (req, res) { | ||
var dispatch = function (req, res) { | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
buffer += chunk; | ||
}); | ||
buffer += chunk; | ||
}); | ||
req.on('error', function (err) { | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end('error'); | ||
}); | ||
req.on('error', function (err) { | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end('error'); | ||
}); | ||
req.on('close', function () { | ||
}); | ||
req.on('close', function () { | ||
}); | ||
req.on('end', function () { | ||
}); | ||
}; | ||
req.on('end', function () { | ||
}); | ||
}; | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { error: true } }, function (res) { | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { error: true } }, function (res) { | ||
expect(res.payload).to.equal('error'); | ||
done(); | ||
}); | ||
expect(res.payload).to.equal('error'); | ||
done(); | ||
}); | ||
}); | ||
it('simulates close', function (done) { | ||
it('simulates close', function (done) { | ||
var dispatch = function (req, res) { | ||
var dispatch = function (req, res) { | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
var buffer = ''; | ||
req.on('data', function (chunk) { | ||
buffer += chunk; | ||
}); | ||
buffer += chunk; | ||
}); | ||
req.on('error', function (err) { | ||
}); | ||
req.on('error', function (err) { | ||
}); | ||
req.on('close', function () { | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end('close'); | ||
}); | ||
req.on('close', function () { | ||
res.writeHead(200, { 'Content-Length': 0 }); | ||
res.end('close'); | ||
}); | ||
req.on('end', function () { | ||
}); | ||
}; | ||
req.on('end', function () { | ||
}); | ||
}; | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { close: true } }, function (res) { | ||
var body = 'something special just for you'; | ||
Shot.inject(dispatch, { method: 'get', url: '/', payload: body, simulate: { close: true } }, function (res) { | ||
expect(res.payload).to.equal('close'); | ||
done(); | ||
}); | ||
expect(res.payload).to.equal('close'); | ||
done(); | ||
}); | ||
@@ -292,0 +315,0 @@ }); |
Sorry, the diff of this file is not supported yet
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
2
400
57627