Skip to content

Commit

Permalink
tests(smokehouse): gzip test to assert transfer and resource sizes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored and brendankenny committed Feb 26, 2019
1 parent 6fcec75 commit 7dbcead
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lighthouse-cli/test/fixtures/byte-efficiency/gzip.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<!--
* Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-->
<html>
<head>
<title>Gzip</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<script src="script.js?gzip=1"></script>
<script src="script.js"></script>
</head>
<body>
</body>
</html>
11 changes: 11 additions & 0 deletions lighthouse-cli/test/fixtures/static-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lighthouse-cli/test/smokehouse/byte-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
extends: 'lighthouse:full',
settings: {
onlyAudits: [
'network-requests',
'offscreen-images',
'uses-webp-images',
'uses-optimized-images',
Expand Down
25 changes: 25 additions & 0 deletions lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
},
},
},
];

0 comments on commit 7dbcead

Please sign in to comment.