Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
};
}

Expand Down
51 changes: 51 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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() {
Expand Down