ci: fix mocha utils (#10496)
This commit is contained in:
parent
d16ca474d3
commit
5a3abb2f5e
@ -39,39 +39,26 @@ import sinon from 'sinon';
|
||||
|
||||
import {extendExpectWithToBeGolden} from './utils.js';
|
||||
|
||||
let processVariables!: {
|
||||
product: string;
|
||||
alternativeInstall: string | boolean;
|
||||
headless: 'true' | 'false' | 'new';
|
||||
isHeadless: boolean;
|
||||
isFirefox: boolean;
|
||||
isChrome: boolean;
|
||||
protocol: 'cdp' | 'webDriverBiDi';
|
||||
defaultBrowserOptions: PuppeteerLaunchOptions;
|
||||
};
|
||||
async function setUpProcessVariables() {
|
||||
const product =
|
||||
const product =
|
||||
process.env['PRODUCT'] || process.env['PUPPETEER_PRODUCT'] || 'chrome';
|
||||
|
||||
const alternativeInstall = process.env['PUPPETEER_ALT_INSTALL'] || false;
|
||||
const alternativeInstall = process.env['PUPPETEER_ALT_INSTALL'] || false;
|
||||
|
||||
const headless = (process.env['HEADLESS'] || 'true').trim().toLowerCase() as
|
||||
const headless = (process.env['HEADLESS'] || 'true').trim().toLowerCase() as
|
||||
| 'true'
|
||||
| 'false'
|
||||
| 'new';
|
||||
const isHeadless = headless === 'true' || headless === 'new';
|
||||
const isFirefox = product === 'firefox';
|
||||
const isChrome = product === 'chrome';
|
||||
const protocol = (process.env['PUPPETEER_PROTOCOL'] || 'cdp') as
|
||||
const isHeadless = headless === 'true' || headless === 'new';
|
||||
const isFirefox = product === 'firefox';
|
||||
const isChrome = product === 'chrome';
|
||||
const protocol = (process.env['PUPPETEER_PROTOCOL'] || 'cdp') as
|
||||
| 'cdp'
|
||||
| 'webDriverBiDi';
|
||||
|
||||
let extraLaunchOptions = {};
|
||||
try {
|
||||
extraLaunchOptions = JSON.parse(
|
||||
process.env['EXTRA_LAUNCH_OPTIONS'] || '{}'
|
||||
);
|
||||
} catch (error) {
|
||||
let extraLaunchOptions = {};
|
||||
try {
|
||||
extraLaunchOptions = JSON.parse(process.env['EXTRA_LAUNCH_OPTIONS'] || '{}');
|
||||
} catch (error) {
|
||||
if (isErrorLike(error)) {
|
||||
console.warn(
|
||||
`Error parsing EXTRA_LAUNCH_OPTIONS: ${error.message}. Skipping.`
|
||||
@ -79,9 +66,9 @@ async function setUpProcessVariables() {
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const defaultBrowserOptions = Object.assign(
|
||||
const defaultBrowserOptions = Object.assign(
|
||||
{
|
||||
handleSIGINT: true,
|
||||
executablePath: process.env['BINARY'],
|
||||
@ -90,22 +77,31 @@ async function setUpProcessVariables() {
|
||||
protocol,
|
||||
},
|
||||
extraLaunchOptions
|
||||
);
|
||||
);
|
||||
|
||||
if (defaultBrowserOptions.executablePath) {
|
||||
if (defaultBrowserOptions.executablePath) {
|
||||
console.warn(
|
||||
`WARN: running ${product} tests with ${defaultBrowserOptions.executablePath}`
|
||||
);
|
||||
} else {
|
||||
} else {
|
||||
const executablePath = puppeteer.executablePath();
|
||||
if (!fs.existsSync(executablePath)) {
|
||||
throw new Error(
|
||||
`Browser is not downloaded at ${executablePath}. Run 'npm install' and try to re-run tests`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processVariables = {
|
||||
const processVariables: {
|
||||
product: string;
|
||||
alternativeInstall: string | boolean;
|
||||
headless: 'true' | 'false' | 'new';
|
||||
isHeadless: boolean;
|
||||
isFirefox: boolean;
|
||||
isChrome: boolean;
|
||||
protocol: 'cdp' | 'webDriverBiDi';
|
||||
defaultBrowserOptions: PuppeteerLaunchOptions;
|
||||
} = {
|
||||
product,
|
||||
alternativeInstall,
|
||||
headless,
|
||||
@ -114,11 +110,7 @@ async function setUpProcessVariables() {
|
||||
isChrome,
|
||||
protocol,
|
||||
defaultBrowserOptions,
|
||||
};
|
||||
}
|
||||
(async (): Promise<void> => {
|
||||
await setUpProcessVariables();
|
||||
})();
|
||||
};
|
||||
|
||||
const setupServer = async () => {
|
||||
const assetsPath = path.join(__dirname, '../assets');
|
||||
|
Loading…
Reference in New Issue
Block a user