Skip to content

Commit

Permalink
fix: Record 0 for headerSize if transferSize is 0 (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
limhjgrace committed Jan 23, 2024
1 parent 31d8e30 commit 776915e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/plugins/event-plugins/NavigationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ export class NavigationPlugin extends InternalPlugin {

duration: entryData.duration,

headerSize: entryData.transferSize - entryData.encodedBodySize,
headerSize:
entryData.transferSize > 0
? entryData.transferSize - entryData.encodedBodySize
: 0,
transferSize: entryData.transferSize,
compressionRatio:
entryData.encodedBodySize > 0
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/event-plugins/__tests__/NavigationPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ describe('NavigationPlugin tests', () => {
);
});

test('When transferSize is 0 then headerSize is 0', async () => {
const plugin: NavigationPlugin = buildNavigationPlugin();
// Run
plugin.load(context);
window.dispatchEvent(new Event('load'));
plugin.disable();

expect(record.mock.calls[0][0]).toEqual(
PERFORMANCE_NAVIGATION_EVENT_TYPE
);
expect(record.mock.calls[0][1]).toEqual(
expect.objectContaining({
headerSize: 0
})
);
});

test('When navigation timing level 2 API is not present then navigation timing level 1 API is recorded', async () => {
jest.useFakeTimers();
mockPerformanceObjectWith([putRumEventsDocument], [], []);
Expand Down
2 changes: 1 addition & 1 deletion src/test-utils/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const navigationEvent = {
secureConnectionStart: 6.495000001450535,
serverTiming: [],
startTime: 0,
transferSize: 36525,
transferSize: 0,
type: 'navigate',
unloadEventEnd: 0,
unloadEventStart: 0,
Expand Down

0 comments on commit 776915e

Please sign in to comment.