chore: launcher test should respect headless (#10625)

This commit is contained in:
Nikolay Vitkov 2023-07-25 09:06:35 +02:00 committed by GitHub
parent 186b994fba
commit 7d97b5804f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,12 @@ import {Page} from 'puppeteer-core/internal/api/Page.js';
import {rmSync} from 'puppeteer-core/internal/node/util/fs.js'; import {rmSync} from 'puppeteer-core/internal/node/util/fs.js';
import sinon from 'sinon'; import sinon from 'sinon';
import {getTestState, itOnlyRegularInstall, launch} from './mocha-utils.js'; import {
getTestState,
itOnlyRegularInstall,
launch,
isHeadless,
} from './mocha-utils.js';
import {dumpFrames, waitEvent} from './utils.js'; import {dumpFrames, waitEvent} from './utils.js';
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-'); const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
@ -331,7 +336,9 @@ describe('Launcher specs', function () {
} catch {} } catch {}
}); });
it('should return the default arguments', async () => { it('should return the default arguments', async () => {
const {isChrome, isFirefox, puppeteer} = await getTestState(); const {isChrome, isFirefox, puppeteer} = await getTestState({
skipLaunch: true,
});
if (isChrome) { if (isChrome) {
expect(puppeteer.defaultArgs()).toContain('--no-first-run'); expect(puppeteer.defaultArgs()).toContain('--no-first-run');
@ -371,7 +378,9 @@ describe('Launcher specs', function () {
} }
}); });
it('should report the correct product', async () => { it('should report the correct product', async () => {
const {isChrome, isFirefox, puppeteer} = await getTestState(); const {isChrome, isFirefox, puppeteer} = await getTestState({
skipLaunch: true,
});
if (isChrome) { if (isChrome) {
expect(puppeteer.product).toBe('chrome'); expect(puppeteer.product).toBe('chrome');
} else if (isFirefox) { } else if (isFirefox) {
@ -476,10 +485,9 @@ describe('Launcher specs', function () {
} }
}); });
it('should pass the timeout parameter to browser.waitForTarget', async () => { it('should pass the timeout parameter to browser.waitForTarget', async () => {
const {defaultBrowserOptions} = await getTestState(); const options = {
const options = Object.assign({}, defaultBrowserOptions, {
timeout: 1, timeout: 1,
}); };
let error!: Error; let error!: Error;
await launch(options).catch(error_ => { await launch(options).catch(error_ => {
return (error = error_); return (error = error_);
@ -547,21 +555,20 @@ describe('Launcher specs', function () {
} }
}); });
it('should not allow setting debuggingPort and pipe', async () => { it('should not allow setting debuggingPort and pipe', async () => {
const {defaultBrowserOptions} = await getTestState(); const options = {
const options = Object.assign({}, defaultBrowserOptions, {
defaultViewport: null, defaultViewport: null,
debuggingPort: 9999, debuggingPort: 9999,
pipe: true, pipe: true,
}); };
let error!: Error; let error!: Error;
await launch(options).catch(error_ => { await launch(options).catch(error_ => {
return (error = error_); return (error = error_);
}); });
expect(error.message).toContain('either pipe or debugging port'); expect(error.message).toContain('either pipe or debugging port');
}); });
it('should launch Chrome properly with --no-startup-window and waitForInitialPage=false', async () => { (!isHeadless ? it : it.skip)(
'should launch Chrome properly with --no-startup-window and waitForInitialPage=false',
async () => {
const {defaultBrowserOptions} = await getTestState({ const {defaultBrowserOptions} = await getTestState({
skipLaunch: true, skipLaunch: true,
}); });
@ -582,7 +589,8 @@ describe('Launcher specs', function () {
} finally { } finally {
await close(); await close();
} }
}); }
);
}); });
describe('Puppeteer.launch', function () { describe('Puppeteer.launch', function () {
@ -861,14 +869,18 @@ describe('Launcher specs', function () {
}); });
describe('Puppeteer.executablePath', function () { describe('Puppeteer.executablePath', function () {
itOnlyRegularInstall('should work', async () => { itOnlyRegularInstall('should work', async () => {
const {puppeteer} = await getTestState(); const {puppeteer} = await getTestState({
skipLaunch: true,
});
const executablePath = puppeteer.executablePath(); const executablePath = puppeteer.executablePath();
expect(fs.existsSync(executablePath)).toBe(true); expect(fs.existsSync(executablePath)).toBe(true);
expect(fs.realpathSync(executablePath)).toBe(executablePath); expect(fs.realpathSync(executablePath)).toBe(executablePath);
}); });
it('returns executablePath for channel', async () => { it('returns executablePath for channel', async () => {
const {puppeteer} = await getTestState(); const {puppeteer} = await getTestState({
skipLaunch: true,
});
const executablePath = puppeteer.executablePath('chrome'); const executablePath = puppeteer.executablePath('chrome');
expect(executablePath).toBeTruthy(); expect(executablePath).toBeTruthy();
@ -877,7 +889,9 @@ describe('Launcher specs', function () {
const sandbox = sinon.createSandbox(); const sandbox = sinon.createSandbox();
beforeEach(async () => { beforeEach(async () => {
const {puppeteer} = await getTestState(); const {puppeteer} = await getTestState({
skipLaunch: true,
});
sandbox sandbox
.stub(puppeteer.configuration, 'executablePath') .stub(puppeteer.configuration, 'executablePath')
.value('SOME_CUSTOM_EXECUTABLE'); .value('SOME_CUSTOM_EXECUTABLE');
@ -888,7 +902,9 @@ describe('Launcher specs', function () {
}); });
it('its value is used', async () => { it('its value is used', async () => {
const {puppeteer} = await getTestState(); const {puppeteer} = await getTestState({
skipLaunch: true,
});
try { try {
puppeteer.executablePath(); puppeteer.executablePath();
} catch (error) { } catch (error) {