diff --git a/lighthouse-cli/test/fixtures/static-server.js b/lighthouse-cli/test/fixtures/static-server.js index 83d60fef781a..ed35d9a151d9 100644 --- a/lighthouse-cli/test/fixtures/static-server.js +++ b/lighthouse-cli/test/fixtures/static-server.js @@ -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; @@ -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 = ` + +

Smoke test fixtures

+ ${fixturePaths.map(p => `${escape(p)}`).join('
')} + `; + 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); @@ -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}`); } else { module.exports = { server: serverForOnline,