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
Changes from all 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
25 changes: 22 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 mime = require('mime-types');
const parseQueryString = require('querystring').parse;
const parseURL = require('url').parse;
Expand All @@ -26,6 +27,21 @@ function requestHandler(request, response) {
const queryString = requestUrl.search && parseQueryString(requestUrl.search.slice(1));
let absoluteFilePath = path.join(__dirname, filePath);

// Create an index page that lists the available test pages.
if (filePath === '/') {
const fixturePaths = glob.sync('**/*.html', {cwd: __dirname});
const html = `
<html>
<h1>Smoke test fixtures</h1>
${fixturePaths.map(p => `<a href=${encodeURI(p)}>${escape(p)}</a>`).join('<br>')}
`;
response.writeHead(200, {
'Content-Security-Policy': `default-src 'none';`,
});
sendResponse(200, html);
return;
}

if (filePath.startsWith('/dist/viewer')) {
// Rewrite lighthouse-viewer paths to point to that location.
absoluteFilePath = path.join(__dirname, '/../../../', filePath);
Expand Down Expand Up @@ -142,12 +158,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