Skip to content

Commit ff484c8

Browse files
committed
test: load the browser fetcher the way puppeteer itself is loaded
`@puppeteer/browsers` is ESM-only, so a `require` of it throws wherever Node does not allow one — before either Firefox path can report a browser problem. Both sites take it by dynamic import now, and the tooling script carries the license header every file under `tooling/` opens with.
1 parent c7cfb0a commit ff484c8

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

‎eslint.config.mjs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ export default defineConfig([
192192
}
193193
},
194194
{
195-
// puppeteer-core is ESM-only (v25+) and is loaded via dynamic import here
195+
// puppeteer-core and @puppeteer/browsers are ESM-only and are loaded via
196+
// dynamic import here
196197
files: ["test/helpers/launchBrowser.js"],
197198
languageOptions: {
198199
ecmaVersion: 2020
@@ -246,6 +247,22 @@ export default defineConfig([
246247
"no-console": "off"
247248
}
248249
},
250+
{
251+
// Fetches a browser for the suites that compare against one, from a package
252+
// that is ESM-only — so it runs on modern Node rather than the baseline.
253+
files: ["tooling/install-firefox.js"],
254+
languageOptions: {
255+
ecmaVersion: 2022
256+
},
257+
rules: {
258+
"n/no-unsupported-features/es-syntax": [
259+
"error",
260+
{
261+
ignores: ["dynamic-import"]
262+
}
263+
]
264+
}
265+
},
249266
{
250267
// The tool comparisons run on modern Node, not webpack's runtime baseline:
251268
// they measure with post-10 APIs (fs.promises, zstd, resourceUsage).

‎test/helpers/launchBrowser.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ const CACHE_DIR = `${os.homedir()}/.cache/puppeteer`;
1111
* @returns {Promise<string | undefined>} the executable path
1212
*/
1313
const installedFirefox = async () => {
14-
const {
15-
Browser,
16-
detectBrowserPlatform,
17-
getInstalledBrowsers
18-
} = require("@puppeteer/browsers");
14+
// ESM-only, like puppeteer-core itself, so it is loaded the same way.
15+
const { Browser, detectBrowserPlatform, getInstalledBrowsers } =
16+
await import("@puppeteer/browsers");
1917

2018
const platform = detectBrowserPlatform();
2119
for (const one of await getInstalledBrowsers({ cacheDir: CACHE_DIR })) {

‎test/wpt‎

Submodule wpt updated 921 files

‎tooling/install-firefox.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Raj Aryan @aryanraj45
4+
*/
5+
16
"use strict";
27

38
// Downloads the Firefox the browser suites compare against, into puppeteer's own
49
// cache rather than into webpack's dependencies. Safe to re-run: an install that
510
// is already there is reported and nothing is fetched.
611

712
const os = require("os");
8-
const {
9-
Browser,
10-
detectBrowserPlatform,
11-
install,
12-
resolveBuildId
13-
} = require("@puppeteer/browsers");
1413

1514
const CACHE_DIR = `${os.homedir()}/.cache/puppeteer`;
1615

1716
(async () => {
17+
// `@puppeteer/browsers` is ESM-only, so it is loaded the way puppeteer itself
18+
// is rather than with `require`.
19+
const { Browser, detectBrowserPlatform, install, resolveBuildId } =
20+
await import("@puppeteer/browsers");
1821
const platform = detectBrowserPlatform();
1922
if (platform === undefined) throw new Error("no browser platform detected");
2023
const buildId = await resolveBuildId(Browser.FIREFOX, platform, "stable");

0 commit comments

Comments
 (0)