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
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,15 +43,19 @@ export async function collectFlow(
return flow;
}

export 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ describe('parseLaunchOptions', () => {
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' });
Expand Down
Loading