Skip to content

Commit

Permalink
fix: close puppeteer browser instance
Browse files Browse the repository at this point in the history
  • Loading branch information
amilajack committed Feb 9, 2023
1 parent ed49b50 commit 94c59c2
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/helpers/ast-node-types-tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ export function getJsAssertions(
};
}

// @hack enable infinity event listener chaining
process.setMaxListeners(0);

/**
* @HACK: Tests wont run unless the tests are parallelized across browsers
* This is a temporary solution that creates two browser sessions and
Expand All @@ -205,15 +208,24 @@ export function getJsAssertions(
async function parallelizeBrowserTests<T>(tests: string[]): Promise<T[]> {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://example.com");
const res = await page.evaluate(
// eslint-disable-next-line no-eval
(compatTest: string) => eval(compatTest),
`(function() {
return [${tests.join(",")}];
})()`
);
await page.close();
let res: T[] = [];

try {
await page.goto("https://example.com");
res = await page.evaluate(
// eslint-disable-next-line no-eval
(compatTest: string) => eval(compatTest),
`(function() {
return [${tests.join(",")}];
})()`
);
} catch (e) {
console.error(e);
} finally {
await page.close();
await browser.close();
}

return res;
}

Expand Down

0 comments on commit 94c59c2

Please sign in to comment.