fix(har tracing): record response.bodySize for API requests

This commit is contained in:
Simon Knott 2024-09-17 16:50:41 +02:00
parent 507e515cb2
commit 4c624f0462
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 4 additions and 0 deletions

View file

@ -236,6 +236,8 @@ export class HarTracer {
if (contentType) if (contentType)
content.mimeType = contentType; content.mimeType = contentType;
this._storeResponseContent(event.body, content, 'other'); this._storeResponseContent(event.body, content, 'other');
if (!this._options.omitSizes)
harEntry.response.bodySize = event.body?.length ?? 0;
if (this._started) if (this._started)
this._delegate.onEntryFinished(harEntry); this._delegate.onEntryFinished(harEntry);

View file

@ -820,6 +820,7 @@ it('should include API request', async ({ contextFactory, server }, testInfo) =>
expect(entry.response.headers.find(h => h.name.toLowerCase() === 'content-type')?.value).toContain('application/json'); expect(entry.response.headers.find(h => h.name.toLowerCase() === 'content-type')?.value).toContain('application/json');
expect(entry.response.content.size).toBe(15); expect(entry.response.content.size).toBe(15);
expect(entry.response.content.text).toBe(responseBody.toString()); expect(entry.response.content.text).toBe(responseBody.toString());
expect(entry.response.bodySize).toBe(15);
expect(entry.time).toBeGreaterThan(0); expect(entry.time).toBeGreaterThan(0);
expect(entry.timings).toEqual(expect.objectContaining({ expect(entry.timings).toEqual(expect.objectContaining({
@ -844,6 +845,7 @@ it('should respect minimal mode for API Requests', async ({ contextFactory, serv
expect(entries).toHaveLength(1); expect(entries).toHaveLength(1);
const [entry] = entries; const [entry] = entries;
expect(entry.timings).toEqual({ receive: -1, send: -1, wait: -1 }); expect(entry.timings).toEqual({ receive: -1, send: -1, wait: -1 });
expect(entry.response.bodySize).toBe(-1);
}); });
it('should include redirects from API request', async ({ contextFactory, server }, testInfo) => { it('should include redirects from API request', async ({ contextFactory, server }, testInfo) => {