Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat: set default headless mode (#239)
Browse files Browse the repository at this point in the history
* set default headless mode

* update headless parameter
  • Loading branch information
Lykhoyda authored Jan 13, 2023
1 parent 0a8d442 commit 9fcb540
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
6 changes: 5 additions & 1 deletion src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export const bootstrap = async ({
browser: DappeteerBrowser;
metaMaskPage: DappeteerPage;
}> => {
const browser = await launch(launchOptions);
const browser = await launch({
headless: true,
...launchOptions,
});
const metaMask = await setupMetaMask(browser, {
seed,
password,
Expand All @@ -43,6 +46,7 @@ export const initSnapEnv = async (
snapId: string;
}> => {
const browser = await launch({
headless: true,
...opts,
metaMaskFlask: true,
});
Expand Down
8 changes: 5 additions & 3 deletions src/setup/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ export async function launch(
);
else
console.log(
`Running tests on MetaMask version ${metaMaskVersion} (flask: ${String(
options.metaMaskFlask ?? false
)})`
`
Running tests on MetaMask version ${metaMaskVersion}
Flask version: ${String(options.metaMaskFlask ?? false)},
Headless: ${String(options.headless)}
`
);

console.warn(); // new line
Expand Down
4 changes: 2 additions & 2 deletions src/setup/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export async function launchPlaywright(
await import("playwright")
).chromium.launchPersistentContext(tmpdir, {
...(options.playwrightOptions ?? {}),
headless: options.playwrightOptions?.headless,
headless: options.headless,
args: [
`--disable-extensions-except=${metamaskPath}`,
`--load-extension=${metamaskPath}`,
...(options.playwrightOptions?.args || []),
...(options.puppeteerOptions?.headless ? ["--headless=chrome"] : []),
...(options.headless ? ["--headless=chrome"] : []),
],
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/setup/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export async function launchPuppeteer(
await import("puppeteer")
).default.launch({
...(options.puppeteerOptions ?? {}),
headless: options.puppeteerOptions?.headless,
headless: options.headless,
args: [
`--disable-extensions-except=${metamaskPath}`,
`--load-extension=${metamaskPath}`,
...(options.puppeteerOptions?.args || []),
...(options.puppeteerOptions?.headless ? ["--headless=chrome"] : []),
...(options.headless ? ["--headless=chrome"] : []),
],
});
const { DPuppeteerBrowser } = await import("../puppeteer");
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type DappeteerLaunchOptions = {
//fallbacks to installed dependency and prefers playwright if both are installed
automation?: "puppeteer" | "playwright";
browser: "chrome";
headless?: boolean; // default true
puppeteerOptions?: Parameters<typeof puppeteerLaunch>[0];
playwrightOptions?: PlaywrightLaunchOptions;
};
Expand Down
6 changes: 0 additions & 6 deletions test/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ export const mochaHooks = {
browser: "chrome",
metaMaskVersion:
process.env.METAMASK_VERSION || dappeteer.RECOMMENDED_METAMASK_VERSION,
playwrightOptions: {
headless: true,
},
puppeteerOptions: {
headless: true,
},
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
6 changes: 0 additions & 6 deletions test/global_flask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export const mochaHooks = {
metaMaskVersion:
process.env.METAMASK_VERSION || dappeteer.RECOMMENDED_METAMASK_VERSION,
metaMaskFlask: true,
playwrightOptions: {
headless: true,
},
puppeteerOptions: {
headless: true,
},
});

const snapServers = await buildSnaps();
Expand Down

0 comments on commit 9fcb540

Please sign in to comment.