Skip to content
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
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"enquirer": "^2.4.1",
"lighthouse": "^13.6.0",
"prettier": "^3.9.10",
"puppeteer": "^25.16.0",
"puppeteer": "^25.17.0",
"rxjs": "^7.8.2",
"ts-node": "^10.9.2",
"tslib": "^2.9.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"tslib": "^2.9.1",
"yargs": "^18.2.0",
"lighthouse": "^13.6.0",
"puppeteer": "^25.16.0",
"puppeteer": "^25.17.0",
"@puppeteer/replay": "^4.0.2",
"prettier": "^3.9.10",
"enquirer": "^2.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function collectFlow(
const lhConfig = mergeLhConfig(globalLhCfg, flowOptions?.config);
flowOptions.config = lhConfig;

const browser: Browser = await puppeteer.launch(parseLaunchOptions(launchOptions));
const browser: Browser = await puppeteer.launch(parseLaunchOptions(launchOptions, argv));
const page: Page = await browser.newPage();

logVerbose(`Collect: ${flowOptions.name} from URL ${cliOption.url}`);
Expand All @@ -43,21 +43,25 @@ export async function collectFlow(
return flow;
}

function parseLaunchOptions(launchOptions?: LaunchOptions): LaunchOptions {
export function parseLaunchOptions(
launchOptions?: LaunchOptions,
{ dryRun }: { dryRun?: boolean } = {}
): LaunchOptions {
// object containing the options for puppeteer/chromium
launchOptions = launchOptions || {
// has to be false to run in the CI because of a bug :(
// https://github.com/puppeteer/puppeteer/issues/8148
headless: false,
// hack for dryRun => should get fixed inside user flow in future
defaultViewport: { isMobile: true, isLandscape: false, width: 800, height: 600 }
} as LaunchOptions;
// Only for dry runs. In a real run, a mobile viewport makes Puppeteer reload the page
// when a recording's setViewport step sets isMobile: false.
...(dryRun && { defaultViewport: { isMobile: true, isLandscape: false, width: 800, height: 600 } }),
};
const cliMode = detectCliMode();
// cli mode is "CI" or "SANDBOX"
if (cliMode !== 'DEFAULT' && launchOptions) {
const headlessMode = 'new';
logVerbose(`Set options#headless to ${headlessMode} in puppeteer#launch as we are running in ${cliMode} mode`);
(launchOptions as { headless?: unknown }).headless = headlessMode;
// `true` is Chrome's new headless mode since Puppeteer v22, `'new'` is no longer a valid value
logVerbose(`Set options#headless to true in puppeteer#launch as we are running in ${cliMode} mode`);
launchOptions.headless = true;
}

return launchOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { parseLaunchOptions } from './collect-flow.js';
import * as cliMode from '../../../../global/cli-mode/cli-mode.js';

vi.mock('../../../../core/loggin/index.js', () => ({ logVerbose: vi.fn() }));

describe('parseLaunchOptions', () => {
afterEach(() => {
vi.restoreAllMocks();
});

it('should keep the browser visible by default in DEFAULT mode', () => {
vi.spyOn(cliMode, 'detectCliMode').mockReturnValue('DEFAULT');
expect(parseLaunchOptions().headless).toBe(false);
});

it('should use the default viewport of Puppeteer if no launch options are given', () => {
vi.spyOn(cliMode, 'detectCliMode').mockReturnValue('DEFAULT');
expect(parseLaunchOptions().defaultViewport).toBeUndefined();
});

it('should use a mobile viewport for a dry run if no launch options are given', () => {
vi.spyOn(cliMode, 'detectCliMode').mockReturnValue('DEFAULT');
expect(parseLaunchOptions(undefined, { dryRun: true }).defaultViewport).toEqual({
isMobile: true,
isLandscape: false,
width: 800,
height: 600,
});
});

it('should keep the given launch options for a dry run', () => {
vi.spyOn(cliMode, 'detectCliMode').mockReturnValue('DEFAULT');
expect(parseLaunchOptions({ headless: 'shell' }, { dryRun: true })).toEqual({ headless: 'shell' });
});

it('should keep the given launch options in DEFAULT mode', () => {
vi.spyOn(cliMode, 'detectCliMode').mockReturnValue('DEFAULT');
expect(parseLaunchOptions({ headless: 'shell' })).toEqual({ headless: 'shell' });
});

it.each(['CI', 'SANDBOX'] as const)('should run in new headless mode in %s mode', (mode) => {
vi.spyOn(cliMode, 'detectCliMode').mockReturnValue(mode);
expect(parseLaunchOptions().headless).toBe(true);
expect(parseLaunchOptions({ headless: false }).headless).toBe(true);
});
});
Loading