-
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
core(user-flow): dry run flag #13837
Open
adamraine
wants to merge
15
commits into
main
Choose a base branch
from
flow-dry-run
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
943ffe8
core(user-flow): dry run flag
adamraine 716be02
ope
adamraine 6561c35
test
adamraine acce076
maybe
adamraine 0b99bdd
rm expectation
adamraine 8612d7c
gotoURL
adamraine f39db6f
Merge branch 'master' into flow-dry-run
adamraine 3d9b4c5
canon pptr
adamraine 8112de3
Merge branch 'master' into flow-dry-run
adamraine 8550d7b
tests
adamraine 61f322d
bool
adamraine 9ee2460
comment
adamraine 4df2f2d
doc
adamraine 9411a5a
Merge branch 'master' into flow-dry-run
adamraine 2641f7f
Merge branch 'master' into flow-dry-run
adamraine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @license Copyright 2022 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'; | ||
|
||
const Driver = require('./driver.js'); | ||
const emulation = require('../../lib/emulation.js'); | ||
const {initializeConfig} = require('../config/config.js'); | ||
const {gotoURL} = require('../../gather/driver/navigation.js'); | ||
|
||
/** | ||
* @param {LH.Gatherer.GatherMode} gatherMode | ||
* @param {{page: LH.Puppeteer.Page, config?: LH.Config.Json, configContext?: LH.Config.FRContext}} options | ||
*/ | ||
async function dryRunSetup(gatherMode, options) { | ||
const {page, config: configJson, configContext} = options; | ||
const {config} = await initializeConfig(configJson, {...configContext, gatherMode}); | ||
const driver = new Driver(page); | ||
await driver.connect(); | ||
await emulation.emulate(driver.defaultSession, config.settings); | ||
return {driver, config}; | ||
} | ||
|
||
/** | ||
* @param {Exclude<LH.Gatherer.GatherMode, 'navigation'>} gatherMode | ||
* @param {{page: LH.Puppeteer.Page, config?: LH.Config.Json, configContext?: LH.Config.FRContext}} options | ||
*/ | ||
async function dryRun(gatherMode, options) { | ||
const {driver} = await dryRunSetup(gatherMode, options); | ||
await driver.disconnect(); | ||
} | ||
|
||
/** | ||
* @param {LH.NavigationRequestor} requestor | ||
* @param {{page: LH.Puppeteer.Page, config?: LH.Config.Json, configContext?: LH.Config.FRContext}} options | ||
*/ | ||
async function dryRunNavigation(requestor, options) { | ||
const {driver, config} = await dryRunSetup('navigation', options); | ||
if (!config.navigations || !config.navigations.length) { | ||
throw new Error('No navigations configured'); | ||
} | ||
|
||
const navigation = config.navigations[0]; | ||
await gotoURL(driver, requestor, { | ||
...navigation, | ||
maxWaitForFcp: config.settings.maxWaitForFcp, | ||
maxWaitForLoad: config.settings.maxWaitForLoad, | ||
waitUntil: navigation.pauseAfterFcpMs ? ['fcp', 'load'] : ['load'], | ||
}); | ||
|
||
await driver.disconnect(); | ||
} | ||
|
||
module.exports = { | ||
dryRun, | ||
dryRunNavigation, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
lighthouse-core/test/fraggle-rock/scenarios/dry-run-test-pptr.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @license Copyright 2022 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. | ||
*/ | ||
|
||
import {jest} from '@jest/globals'; | ||
|
||
import * as api from '../../../fraggle-rock/api.js'; | ||
import {createTestState} from './pptr-test-utils.js'; | ||
import {LH_ROOT} from '../../../../root.js'; | ||
|
||
/* eslint-env jest */ | ||
/* eslint-env browser */ | ||
|
||
jest.setTimeout(90_000); | ||
|
||
describe('Dry Run', () => { | ||
const state = createTestState(); | ||
|
||
state.installSetupAndTeardownHooks(); | ||
|
||
beforeAll(() => { | ||
state.server.baseDir = `${LH_ROOT}/lighthouse-core/test/fixtures/fraggle-rock/snapshot-basic`; | ||
}); | ||
|
||
it('should setup environment and perform flow actions', async () => { | ||
const pageUrl = `${state.serverBaseUrl}/onclick.html`; | ||
|
||
const flow = await api.startFlow(state.page, {dryRun: true}); | ||
await flow.navigate(pageUrl); | ||
|
||
await flow.startNavigation(); | ||
await state.page.goto(pageUrl); | ||
await flow.endNavigation(); | ||
|
||
await flow.startTimespan(); | ||
await state.page.click('button'); | ||
await flow.endTimespan(); | ||
|
||
await flow.snapshot(); | ||
|
||
// Ensure page navigated occurred and button was clicked. | ||
const finalUrl = await state.page.url(); | ||
expect(finalUrl).toEqual(`${pageUrl}#done`); | ||
|
||
// Ensure Lighthouse emulated a mobile device. | ||
// Device scale factor override is not shared between sessions | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1337089 | ||
const deviceMetrics = await state.page.evaluate(() => ({ | ||
width: document.documentElement.clientWidth, | ||
height: document.documentElement.clientHeight, | ||
adamraine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// deviceScaleFactor: window.devicePixelRatio, | ||
})); | ||
expect(deviceMetrics).toEqual({ | ||
height: 640, | ||
width: 360, | ||
// deviceScaleFactor: 2, | ||
}); | ||
|
||
expect(flow.createArtifactsJson()).toEqual({ | ||
gatherSteps: [], | ||
}); | ||
expect(await flow.createFlowResult()).toEqual({ | ||
name: 'Dry run', | ||
steps: [], | ||
}); | ||
expect(await flow.generateReport()).toEqual( | ||
'<h1>Cannot generate a flow report from a dry run</h1>' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What happens to emulation when the driver disconnects? Does it persist or go away?
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.
https://bugs.chromium.org/p/chromium/issues/detail?id=1337089
TLDR it goes back to default, even if another session exists that is overriding the device emulation.