chore: launcher test should respect headless (#10625)
This commit is contained in:
parent
186b994fba
commit
7d97b5804f
@ -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,42 +555,42 @@ 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)(
|
||||||
const {defaultBrowserOptions} = await getTestState({
|
'should launch Chrome properly with --no-startup-window and waitForInitialPage=false',
|
||||||
skipLaunch: true,
|
async () => {
|
||||||
});
|
const {defaultBrowserOptions} = await getTestState({
|
||||||
const options = {
|
skipLaunch: true,
|
||||||
waitForInitialPage: false,
|
});
|
||||||
// This is needed to prevent Puppeteer from adding an initial blank page.
|
const options = {
|
||||||
// See also https://github.com/puppeteer/puppeteer/blob/ad6b736039436fcc5c0a262e5b575aa041427be3/src/node/Launcher.ts#L200
|
waitForInitialPage: false,
|
||||||
ignoreDefaultArgs: true,
|
// This is needed to prevent Puppeteer from adding an initial blank page.
|
||||||
...defaultBrowserOptions,
|
// See also https://github.com/puppeteer/puppeteer/blob/ad6b736039436fcc5c0a262e5b575aa041427be3/src/node/Launcher.ts#L200
|
||||||
args: ['--no-startup-window'],
|
ignoreDefaultArgs: true,
|
||||||
};
|
...defaultBrowserOptions,
|
||||||
const {browser, close} = await launch(options, {
|
args: ['--no-startup-window'],
|
||||||
createContext: false,
|
};
|
||||||
});
|
const {browser, close} = await launch(options, {
|
||||||
try {
|
createContext: false,
|
||||||
const pages = await browser.pages();
|
});
|
||||||
expect(pages).toHaveLength(0);
|
try {
|
||||||
} finally {
|
const pages = await browser.pages();
|
||||||
await close();
|
expect(pages).toHaveLength(0);
|
||||||
|
} finally {
|
||||||
|
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user