Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/main-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions docs/src/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 37 additions & 34 deletions scripts/install-puppeteer.mjs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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);
});
Loading