Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Add tests for multi-callback chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisJEllis committed Oct 26, 2016
1 parent ab8ec24 commit 891bf7d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"glob": "~3.1.13",
"istanbul": "^0.4.3",
"koa": "*",
"mocha": "*",
"nock": "~0.28.2",
"mocha": "~3.1.2",
"nock": "~9.0.0",
"should": "~3.3.1"
}
}
78 changes: 77 additions & 1 deletion test/raven.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ describe('raven.Client', function () {
});

afterEach(function () {
process.removeAllListeners('uncaughtException');
var uncaughtBefore = this.uncaughtBefore;
// restore things to how they were
for (var i = 0; i < uncaughtBefore.length; i++) {
process.addListener('uncaughtException', uncaughtBefore[i]);
process.on('uncaughtException', uncaughtBefore[i]);
}
});

Expand Down Expand Up @@ -400,6 +401,81 @@ describe('raven.Client', function () {
});
});

it('should pass original shouldSendCallback to newer shouldSendCallback', function (done) {
var cb1 = function (data) {
return false;
};

var cb2 = function (data, original) {
original.should.equal(cb1);
return original(data);
};

var cb3 = function (data, original) {
return original(data);
};

client = new raven.Client(dsn, {
shouldSendCallback: cb1,
});

client.setShouldSendCallback(cb2);
client.setShouldSendCallback(cb3);

// neither of these should fire, so report err to done if they do
client.on('logged', done);
client.on('error', done);

client.process({
message: 'test'
}, function (err, eventId) {
setTimeout(done, 10);
});
});

it('should pass original dataCallback to newer dataCallback', function (done) {
var scope = nock('https://app.getsentry.com')
.filteringRequestBody(/.*/, '*')
.post('/api/269/store/', '*')
.reply(200, function (uri, body, cb) {
console.log(typeof cb);
zlib.inflate(new Buffer(body, 'base64'), function (err, dec) {
if (err) return done(err);
var msg = JSON.parse(dec.toString());
msg.extra.foo.should.equal('bar');
cb(null, 'OK');
});
});

var cb1 = function (data) {
data.extra = { foo: 'bar' };
return data;
};

var cb2 = function (data, original) {
original.should.equal(cb1);
return original(data);
};

var cb3 = function (data, original) {
return original(data);
};

client = new raven.Client(dsn, {
dataCallback: cb1,
});

client.setDataCallback(cb2);
client.setDataCallback(cb3);

client.process({
message: 'test'
}, function (err, eventId) {
scope.done();
done();
});
});

it('should call the callback after sending', function (done) {
var firedCallback = false;
var sentResponse = false;
Expand Down

0 comments on commit 891bf7d

Please sign in to comment.