-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: use smokehouse runner for test-bundle #9943
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,8 @@ const isDevtools = file => path.basename(file).includes('devtools'); | |
/** @param {string} file */ | ||
const isLightrider = file => path.basename(file).includes('lightrider'); | ||
|
||
const BANNER = `// lighthouse, browserified. ${VERSION} (${COMMIT_HASH})\n`; | ||
const BANNER = `// lighthouse, browserified. ${VERSION} (${COMMIT_HASH})\n` + | ||
'// @ts-nocheck\n'; // To prevent tsc stepping into any required bundles. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we just exclude the bundle in tsconfig? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
from my experience this isn't possible (include and exclude are just including and excluding root files that tsc starts walking from), but I would be happy if I was missing something :) See https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#details ("Any files that are referenced by files included...") |
||
const DEBUG = false; // true for sourcemaps | ||
|
||
/** | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -50,13 +50,12 @@ function listenForStatus(listenCallback) { | |||||
} | ||||||
|
||||||
if (typeof module !== 'undefined' && module.exports) { | ||||||
// export for require()ing (via browserify). | ||||||
module.exports = { | ||||||
runLighthouseInWorker, | ||||||
listenForStatus, | ||||||
registerLocaleData, | ||||||
lookupLocale, | ||||||
}; | ||||||
// Ideally this could be exposed via browserify's `standalone`, but it doesn't | ||||||
// work for LH because of https://github.com/browserify/browserify/issues/968. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(period broke link) |
||||||
// Instead, since this file is only ever run in node for testing, expose a | ||||||
// bundle entry point as global. | ||||||
// @ts-ignore | ||||||
global.runBundledLighthouse = lighthouse; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. originally was going to make I am slightly concerned about drift between how devtools calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This drift sounds fine to me. When I have the smoke tests run against the Audits panel, it will be at a higher level than this bundle, so the drift between So while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ah, good to know, I didn't realize that, though it makes sense.
Agree it's kind of confusing, but the benefit is it's getting all the bundle customizations--all the Originally I had it something like function runLighthouseInWorker() {
// ...
runLighthouse(...args);
}
/**
* Intermediate function to expose for testing.
*/
function runLighthouse() {
lighthouse(...args)
}
global.runBundledLighthouse = runLighthouse; that spelled it out a little more clearly but also seemed a bit silly. We could change the Other ways we could make things more explicit and clearer? |
||||||
} | ||||||
|
||||||
// Expose only in DevTools' worker | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,15 @@ const log = require('lighthouse-logger'); | |
const {runSmokehouse} = require('../smokehouse.js'); | ||
const {server, serverForOffline} = require('../../fixtures/static-server.js'); | ||
|
||
const cliLighthouseRunner = require('../lighthouse-runners/cli.js').runLighthouse; | ||
|
||
const coreTestDefnsPath = require.resolve('../test-definitions/core-tests.js'); | ||
|
||
const runners = { | ||
cli: cliLighthouseRunner, | ||
/** | ||
* Possible Lighthouse runners. Loaded dynamically so e.g. a CLI run isn't | ||
* contingent on having built all the bundles. | ||
*/ | ||
const runnerPaths = { | ||
cli: '../lighthouse-runners/cli.js', | ||
bundle: '../lighthouse-runners/bundle.js', | ||
}; | ||
|
||
/** | ||
|
@@ -76,7 +79,7 @@ async function begin() { | |
.alias({ | ||
'jobs': 'j', | ||
}) | ||
.choices('runner', ['cli']) | ||
.choices('runner', ['cli', 'bundle']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should there be a makes sense to just wait for someone to request this feature, but it's easy enough to do perhaps we should just do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I will be one such user in the near future :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could we just add it when you need it? Agreed it fits in easily, these are more or less just shorthand forms of that, but I'd like to avoid messing with yargs more right now :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
though |
||
.default('runner', 'cli') | ||
.wrap(yargs.terminalWidth()) | ||
.argv; | ||
|
@@ -85,7 +88,11 @@ async function begin() { | |
const jobs = argv.jobs !== undefined ? Number(argv.jobs) : undefined; | ||
const retries = argv.retries !== undefined ? Number(argv.retries) : undefined; | ||
|
||
const lighthouseRunner = runners[/** @type {keyof typeof runners} */ (argv.runner)]; | ||
const runnerPath = runnerPaths[/** @type {keyof typeof runnerPaths} */ (argv.runner)]; | ||
if (argv.runner === 'bundle') { | ||
console.log('\n✨ Be sure to have recently run this: yarn build-all'); | ||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
const lighthouseRunner = require(runnerPath).runLighthouse; | ||
|
||
// Find test definition file and filter by requestedTestIds. | ||
let testDefnPath = argv.testsPath || coreTestDefnsPath; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this should be |
||
* @license 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. | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* @fileoverview A runner that launches Chrome and executes Lighthouse via a | ||
* bundle to test that bundling has produced correct and runnable code. | ||
* Currently uses `lighthouse-dt-bundle.js`. | ||
*/ | ||
|
||
const ChromeLauncher = require('chrome-launcher'); | ||
const ChromeProtocol = require('../../../../lighthouse-core/gather/connections/cri.js'); | ||
|
||
// Load bundle, which creates a `global.runBundledLighthouse`. | ||
require('../../../../dist/lighthouse-dt-bundle.js'); | ||
|
||
// Import the main lighthouse() signature for easy type verification. | ||
/** @type {import('../../../../lighthouse-core/index.js')} */ | ||
// @ts-ignore - not worth giving test global an actual type. | ||
const lighthouse = global.runBundledLighthouse; | ||
|
||
/** | ||
* Launch Chrome and do a full Lighthouse run via the Lighthouse CLI. | ||
* @param {string} url | ||
* @param {LH.Config.Json=} configJson | ||
* @param {{isDebug?: boolean}=} testRunnerOptions | ||
* @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>} | ||
*/ | ||
async function runLighthouse(url, configJson, testRunnerOptions = {}) { | ||
// Launch and connect to Chrome. | ||
const launchedChrome = await ChromeLauncher.launch(); | ||
const port = launchedChrome.port; | ||
const connection = new ChromeProtocol(port); | ||
|
||
// Run Lighthouse. | ||
const logLevel = testRunnerOptions.isDebug ? 'info' : undefined; | ||
const runnerResult = await lighthouse(url, {port, logLevel}, configJson, connection); | ||
if (!runnerResult) throw new Error('No runnerResult'); | ||
|
||
// Clean up and return results. | ||
await launchedChrome.kill(); | ||
return { | ||
lhr: runnerResult.lhr, | ||
artifacts: runnerResult.artifacts, | ||
log: '', // TODO: if want to run in parallel, need to capture lighthouse-logger output. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a way to control where |
||
}; | ||
} | ||
|
||
module.exports = { | ||
runLighthouse, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since
dist/lighthouse-dt-bundle.js
is required in smokehouse and smokehouse is type checked, tsc automatically starts checking the bundle code too. This is the only reliable way I could think of to stop it, but happy for alternatives :)