Skip to content

Commit d1b5f52

Browse files
committed
Add tests for multi-callback chaining
1 parent b83f360 commit d1b5f52

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"glob": "~3.1.13",
4141
"istanbul": "^0.4.3",
4242
"koa": "*",
43-
"mocha": "*",
44-
"nock": "~0.28.2",
43+
"mocha": "~3.1.2",
44+
"nock": "~9.0.0",
4545
"should": "~3.3.1"
4646
}
4747
}

test/raven.client.js

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,11 @@ describe('raven.Client', function () {
280280
});
281281

282282
afterEach(function () {
283+
process.removeAllListeners('uncaughtException');
283284
var uncaughtBefore = this.uncaughtBefore;
284285
// restore things to how they were
285286
for (var i = 0; i < uncaughtBefore.length; i++) {
286-
process.addListener('uncaughtException', uncaughtBefore[i]);
287+
process.on('uncaughtException', uncaughtBefore[i]);
287288
}
288289
});
289290

@@ -400,6 +401,80 @@ describe('raven.Client', function () {
400401
});
401402
});
402403

404+
it('should pass original shouldSendCallback to newer shouldSendCallback', function (done) {
405+
var cb1 = function (data) {
406+
return false;
407+
};
408+
409+
var cb2 = function (data, original) {
410+
original.should.equal(cb1);
411+
return original(data);
412+
};
413+
414+
var cb3 = function (data, original) {
415+
return original(data);
416+
};
417+
418+
client = new raven.Client(dsn, {
419+
shouldSendCallback: cb1,
420+
});
421+
422+
client.setShouldSendCallback(cb2);
423+
client.setShouldSendCallback(cb3);
424+
425+
// neither of these should fire, so report err to done if they do
426+
client.on('logged', done);
427+
client.on('error', done);
428+
429+
client.process({
430+
message: 'test'
431+
}, function (err, eventId) {
432+
setTimeout(done, 10);
433+
});
434+
});
435+
436+
it('should pass original dataCallback to newer dataCallback', function (done) {
437+
var scope = nock('https://app.getsentry.com')
438+
.filteringRequestBody(/.*/, '*')
439+
.post('/api/269/store/', '*')
440+
.reply(200, function (uri, body, cb) {
441+
zlib.inflate(new Buffer(body, 'base64'), function (err, dec) {
442+
if (err) return done(err);
443+
var msg = JSON.parse(dec.toString());
444+
msg.extra.foo.should.equal('bar');
445+
cb(null, 'OK');
446+
});
447+
});
448+
449+
var cb1 = function (data) {
450+
data.extra = { foo: 'bar' };
451+
return data;
452+
};
453+
454+
var cb2 = function (data, original) {
455+
original.should.equal(cb1);
456+
return original(data);
457+
};
458+
459+
var cb3 = function (data, original) {
460+
return original(data);
461+
};
462+
463+
client = new raven.Client(dsn, {
464+
dataCallback: cb1,
465+
});
466+
467+
client.setDataCallback(cb2);
468+
client.setDataCallback(cb3);
469+
470+
client.process({
471+
message: 'test'
472+
}, function (err, eventId) {
473+
scope.done();
474+
done();
475+
});
476+
});
477+
403478
it('should call the callback after sending', function (done) {
404479
var firedCallback = false;
405480
var sentResponse = false;

0 commit comments

Comments
 (0)