From 8a3e992031b6dd6d25920b82f6a2c9cf01270de4 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 10 Sep 2021 20:53:08 +0200 Subject: [PATCH] test: add test for responseBodySize with chunked requests (#8839) --- tests/page/page-network-sizes.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/page/page-network-sizes.spec.ts b/tests/page/page-network-sizes.spec.ts index 3a497b2051..953082ed90 100644 --- a/tests/page/page-network-sizes.spec.ts +++ b/tests/page/page-network-sizes.spec.ts @@ -73,6 +73,24 @@ it('should have the correct responseBodySize', async ({ page, server, asset, bro expect(sizes.responseBodySize).toBe(fs.statSync(asset('simplezip.json')).size); }); +it('should have the correct responseBodySize for chunked request', async ({ page, server, asset }) => { + it.fixme(); + const content = fs.readFileSync(asset('simplezip.json')); + const AMOUNT_OF_CHUNKS = 10; + const CHUNK_SIZE = Math.ceil(content.length / AMOUNT_OF_CHUNKS); + server.setRoute('/chunked-simplezip.json', (req, resp) => { + resp.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Transfer-Encoding': 'chunked' }); + for (let start = 0; start < content.length; start += CHUNK_SIZE) { + const end = Math.min(start + CHUNK_SIZE, content.length); + resp.write(content.slice(start, end)); + } + resp.end(); + }); + const response = await page.goto(server.PREFIX + '/chunked-simplezip.json'); + const sizes = await response.request().sizes(); + expect(sizes.responseBodySize).toBe(fs.statSync(asset('simplezip.json')).size); +}); + it('should have the correct responseBodySize with gzip compression', async ({ page, server, asset }, testInfo) => { server.enableGzip('/simplezip.json'); await page.goto(server.EMPTY_PAGE);