diff --git a/src/formatters/NetworkFormatter.ts b/src/formatters/NetworkFormatter.ts index 001a5fec5..42053be08 100644 --- a/src/formatters/NetworkFormatter.ts +++ b/src/formatters/NetworkFormatter.ts @@ -171,17 +171,24 @@ export class NetworkFormatter { const httpResponse = request.response(); const failure = request.failure(); let status: string; - if (httpResponse) { - const responseStatus = httpResponse.status(); - status = - responseStatus >= 200 && responseStatus <= 299 - ? `[success - ${responseStatus}]` - : `[failed - ${responseStatus}]`; - } else if (failure) { + if (failure) { status = `[failed - ${failure.errorText}]`; + } else if (httpResponse) { + const responseStatus = httpResponse.status(); + + if (responseStatus >= 100 && responseStatus <= 199) { + status = `[info - ${responseStatus}]`; + } else if (responseStatus >= 200 && responseStatus <= 299) { + status = `[success - ${responseStatus}]`; + } else if (responseStatus >= 300 && responseStatus <= 399) { + status = `[redirect - ${responseStatus}]`; + } else { + status = `[failed - ${responseStatus}]`; + } } else { status = '[pending]'; } + return status; } diff --git a/tests/formatters/NetworkFormatter.test.ts b/tests/formatters/NetworkFormatter.test.ts index aa8f26618..77aea406d 100644 --- a/tests/formatters/NetworkFormatter.test.ts +++ b/tests/formatters/NetworkFormatter.test.ts @@ -49,7 +49,7 @@ describe('NetworkFormatter', () => { assert.equal( formatter.toString(), - 'reqid=1 GET http://example.com [failed - 199]', + 'reqid=1 GET http://example.com [info - 199]', ); }); it('shows correct status for request with response code above 200', async () => { @@ -61,7 +61,7 @@ describe('NetworkFormatter', () => { assert.equal( formatter.toString(), - 'reqid=1 GET http://example.com [failed - 300]', + 'reqid=1 GET http://example.com [redirect - 300]', ); }); it('shows correct status for request that failed', async () => { diff --git a/tests/tools/network.test.js.snapshot b/tests/tools/network.test.js.snapshot index 420d92cea..57e44e226 100644 --- a/tests/tools/network.test.js.snapshot +++ b/tests/tools/network.test.js.snapshot @@ -47,7 +47,7 @@ exports[`network > network_list_requests > list requests from previous navigatio # list_request response ## Network requests Showing 1-3 of 3 (Page 1 of 1). -reqid=1 GET http://localhost:/redirect [failed - 302] +reqid=1 GET http://localhost:/redirect [redirect - 302] reqid=2 GET http://localhost:/redirected [success - 200] reqid=3 GET http://localhost:/redirected-page [success - 200] `; diff --git a/tests/tools/performance.test.ts b/tests/tools/performance.test.ts index b1fc2ad5a..26e3d2108 100644 --- a/tests/tools/performance.test.ts +++ b/tests/tools/performance.test.ts @@ -140,7 +140,7 @@ describe('performance', () => { }); }); - it.only('supports filePath', async () => { + it('supports filePath', async () => { const rawData = loadTraceAsBuffer('basic-trace.json.gz'); // rawData is the decompressed buffer (based on loadTraceAsBuffer implementation). // We want to simulate saving it as a .gz file, so the tool should compress it.