diff --git a/src/raven.js b/src/raven.js index b5d569470094..28d520b55c60 100644 --- a/src/raven.js +++ b/src/raven.js @@ -1873,7 +1873,11 @@ Raven.prototype = { // intentionally make shallow copy so that additions // to breadcrumbs aren't accidentally sent in this request data.breadcrumbs = { - values: [].slice.call(this._breadcrumbs, 0) + values: [].slice.call(this._breadcrumbs, 0).sort(function(prev, next) { + if (prev.timestamp > next.timestamp) return 1; + if (prev.timestamp < next.timestamp) return -1; + return 0; + }) }; } diff --git a/test/raven.test.js b/test/raven.test.js index a0ac4caa1d1e..bafe193ebdcb 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -1696,6 +1696,7 @@ describe('globals', function() { assert.equal(Raven._backoffStart, null); // clock is at 100ms assert.equal(Raven._backoffDuration, 0); }); + it('should truncate url in breadcrumb', function() { this.sinon.stub(Raven, 'isSetup').returns(true); this.sinon.stub(Raven, '_makeRequest'); @@ -1816,6 +1817,56 @@ describe('globals', function() { Raven._send({message: 'bar'}); }, TypeError); }); + + it('should sort all breadcrumbs based on their timestamps', function() { + this.sinon.stub(Raven, 'isSetup').returns(true); + this.sinon.stub(Raven, '_makeRequest'); + this.sinon.stub(Raven, '_getHttpData').returns({ + url: 'http://localhost/?a=b', + headers: {'User-Agent': 'lolbrowser'} + }); + this.sinon.spy(Raven, '_sendProcessedPayload'); + + Raven._breadcrumbs = [ + { + type: 'ui.something', + message: 'something click 100', + timestamp: 100 + }, + { + type: 'ui.something', + message: 'something click 300', + timestamp: 300 + }, + { + type: 'ui.something', + message: 'something click 200', + timestamp: 200 + } + ]; + + Raven._send({message: 'bar'}); + + var data = Raven._sendProcessedPayload.getCall(0).args[0]; + + assert.deepEqual(data.breadcrumbs.values, [ + { + type: 'ui.something', + message: 'something click 100', + timestamp: 100 + }, + { + type: 'ui.something', + message: 'something click 200', + timestamp: 200 + }, + { + type: 'ui.something', + message: 'something click 300', + timestamp: 300 + } + ]); + }); }); describe('makeRequest', function() {