shots / console: resolve playwright only from an installed node_modules copy; in a project without playwright Bun auto-installed the newest one into its global cache, whose browsers were never downloaded (capture-web on Linux CI: 'headless shell: not installed'; macOS hid it with Google Chrome)

This commit is contained in:
CRTkafa 2026-10-13 02:55:12 +08:00
parent 56591f4118
commit b9579e2a2e
2 changed files with 26 additions and 1 deletions

View file

@ -8,7 +8,7 @@ import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync
import { hostname, tmpdir } from 'node:os';
import { join } from 'node:path';
import { openConsoleBrowser } from '../cli/console/session';
import { installedBrowsers, launch, launchCandidates, launchPersistent, persistentExecutable, profileHolder } from '../cli/shots/browser';
import { chromiumFor, installedBrowsers, isInstalledPackage, launch, launchCandidates, launchPersistent, persistentExecutable, profileHolder } from '../cli/shots/browser';
/* eslint-disable @typescript-eslint/no-explicit-any */
@ -139,3 +139,21 @@ describe('console fill', () => {
expect(f.calls).toEqual([]);
});
});
describe('playwright resolution', () => {
test('a project without playwright uses storebound\'s installed copy, never a Bun auto-install of the newest one', async () => {
// regression (Linux CI): `shots capture` in a temp project resolved playwright through Bun's auto-install (the
// newest version, in ~/.bun/install/cache) whose browser build was not downloaded: "headless shell: not installed"
expect(isInstalledPackage('/p/node_modules/playwright/index.mjs')).toBe(true);
expect(isInstalledPackage('C:\\p\\node_modules\\playwright\\index.mjs')).toBe(true);
expect(isInstalledPackage('/root/.bun/install/cache/playwright@1.64.0@@@1/index.mjs')).toBe(false);
const bare = mkdtempSync(join(tmpdir(), 'sb-no-playwright-'));
try {
// in a child whose cwd has no node_modules, like a real run in such a project (auto-install is on there)
const mod = JSON.stringify(join(import.meta.dir, '..', 'cli', 'shots', 'browser.ts'));
const r = Bun.spawnSync(['bun', '-e', `const { chromiumFor } = await import(${mod}); console.log((await chromiumFor(process.cwd())).executablePath());`], { cwd: bare });
const own = await chromiumFor(join(import.meta.dir, '..'));
expect(r.stdout.toString().trim()).toBe(own.executablePath());
} finally { rmSync(bare, { recursive: true, force: true }); }
});
});