diff --git a/lighthouse-cli/test/fixtures/byte-efficiency/gzip.html b/lighthouse-cli/test/fixtures/byte-efficiency/gzip.html new file mode 100644 index 000000000000..d6ba29c443ab --- /dev/null +++ b/lighthouse-cli/test/fixtures/byte-efficiency/gzip.html @@ -0,0 +1,17 @@ + + + + +Gzip + + + + + + + + diff --git a/lighthouse-cli/test/fixtures/static-server.js b/lighthouse-cli/test/fixtures/static-server.js index 2e6604b5de3f..9e5b98bca363 100644 --- a/lighthouse-cli/test/fixtures/static-server.js +++ b/lighthouse-cli/test/fixtures/static-server.js @@ -9,6 +9,7 @@ /* eslint-disable no-console */ const http = require('http'); +const zlib = require('zlib'); const path = require('path'); const fs = require('fs'); const parseQueryString = require('querystring').parse; @@ -71,6 +72,7 @@ function requestHandler(request, response) { } let delay = 0; + let useGzip = false; if (queryString) { const params = new URLSearchParams(queryString); // set document status-code @@ -93,12 +95,21 @@ function requestHandler(request, response) { } } + if (params.has('gzip')) { + useGzip = Boolean(params.get('gzip')); + } + // redirect url to new url if present if (params.has('redirect')) { return setTimeout(sendRedirect, delay, params.get('redirect')); } } + if (useGzip) { + data = zlib.gzipSync(data); + headers['Content-Encoding'] = 'gzip'; + } + response.writeHead(statusCode, headers); // Delay the response diff --git a/lighthouse-cli/test/smokehouse/byte-config.js b/lighthouse-cli/test/smokehouse/byte-config.js index 6718ab5263ee..cb901fa93513 100644 --- a/lighthouse-cli/test/smokehouse/byte-config.js +++ b/lighthouse-cli/test/smokehouse/byte-config.js @@ -12,6 +12,7 @@ module.exports = { extends: 'lighthouse:full', settings: { onlyAudits: [ + 'network-requests', 'offscreen-images', 'uses-webp-images', 'uses-optimized-images', diff --git a/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js b/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js index d26e7cf1546d..2156f2e9f03e 100644 --- a/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js +++ b/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js @@ -103,4 +103,29 @@ module.exports = [ }, }, }, + { + requestedUrl: 'http://localhost:10200/byte-efficiency/gzip.html', + finalUrl: 'http://localhost:10200/byte-efficiency/gzip.html', + audits: { + 'network-requests': { + details: { + items: [ + { + url: 'http://localhost:10200/byte-efficiency/gzip.html', + }, + { + url: 'http://localhost:10200/byte-efficiency/script.js?gzip=1', + transferSize: 1136, + resourceSize: 52997, + }, + { + url: 'http://localhost:10200/byte-efficiency/script.js', + transferSize: 53181, + resourceSize: 52997, + }, + ], + }, + }, + }, + }, ];