From 636a28470e8d926070cc3caa0b7e9a70c5750436 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Wed, 14 Oct 2026 14:19:30 +0000 Subject: [PATCH] fix(ci): launch the installed Chrome version in browser tests --- .github/workflows/main-windows.yml | 9 ---- .github/workflows/main.yml | 9 ---- docs/src/contributing.md | 15 +++++++ scripts/install-puppeteer.mjs | 71 ++++++++++++++++-------------- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/.github/workflows/main-windows.yml b/.github/workflows/main-windows.yml index 7a5abc74f..0d94deef8 100644 --- a/.github/workflows/main-windows.yml +++ b/.github/workflows/main-windows.yml @@ -191,16 +191,7 @@ jobs: path: | /c/users/runneradmin/.cache/puppeteer - # NOTE: We can stop pinning the version of puppeteer when the version that the mac atttempts to use - # syncs up (right now newest is 148.0.7778.178, but puppeteer will attempt to use 148.0.7778.97) - - name: Install puppeteer (pinned) - if: ${{ matrix.node == 'latest' }} - run: | - export PUPPETEER_VERSION=148.0.7778.97 - pnpm run test:setup:puppeteer - - name: Install puppeteer - if: ${{ matrix.node != 'latest' }} run: | pnpm run test:setup:puppeteer diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ce7cbbbe..3d9846203 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -261,16 +261,7 @@ jobs: path: | /Users/runner/.cache/puppeteer - # NOTE: We can stop pinning the version of puppeteer when the version that the mac atttempts to use - # syncs up (right now newest is 148.0.7778.178, but puppeteer will attempt to use 148.0.7778.97) - - name: Install puppeteer (pinned) - if: ${{ matrix.node == 'latest' }} - run: | - export PUPPETEER_VERSION=148.0.7778.97 - pnpm run test:setup:puppeteer - - name: Install puppeteer - if: ${{ matrix.node != 'latest' }} run: | pnpm run test:setup:puppeteer diff --git a/docs/src/contributing.md b/docs/src/contributing.md index 51553f02f..b80bfdb83 100644 --- a/docs/src/contributing.md +++ b/docs/src/contributing.md @@ -88,6 +88,21 @@ There are three test suites in jco: > > The command above runs a single test file -- the name of the file is relative to `packages/jco/test`. +### Browser test setup + +Install Chrome and select the installed executable before running browser tests: + +```sh +export PUPPETEER_EXECUTABLE_PATH="$(node scripts/install-puppeteer.mjs)" +``` + +The installer downloads the current stable Chrome release by default. +Set `PUPPETEER_VERSION` to an exact Chrome for Testing version to pin the installation. +The script prints the executable path to stdout and diagnostics to stderr. +GitHub Actions jobs automatically receive `PUPPETEER_EXECUTABLE_PATH` through `GITHUB_ENV`, +so tests use the installed version even when Puppeteer expects a different revision. +This also applies when the browser is already cached. + ### Testing Rust-side bindgen changes When working on the Rust bindgen crate (`crates/js-component-bindgen`), you generally must build `jco-transpile` to see diff --git a/scripts/install-puppeteer.mjs b/scripts/install-puppeteer.mjs index 05ecc8304..9055c6571 100644 --- a/scripts/install-puppeteer.mjs +++ b/scripts/install-puppeteer.mjs @@ -1,6 +1,7 @@ -import * as fs from "node:fs/promises"; -import * as path from "node:path"; -import * as process from "node:process"; +import * as fs from 'node:fs/promises'; +import { homedir } from 'node:os'; +import * as path from 'node:path'; +import * as process from 'node:process'; import { Browser, @@ -10,41 +11,39 @@ import { detectBrowserPlatform, install, resolveBuildId, -} from "@puppeteer/browsers"; +} from '@puppeteer/browsers'; /** * Robustly install puppeteer, handling the case where browser folder * exists but the executable is missing. */ async function main() { - const requestedBrowser = process.argv[2] ?? "chrome"; - if (requestedBrowser !== "chrome" && requestedBrowser !== "firefox") { + const requestedBrowser = process.argv[2] ?? 'chrome'; + if (requestedBrowser !== 'chrome' && requestedBrowser !== 'firefox') { throw new Error(`unsupported Puppeteer browser: ${requestedBrowser}`); } - const browser = requestedBrowser === "firefox" ? Browser.FIREFOX : Browser.CHROME; + const platform = detectBrowserPlatform(); + if (!platform) { + throw new Error('Could not detect browser platform'); + } + + const browser = requestedBrowser === 'firefox' ? Browser.FIREFOX : Browser.CHROME; let buildId = - requestedBrowser === "firefox" ? process.env.PUPPETEER_FIREFOX_VERSION : process.env.PUPPETEER_VERSION; + requestedBrowser === 'firefox' ? process.env.PUPPETEER_FIREFOX_VERSION : process.env.PUPPETEER_VERSION; if (!buildId) { buildId = await resolveBuildId( browser, - process.platform, - requestedBrowser === "firefox" ? BrowserTag.NIGHTLY : ChromeReleaseChannel.STABLE, + platform, + requestedBrowser === 'firefox' ? BrowserTag.NIGHTLY : ChromeReleaseChannel.STABLE, ); } if (!buildId) { - throw new Error("failed to resovle build ID"); - } - - const platform = detectBrowserPlatform(); - if (!platform) { - throw new Error("Could not detect browser platform"); + throw new Error('failed to resolve build ID'); } - const cacheDir = - process.env.PUPPETEER_CACHE_DIR ?? - path.join(process.env.HOME ?? process.cwd(), ".cache", "puppeteer"); + const cacheDir = process.env.PUPPETEER_CACHE_DIR ?? path.join(homedir(), '.cache', 'puppeteer'); const executablePath = computeExecutablePath({ browser, @@ -56,26 +55,30 @@ async function main() { try { await fs.access(executablePath); console.error(`[info] ${requestedBrowser} already installed: ${executablePath}`); - return; } catch { const browserDir = path.join(cacheDir, browser, `${platform}-${buildId}`); console.error(`[info] executable missing; removing incomplete install: ${browserDir}`); await fs.rm(browserDir, { recursive: true, force: true }); - } - const installedBrowser = await install({ - browser, - buildId, - cacheDir, - platform, - }); + const installedBrowser = await install({ + browser, + buildId, + cacheDir, + platform, + }); - await fs.access(installedBrowser.executablePath); - console.error(`[info] ${requestedBrowser} installed: ${installedBrowser.executablePath}`); + await fs.access(installedBrowser.executablePath); + console.error(`[info] ${requestedBrowser} installed: ${installedBrowser.executablePath}`); + } + + // Puppeteer's default revision can differ from the browser we just installed. + if (browser === Browser.CHROME && process.env.GITHUB_ENV) { + await fs.appendFile(process.env.GITHUB_ENV, `PUPPETEER_EXECUTABLE_PATH=${executablePath}\n`); + } + console.log(executablePath); } -main() - .catch((err) => { - console.error(err); - process.exit(1); - }); +main().catch((err) => { + console.error(err); + process.exit(1); +});