Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Apr 5, 2013
1 parent ed6542d commit dace161
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
35 changes: 14 additions & 21 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ internals.Request = function (options) {
// Use _shot namespace to avoid collision with Node

this._shot = {
payload: options.payload,
payload: options.payload || null,
listeners: {},
isPlayed: false,
isDone: false,
simulate: options.simulate || {}
};

Expand All @@ -41,43 +41,36 @@ Util.inherits(internals.Request, Stream.Readable);

internals.Request.prototype._read = function (size) {

if (this._shot.isPlayed) {
var self = this;

if (this._shot.isDone) {
this.push(null);
return;
}

this._shot.isPlayed = true;
this._shot.isDone = true;

if (this._shot.payload) {
this.push(this._shot.payload);
}

this.once('readable', function () {
setImmediate(function () {

if (this._shot.simulate.error) {
this.emit('error', new Error('Simulated'));
if (self._shot.simulate.error) {
self.emit('error', new Error('Simulated'));
}

if (this._shot.simulate.close) {
this.emit('close');
if (self._shot.simulate.close) {
self.emit('close');
}

if (this._shot.simulate.end !== false) { // 'end' defaults to true
this.push(null);
if (self._shot.simulate.end !== false) { // 'end' defaults to true
self.push(null);
}
});
};


internals.Request.prototype.setEncoding = function () {

};


internals.Request.prototype.destroy = function () {

};


internals.Response = function (req, onEnd) {

Http.ServerResponse.call(this, { method: req.method, httpVersionMajor: 1, httpVersionMinor: 1 });
Expand Down
16 changes: 8 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ describe('Shot', function () {
var dispatch = function (req, res) {

var buffer = '';
req.on('readable', function () {
req.on('readable', function () {

buffer += req.read();
buffer += req.read();
});

req.on('error', function (err) {
Expand Down Expand Up @@ -181,10 +181,10 @@ describe('Shot', function () {
var dispatch = function (req, res) {

var buffer = '';
req.on('readable', function () {
req.on('readable', function () {

buffer += req.read();
});
buffer += req.read();
});

req.on('error', function (err) {

Expand Down Expand Up @@ -212,10 +212,10 @@ describe('Shot', function () {
var dispatch = function (req, res) {

var buffer = '';
req.on('readable', function () {
req.on('readable', function () {

buffer += req.read();
});
buffer += req.read();
});

req.on('error', function (err) {
});
Expand Down

0 comments on commit dace161

Please sign in to comment.