shots: Playwright's chromium is taken from the namespace or default of a project's CommonJS playwright; a module without chromium.launch names the resolved file and its exports (a project's playwright 1.57 under a global Bun install gave 'reading launch of undefined'); tests: the review-account fixture typechecks

This commit is contained in:
CRTkafa 2026-10-20 13:44:22 +07:00
parent ac84ad4bbf
commit 353e13d5be
4 changed files with 43 additions and 3 deletions

View file

@ -26,6 +26,9 @@ import { compiled } from '../lib/runner';
import * as rt from '../lib/rt';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
/** A playwright module that resolved but does not have the API: named, so the error says which file it was. */
class PlaywrightShapeError extends Error {}
async function chromium(root: string): Promise<any> {
for (const base of [root, rt.packageRoot()]) {
try {
@ -34,8 +37,13 @@ async function chromium(root: string): Promise<any> {
// cache (~/.bun/install/cache), whose browser build was never downloaded ("headless shell: not installed" on
// Linux CI, where no Google Chrome hides it); storebound's own copy is next
if (!isInstalledPackage(p)) continue;
return (await rt.importPath(p)).chromium;
} catch { /* next */ }
// playwright's entry is CommonJS: depending on the runtime and version the ESM import puts chromium on the
// namespace or only under default (a project's playwright 1.57 under a global Bun install gave undefined)
const m = await rt.importPath(p);
const c = m?.chromium ?? m?.default?.chromium;
if (!c || typeof c.launch !== 'function') throw new PlaywrightShapeError(`playwright at ${p} has no chromium.launch (exports: ${Object.keys(m ?? {}).slice(0, 8).join(', ') || 'none'}${m?.default ? `; default: ${Object.keys(m.default).slice(0, 8).join(', ')}` : ''})`);
return c;
} catch (e) { if (e instanceof PlaywrightShapeError) throw e; /* next */ }
}
// only reached in the compiled sidecar: the bundled playwright-core (not a runtime dependency of the npm package)
if (compiled()) return (await import('playwright-core')).chromium;