Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(smokehouse): index for static server. print address #9541

Merged
merged 6 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lighthouse-cli/test/fixtures/static-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const http = require('http');
const zlib = require('zlib');
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const parseQueryString = require('querystring').parse;
const parseURL = require('url').parse;
const URLSearchParams = require('url').URLSearchParams;
Expand All @@ -25,6 +26,16 @@ function requestHandler(request, response) {
const queryString = requestUrl.search && parseQueryString(requestUrl.search.slice(1));
let absoluteFilePath = path.join(__dirname, filePath);

if (filePath === '/') {
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
const fixturePaths = glob.sync('**/*.html', {cwd: __dirname});
const html = `
<h1>Smoke test fixtures</h1>
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
${fixturePaths.map(p => `<a href=${p}>${p}</a>`).join('<br>')}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work on windows, like are the paths returned by glob different?

do we care if it doesn't? probably not

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂

`;
sendResponse(200, html);
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (filePath.startsWith('/dist/viewer')) {
// Rewrite lighthouse-viewer paths to point to that location.
absoluteFilePath = path.join(__dirname, '/../../../', filePath);
Expand Down Expand Up @@ -79,6 +90,8 @@ function requestHandler(request, response) {
headers['Content-Type'] = 'image/webp';
} else if (filePath.endsWith('.json')) {
headers['Content-Type'] = 'application/json';
} else if (filePath.endsWith('.html') || filePath === '/') {
headers['Content-Type'] = 'text/html';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels 100% unrelated to the index part, right?

why cause conflicts for yourself in #9542 :)

}

let delay = 0;
Expand Down Expand Up @@ -150,12 +163,15 @@ const serverForOffline = http.createServer(requestHandler);
serverForOnline.on('error', e => console.error(e.code, e));
serverForOffline.on('error', e => console.error(e.code, e));


// If called via `node static-server.js` then start listening, otherwise, just expose the servers
if (require.main === module) {
// Start listening
serverForOnline.listen(10200, 'localhost');
serverForOffline.listen(10503, 'localhost');
const onlinePort = 10200;
const offlinePort = 10503;
serverForOnline.listen(onlinePort, 'localhost');
serverForOffline.listen(offlinePort, 'localhost');
console.log(`online: listening on http://localhost:${onlinePort}`);
console.log(`offline: listening on http://localhost:${offlinePort}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's really nothing offline or online about these, it's just how we use them for one(?) of the smoke tests (we also use them for same- and different-origin in other tests), but I'm not sure it matters what we call them :)

} else {
module.exports = {
server: serverForOnline,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/test/smokehouse/perf/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = [
{resourceType: 'font', requestCount: 2, size: '80000±1000'},
{resourceType: 'script', requestCount: 3, size: '55000±1000'},
{resourceType: 'image', requestCount: 2, size: '28000±1000'},
{resourceType: 'document', requestCount: 1, size: '2100±100'},
{resourceType: 'document', requestCount: 1, size: '2200±100'},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went up b/c content-type header is now added for html docs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right that's easy to forget that header cost is included in these

{resourceType: 'other', requestCount: 2, size: '1250±50'},
{resourceType: 'stylesheet', requestCount: 1, size: '450±100'},
{resourceType: 'media', requestCount: 0, size: 0},
Expand Down