-
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: run most smoke tests on devtools #13456
Changes from 35 commits
b1bf3ff
036c7f6
119f17a
73735d4
29d5b9e
397eff0
71cf0d0
f2bd19a
c947f8d
9a47829
9022261
bbe7de5
7d1ab09
98f36e4
d371fd1
30a3da3
8136727
0c39ed1
4a1ea69
ae5258a
c01b920
c701b3a
747eab1
35c77a6
eba8d0b
97542c1
4367c71
5e4360c
b26652c
9f17ee2
9ccb3f5
32546f7
fd6937c
b79270d
b552400
b056663
12a060c
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 |
---|---|---|
|
@@ -73,3 +73,19 @@ jobs: | |
with: | ||
name: results | ||
path: ${{ github.workspace }}/lighthouse/.tmp/layout-test-results | ||
|
||
# Run smoke tests via DevTools | ||
- name: Define ToT chrome path | ||
run: echo "CHROME_PATH=/Users/runner/chrome-mac-tot/Chromium.app/Contents/MacOS/Chromium" >> $GITHUB_ENV | ||
- name: Install Chrome ToT | ||
working-directory: /Users/runner | ||
run: bash $GITHUB_WORKSPACE/lighthouse/lighthouse-core/scripts/download-chrome.sh && mv chrome-mac chrome-mac-tot | ||
- run: mkdir latest-run | ||
working-directory: ${{ github.workspace }}/lighthouse | ||
- name: yarn smoke --runner devtools | ||
# TODO: run on all tests. | ||
# - Current DevTools hangs on any page with a service worker. | ||
# https://github.com/GoogleChrome/lighthouse/issues/13396 | ||
# - Various other issues that needed investigation. | ||
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 you create an issue to track this second bullet? |
||
run: yarn smoke --runner devtools --invert-match a11y byte-efficiency byte-gzip dbw errors-expired-ssl errors-infinite-loop lantern-idle-callback-short legacy-javascript metrics-tricky-tti metrics-tricky-tti-late-fcp offline-ready offline-sw-broken offline-sw-slow oopif-requests perf-budgets perf-diagnostics-third-party perf-fonts perf-frame-metrics perf-preload perf-trace-elements pwa redirects-client-paint-server redirects-history-push-state redirects-multiple-server redirects-single-client redirects-single-server screenshot seo-passing seo-tap-targets | ||
working-directory: ${{ github.workspace }}/lighthouse |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ yarn-error.log | |
|
||
/chrome-linux/ | ||
/chrome-win32/ | ||
/chrome-mac/ | ||
/chrome.zip | ||
|
||
*__pycache__ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ const coreTestDefnsPath = | |
const runnerPaths = { | ||
cli: '../lighthouse-runners/cli.js', | ||
bundle: '../lighthouse-runners/bundle.js', | ||
devtools: '../lighthouse-runners/devtools.js', | ||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
/** | ||
|
@@ -151,7 +152,7 @@ async function begin() { | |
}, | ||
'runner': { | ||
default: 'cli', | ||
choices: ['cli', 'bundle'], | ||
choices: ['cli', 'bundle', 'devtools'], | ||
describe: 'The method of running Lighthouse', | ||
}, | ||
'tests-path': { | ||
|
@@ -183,7 +184,7 @@ async function begin() { | |
if (argv.runner === 'bundle') { | ||
console.log('\n✨ Be sure to have recently run this: yarn build-all'); | ||
} | ||
const {runLighthouse} = await import(runnerPath); | ||
const {runLighthouse, beforeAll} = await import(runnerPath); | ||
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 remove beforeAll (here and in |
||
|
||
// Find test definition file and filter by requestedTestIds. | ||
let testDefnPath = argv.testsPath || coreTestDefnsPath; | ||
|
@@ -216,6 +217,7 @@ async function begin() { | |
isDebug: argv.debug, | ||
useFraggleRock: argv.fraggleRock, | ||
lighthouseRunner: runLighthouse, | ||
beforeAll, | ||
takeNetworkRequestUrls, | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,98 @@ | ||||||
/** | ||||||
* @license Copyright 2021 The Lighthouse Authors. 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 DevTools. | ||||||
*/ | ||||||
|
||||||
import fs from 'fs'; | ||||||
import os from 'os'; | ||||||
import {spawn} from 'child_process'; | ||||||
|
||||||
import {LH_ROOT} from '../../../../root.js'; | ||||||
|
||||||
const devtoolsDir = | ||||||
process.env.DEVTOOLS_PATH || `${LH_ROOT}/.tmp/chromium-web-tests/devtools/devtools-frontend`; | ||||||
|
||||||
/** | ||||||
* @param {string} command | ||||||
* @param {string[]} args | ||||||
*/ | ||||||
async function spawnAndLog(command, args) { | ||||||
let log = ''; | ||||||
|
||||||
/** @type {Promise<void>} */ | ||||||
const promise = new Promise((resolve, reject) => { | ||||||
const spawnHandle = spawn(command, args); | ||||||
spawnHandle.on('close', code => { | ||||||
if (code === 0) resolve(); | ||||||
else reject(new Error(`Command exited with code ${code}`)); | ||||||
}); | ||||||
spawnHandle.on('error', reject); | ||||||
spawnHandle.stdout.on('data', data => { | ||||||
console.log(data.toString()); | ||||||
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. are these lines intended to stay or for debugging? 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. Yes, otherwise the cases where things hang or error aren't printed (the runner interface only allows returning successful logs). and it's nicer to see the output stream in. 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. just checking that it's intentional. The tradeoff is that concurrent runs will be streaming in stuff all interleaved with each other and hard to tell the source of each line, but that can still be helpful, especially when things are new and need to check that it's actually running, etc |
||||||
log += `STDOUT: ${data.toString()}`; | ||||||
}); | ||||||
spawnHandle.stderr.on('data', data => { | ||||||
console.log(data.toString()); | ||||||
log += `STDERR: ${data.toString()}`; | ||||||
}); | ||||||
}); | ||||||
await promise; | ||||||
|
||||||
return log; | ||||||
} | ||||||
|
||||||
/** @type {Promise<void>} */ | ||||||
let beforeAllPromise; | ||||||
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
Suggested change
or something like that? |
||||||
async function beforeAll() { | ||||||
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 you add a jsdoc like, "Build the lighthouse DevTools bundle and fetch and build the DevTools frontend using it" or whatever? |
||||||
if (process.env.CI) return; | ||||||
|
||||||
process.env.DEVTOOLS_PATH = devtoolsDir; | ||||||
await spawnAndLog('bash', ['lighthouse-core/test/chromium-web-tests/download-devtools.sh']); | ||||||
await spawnAndLog('bash', ['lighthouse-core/test/chromium-web-tests/roll-devtools.sh']); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Launch Chrome and do a full Lighthouse run via DevTools. | ||||||
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. I'm having trouble coming up with a non-awkward way to say this, but seems worth clarifying it's the current/local Lighthouse devtools bundle run in the latest DevTools frontend |
||||||
* @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 = {}) { | ||||||
if (!beforeAllPromise) beforeAllPromise = beforeAll(); | ||||||
await beforeAllPromise; | ||||||
|
||||||
const outputDir = fs.mkdtempSync(os.tmpdir() + '/lh-smoke-cdt-runner-'); | ||||||
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. Does this create multiple temp directories if the smokes are running concurrently? 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. yeah, |
||||||
const args = [ | ||||||
'run-devtools', | ||||||
url, | ||||||
`--custom-devtools-frontend=file://${devtoolsDir}/out/Default/gen/front_end`, | ||||||
'--output-dir', outputDir, | ||||||
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. We could use the custom DT frontend flag to test how PR changes affect DT. 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, I keep making this mistake, thinking that is the default behavior. It is for open-devtools! I want to followup with a change that does that. Will add the arg here for now. |
||||||
]; | ||||||
if (configJson) { | ||||||
args.push('--config', JSON.stringify(configJson)); | ||||||
} | ||||||
|
||||||
const log = await spawnAndLog('yarn', args); | ||||||
const lhr = JSON.parse(fs.readFileSync(`${outputDir}/lhr-0.json`, 'utf-8')); | ||||||
const artifacts = JSON.parse(fs.readFileSync(`${outputDir}/artifacts-0.json`, 'utf-8')); | ||||||
|
||||||
if (testRunnerOptions.isDebug) { | ||||||
console.log(`${url} results saved at ${outputDir}`); | ||||||
} else { | ||||||
fs.rmSync(outputDir, {recursive: true, force: true}); | ||||||
} | ||||||
|
||||||
return {lhr, artifacts, log}; | ||||||
} | ||||||
|
||||||
export { | ||||||
beforeAll, | ||||||
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.
Better in a new job?
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.
How to avoid redoing all the work for building devtools?
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.
Yeah it's not pretty. We could have dependent jobs (or cache the build, but dependent jobs seems workable)? I'm not sure of the best approach, but if the devtools CI job is normally going to take 30+ minutes we'll definitely want to split it up.
edit: if an already-built devtools was available, sharding would work as well