Skip to content

Commit

Permalink
feat(chromium): fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed Dec 6, 2022
1 parent 00bed8b commit 1595f98
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/node/ChromeLauncher.ts
Expand Up @@ -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'
);
Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/node/LaunchOptions.ts
Expand Up @@ -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}
Expand Down
8 changes: 5 additions & 3 deletions test/src/browser.spec.ts
Expand Up @@ -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'
);
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/src/mocha-utils.ts
Expand Up @@ -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';
Expand All @@ -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',
},
Expand Down Expand Up @@ -172,8 +172,8 @@ if (
}
-> mode: ${
isHeadless
? headless === 'chrome'
? '--headless=chrome'
? headless === 'new'
? '--headless=new'
: '--headless'
: 'headful'
}`
Expand Down
20 changes: 17 additions & 3 deletions test/src/navigation.spec.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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');
}
Expand All @@ -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');
}
Expand Down

0 comments on commit 1595f98

Please sign in to comment.