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(devtools): remove usage of frontend globals #15518

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
51 changes: 23 additions & 28 deletions core/scripts/pptr-run-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,33 +145,26 @@ function addSniffer(receiver, methodName, override) {
}

async function waitForLighthouseReady() {
// @ts-expect-error import
const {ViewManager, DockController} = await import('./ui/legacy/legacy.js');
// @ts-expect-error import
const {LighthousePanel} = await import('./panels/lighthouse/lighthouse.js');
// @ts-expect-error import
const {TargetManager} = await import('./core/sdk/sdk.js');
// @ts-expect-error import
const {AdvancedApp} = await import('./panels/emulation/emulation.js');

// Undocking later in the function can cause hiccups when Lighthouse enables device emulation.
// @ts-expect-error global
UI.dockController.setDockSide('undocked');
DockController.DockController.instance().setDockSide('undocked');

await ViewManager.ViewManager.instance().showView('lighthouse');

// @ts-expect-error global
const viewManager = UI.viewManager || (UI.ViewManager.ViewManager || UI.ViewManager).instance();
const views = viewManager.views || viewManager._views;
const panelName = views.has('lighthouse') ? 'lighthouse' : 'audits';
await viewManager.showView(panelName);
const panel = LighthousePanel.LighthousePanel.instance();

// @ts-expect-error global
const panel = UI.panels.lighthouse || UI.panels.audits;
const button = panel.contentElement.querySelector('button');
if (button.disabled) throw new Error('Start button disabled');

// Give the main target model a moment to be available.
// Otherwise, 'SDK.TargetManager.TargetManager.instance().mainTarget()' is null.
// @ts-expect-error global
if (self.runtime && self.runtime.loadLegacyModule) {
// This exposes TargetManager via self.SDK.
try {
// @ts-expect-error global
await self.runtime.loadLegacyModule('core/sdk/sdk-legacy.js');
} catch {}
}
// @ts-expect-error global
const targetManager = SDK.targetManager || (SDK.TargetManager.TargetManager || SDK.TargetManager).instance();
const targetManager = TargetManager.TargetManager.instance();
if (targetManager.primaryPageTarget() === null) {
if (targetManager?.observeTargets) {
await new Promise(resolve => targetManager.observeTargets({
Expand All @@ -186,16 +179,16 @@ async function waitForLighthouseReady() {
}

// Ensure the emulation model is ready before Lighthouse starts by enabling device emulation.
// @ts-expect-error global
const {deviceModeView} = Emulation.AdvancedApp.instance();
const {deviceModeView} = AdvancedApp.AdvancedApp.instance();
if (!deviceModeView.isDeviceModeOn()) {
deviceModeView.toggleDeviceMode();
}
}

async function runLighthouse() {
// @ts-expect-error global
const panel = UI.panels.lighthouse || UI.panels.audits;
// @ts-expect-error import
const {LighthousePanel} = await import('./panels/lighthouse/lighthouse.js');
const panel = LighthousePanel.LighthousePanel.instance();

/** @type {Promise<{lhr: LH.Result, artifacts: LH.Artifacts}>} */
const resultPromise = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -233,9 +226,11 @@ async function runLighthouse() {
return resultPromise;
}

function enableDevToolsThrottling() {
// @ts-expect-error global
const panel = UI.panels.lighthouse || UI.panels.audits;
async function enableDevToolsThrottling() {
// @ts-expect-error import
const {LighthousePanel} = await import('./panels/lighthouse/lighthouse.js');
const panel = LighthousePanel.LighthousePanel.instance();

const toolbarRoot = panel.contentElement.querySelector('.lighthouse-settings-pane .toolbar').shadowRoot;
toolbarRoot.querySelector('option[value="devtools"]').selected = true;
toolbarRoot.querySelector('select').dispatchEvent(new Event('change'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,9 @@
"score": null,
"scoreDisplayMode": "informative",
"displayValue": "3 long tasks found",
"metricSavings": {
"TBT": 143
},
"details": {
"type": "table",
"headings": [
Expand Down Expand Up @@ -9659,6 +9662,9 @@
"score": null,
"scoreDisplayMode": "informative",
"displayValue": "1 long task found",
"metricSavings": {
"TBT": 122.83299999999986
},
"details": {
"type": "table",
"headings": [
Expand Down Expand Up @@ -19213,6 +19219,9 @@
"score": null,
"scoreDisplayMode": "informative",
"displayValue": "2 long tasks found",
"metricSavings": {
"TBT": 13
},
"details": {
"type": "table",
"headings": [
Expand Down
3 changes: 3 additions & 0 deletions core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,9 @@
"score": null,
"scoreDisplayMode": "informative",
"displayValue": "2 long tasks found",
"metricSavings": {
"TBT": 1220.691999999999
Copy link
Member Author

Choose a reason for hiding this comment

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

Drive-by fix, this should have been updated in #15197 but our passing tests were stale

},
"details": {
"type": "table",
"headings": [
Expand Down
Loading