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

Commit d1217ce

Browse files
committed
Add failing test for sending empty req details when there's no req (#321)
1 parent f39bf9a commit d1217ce

1 file changed

Lines changed: 76 additions & 42 deletions

File tree

test/raven.client.js

Lines changed: 76 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,82 @@ describe('raven.Client', function () {
675675
environment: 'production'
676676
});
677677
});
678+
679+
describe('context parsing', function () {
680+
afterEach(function () {
681+
process.domain && process.domain.exit();
682+
});
683+
684+
it('should parse a req property from context', function (done) {
685+
var scope = nock('https://app.getsentry.com')
686+
.filteringRequestBody(/.*/, '*')
687+
.post('/api/269/store/', '*')
688+
.reply(200, function (uri, body) {
689+
zlib.inflate(new Buffer(body, 'base64'), function (err, dec) {
690+
if (err) return done(err);
691+
var msg = JSON.parse(dec.toString());
692+
693+
msg.request.method.should.equal('GET');
694+
msg.request.url.should.equal('https://sentry.io/hello');
695+
msg.user.should.eql({
696+
username: 'lewis'
697+
});
698+
699+
done();
700+
});
701+
return 'OK';
702+
});
703+
704+
705+
client.context(function () {
706+
client.setContext({
707+
req: {
708+
protocol: 'https',
709+
hostname: 'sentry.io',
710+
url: '/hello',
711+
method: 'GET',
712+
user: {
713+
username: 'lewis'
714+
}
715+
}
716+
});
717+
718+
setTimeout(function () {
719+
client.captureException(new Error('foo'), function () {
720+
scope.done();
721+
});
722+
}, 0);
723+
});
724+
});
725+
726+
it('should not attempt to parse an empty req', function (done) {
727+
var scope = nock('https://app.getsentry.com')
728+
.filteringRequestBody(/.*/, '*')
729+
.post('/api/269/store/', '*')
730+
.reply(200, function (uri, body) {
731+
zlib.inflate(new Buffer(body, 'base64'), function (err, dec) {
732+
if (err) return done(err);
733+
var msg = JSON.parse(dec.toString());
734+
735+
msg.message.should.equal('Error: foo');
736+
Object.keys(msg.request).should.have.length(0);
737+
738+
done();
739+
});
740+
return 'OK';
741+
});
742+
743+
744+
client.context(function () {
745+
// no req set on context
746+
setTimeout(function () {
747+
client.captureException(new Error('foo'), function () {
748+
scope.done();
749+
});
750+
}, 0);
751+
});
752+
});
753+
});
678754
});
679755

680756
it('should use a custom transport', function () {
@@ -945,48 +1021,6 @@ describe('raven.Client', function () {
9451021
});
9461022
});
9471023
});
948-
949-
it('should parse a req property from context', function (done) {
950-
var scope = nock('https://app.getsentry.com')
951-
.filteringRequestBody(/.*/, '*')
952-
.post('/api/269/store/', '*')
953-
.reply(200, function (uri, body) {
954-
zlib.inflate(new Buffer(body, 'base64'), function (err, dec) {
955-
if (err) return done(err);
956-
var msg = JSON.parse(dec.toString());
957-
958-
msg.request.method.should.equal('GET');
959-
msg.request.url.should.equal('https://sentry.io/hello');
960-
msg.user.should.eql({
961-
username: 'lewis'
962-
});
963-
964-
done();
965-
});
966-
return 'OK';
967-
});
968-
969-
970-
client.context(function () {
971-
client.setContext({
972-
req: {
973-
protocol: 'https',
974-
hostname: 'sentry.io',
975-
url: '/hello',
976-
method: 'GET',
977-
user: {
978-
username: 'lewis'
979-
}
980-
}
981-
});
982-
983-
setTimeout(function () {
984-
client.captureException(new Error('foo'), function () {
985-
scope.done();
986-
});
987-
}, 0);
988-
});
989-
});
9901024
});
9911025

9921026
describe('#intercept()', function () {

0 commit comments

Comments
 (0)