Skip to content

Commit

Permalink
feat: Close browser & page
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Aug 13, 2024
1 parent 6034a05 commit a6584d5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions e2e/varnish-cache-preload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const openNewPage = async () => {
});
const context = await browser.newContext();
const page = await context.newPage();
return page;
return { page, browser, context };
};

type ConfigQueryOptions = {
Expand All @@ -54,8 +54,8 @@ const preloadChartsPool = async (
concurrency: number = 4
) => {
const openers = Array.from({ length: concurrency }, (_, i) => openNewPage());
const pages = await Promise.all(openers);
const ready = [...pages];
const contexts = await Promise.all(openers);
const ready = contexts.map((c) => c.page);

const withLocales = configs.flatMap((config) =>
locales.map((locale) => ({ locale, key: config.key }))
Expand All @@ -79,7 +79,13 @@ const preloadChartsPool = async (
const promises = withLocales.map((datum) => limit(() => fetchPage(datum)));
await Promise.all(promises);

await Promise.all(pages.map((page) => page.close()));
await Promise.all(
contexts.map(async ({ browser, page, context }) => {
await page.close();
await context.close();
return browser.close();
})
);
};

const preloadChartsWithOptions = async (
Expand Down

0 comments on commit a6584d5

Please sign in to comment.