From 1595f98dbf748acd8a01ddedcbbc74b2c3c439dd Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov Date: Tue, 6 Dec 2022 15:28:24 +0100 Subject: [PATCH] feat(chromium): fix test --- .../puppeteer-core/src/node/ChromeLauncher.ts | 2 +- .../puppeteer-core/src/node/LaunchOptions.ts | 2 +- test/src/browser.spec.ts | 8 +++++--- test/src/mocha-utils.ts | 8 ++++---- test/src/navigation.spec.ts | 20 ++++++++++++++++--- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/puppeteer-core/src/node/ChromeLauncher.ts b/packages/puppeteer-core/src/node/ChromeLauncher.ts index 21df6aa3aabe5..6873ef6997a3b 100644 --- a/packages/puppeteer-core/src/node/ChromeLauncher.ts +++ b/packages/puppeteer-core/src/node/ChromeLauncher.ts @@ -204,7 +204,7 @@ export class ChromeLauncher extends ProductLauncher { } if (headless) { chromeArguments.push( - headless === 'chrome' ? '--headless=chrome' : '--headless', + headless === 'new' ? '--headless=new' : '--headless', '--hide-scrollbars', '--mute-audio' ); diff --git a/packages/puppeteer-core/src/node/LaunchOptions.ts b/packages/puppeteer-core/src/node/LaunchOptions.ts index ab10642d1bb1e..af7847a60b5af 100644 --- a/packages/puppeteer-core/src/node/LaunchOptions.ts +++ b/packages/puppeteer-core/src/node/LaunchOptions.ts @@ -27,7 +27,7 @@ export interface BrowserLaunchArgumentOptions { * Whether to run the browser in headless mode. * @defaultValue true */ - headless?: boolean | 'chrome'; + headless?: boolean | 'new'; /** * Path to a user data directory. * {@link https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/user_data_dir.md | see the Chromium docs} diff --git a/test/src/browser.spec.ts b/test/src/browser.spec.ts index 901acfefe4503..ce719e4149f10 100644 --- a/test/src/browser.spec.ts +++ b/test/src/browser.spec.ts @@ -22,11 +22,13 @@ describe('Browser specs', function () { describe('Browser.version', function () { it('should return whether we are in headless', async () => { - const {browser, isHeadless} = getTestState(); - const version = await browser.version(); + const {browser, isHeadless, headless} = getTestState(); + const version = await browser.version(); expect(version.length).toBeGreaterThan(0); - expect(version.startsWith('Headless')).toBe(isHeadless); + expect(version.startsWith('Headless')).toBe( + isHeadless && headless !== 'new' + ); }); }); diff --git a/test/src/mocha-utils.ts b/test/src/mocha-utils.ts index 56da13b6d3a2a..6d30961d1cd4e 100644 --- a/test/src/mocha-utils.ts +++ b/test/src/mocha-utils.ts @@ -66,7 +66,7 @@ const product = const alternativeInstall = process.env['PUPPETEER_ALT_INSTALL'] || false; const headless = (process.env['HEADLESS'] || 'true').trim().toLowerCase(); -const isHeadless = headless === 'true' || headless === 'chrome'; +const isHeadless = headless === 'true' || headless === 'new'; const isFirefox = product === 'firefox'; const isChrome = product === 'chrome'; const protocol = process.env['PUPPETEER_PROTOCOL'] || 'cdp'; @@ -88,7 +88,7 @@ const defaultBrowserOptions = Object.assign( { handleSIGINT: true, executablePath: process.env['BINARY'], - headless: headless === 'chrome' ? ('chrome' as const) : isHeadless, + headless: headless === 'new' ? ('new' as const) : isHeadless, dumpio: !!process.env['DUMPIO'], protocol: protocol as 'cdp' | 'webDriverBiDi', }, @@ -172,8 +172,8 @@ if ( } -> mode: ${ isHeadless - ? headless === 'chrome' - ? '--headless=chrome' + ? headless === 'new' + ? '--headless=new' : '--headless' : 'headful' }` diff --git a/test/src/navigation.spec.ts b/test/src/navigation.spec.ts index fb1434573739a..61e3fc0ac3552 100644 --- a/test/src/navigation.spec.ts +++ b/test/src/navigation.spec.ts @@ -21,6 +21,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, } from './mocha-utils.js'; +import os from 'os'; import {ServerResponse} from 'http'; import {HTTPRequest} from 'puppeteer-core/internal/common/HTTPRequest.js'; import {TimeoutError} from 'puppeteer'; @@ -152,7 +153,20 @@ describe('navigation', function () { } }); - const ExpectedSSLCertMessage = 'net::ERR_CERT_AUTHORITY_INVALID'; + function getExpectedSSLCertMessage(): string { + const {headless} = getTestState(); + /** + * If you are running this on pre-Catalina versions of macOS this will fail + * locally. Mac OSX Catalina outputs a different message than other + * platforms. See https://support.google.com/chrome/thread/18125056?hl=en + * for details. If you're running pre-Catalina Mac OSX this test will fail + * locally. + * In chrome-headless, the message is also different. + */ + return os.platform() === 'darwin' && headless !== 'chrome' + ? 'net::ERR_CERT_INVALID' + : 'net::ERR_CERT_AUTHORITY_INVALID'; + } it('should fail when navigating to bad SSL', async () => { const {page, httpsServer, isChrome} = getTestState(); @@ -175,7 +189,7 @@ describe('navigation', function () { return (error = error_); }); if (isChrome) { - expect(error.message).toContain(ExpectedSSLCertMessage); + expect(error.message).toContain(getExpectedSSLCertMessage()); } else { expect(error.message).toContain('SSL_ERROR_UNKNOWN'); } @@ -194,7 +208,7 @@ describe('navigation', function () { return (error = error_); }); if (isChrome) { - expect(error.message).toContain(ExpectedSSLCertMessage); + expect(error.message).toContain(getExpectedSSLCertMessage()); } else { expect(error.message).toContain('SSL_ERROR_UNKNOWN'); }