mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
fix(test): prevent expensive setup in beforeAll when test will be skipped
On platforms where Puppeteer is unsupported (Linux arm64, Windows CI), the beforeAll hooks were still running expensive operations like `bun install` and copying files, causing timeouts. Changes: - Move skip condition check to top of file - Add early return in beforeAll hooks when test will be skipped - Disable Puppeteer pipe mode on macOS to prevent flaky "TargetCloseError: Protocol error (Target.setDiscoverTargets)" errors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import assert from "assert";
|
||||
import { which } from "bun";
|
||||
import { copyFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
import type { ConsoleMessage, Page } from "puppeteer";
|
||||
import { launch } from "puppeteer";
|
||||
import { which } from "bun";
|
||||
const root = join(import.meta.dir, "../");
|
||||
|
||||
copyFileSync(join(root, "src/Counter1.txt"), join(root, "src/Counter.tsx"));
|
||||
@@ -25,7 +25,8 @@ const b = await launch({
|
||||
// Inherit the stdout and stderr of the browser process.
|
||||
dumpio: true,
|
||||
// Prefer to use a pipe to connect to the browser, instead of a WebSocket.
|
||||
pipe: true,
|
||||
// On macOS, pipe mode can cause "TargetCloseError: Protocol error (Target.setDiscoverTargets): Target closed"
|
||||
pipe: process.platform !== "darwin",
|
||||
// Disable timeouts.
|
||||
timeout: 0,
|
||||
protocolTimeout: 0,
|
||||
|
||||
@@ -10,9 +10,18 @@ const { parseLockfile } = install_test_helpers;
|
||||
|
||||
expect.extend({ toMatchNodeModulesAt });
|
||||
|
||||
// Chrome for Testing doesn't support arm64 yet
|
||||
// https://github.com/GoogleChromeLabs/chrome-for-testing/issues/1
|
||||
// https://github.com/puppeteer/puppeteer/issues/7740
|
||||
const puppeteer_unsupported = process.platform === "linux" && process.arch === "arm64";
|
||||
|
||||
// https://github.com/oven-sh/bun/issues/11255
|
||||
const shouldSkip = puppeteer_unsupported || (isWindows && isCI);
|
||||
|
||||
let root = tmpdirSync();
|
||||
|
||||
beforeAll(async () => {
|
||||
if (shouldSkip) return;
|
||||
await rm(root, { recursive: true, force: true });
|
||||
await cp(join(import.meta.dir, "../"), root, { recursive: true, force: true });
|
||||
await rm(join(root, ".next"), { recursive: true, force: true });
|
||||
@@ -86,6 +95,7 @@ async function getDevServerURL() {
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
if (shouldSkip) return;
|
||||
copyFileSync(join(root, "src/Counter1.txt"), join(root, "src/Counter.tsx"));
|
||||
|
||||
const install = Bun.spawnSync([bunExe(), "i"], {
|
||||
@@ -116,14 +126,7 @@ afterAll(() => {
|
||||
}
|
||||
});
|
||||
|
||||
// Chrome for Testing doesn't support arm64 yet
|
||||
//
|
||||
// https://github.com/GoogleChromeLabs/chrome-for-testing/issues/1
|
||||
// https://github.com/puppeteer/puppeteer/issues/7740
|
||||
const puppeteer_unsupported = process.platform === "linux" && process.arch === "arm64";
|
||||
|
||||
// https://github.com/oven-sh/bun/issues/11255
|
||||
test.skipIf(puppeteer_unsupported || (isWindows && isCI))(
|
||||
test.skipIf(shouldSkip)(
|
||||
"hot reloading works on the client (+ tailwind hmr)",
|
||||
async () => {
|
||||
expect(dev_server).not.toBeUndefined();
|
||||
|
||||
Reference in New Issue
Block a user