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:
parent
ac84ad4bbf
commit
353e13d5be
4 changed files with 43 additions and 3 deletions
28
tests/playwright-resolve.test.ts
Normal file
28
tests/playwright-resolve.test.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// A project's playwright is CommonJS: its chromium may come through the ESM import only under `default`. A playwright
|
||||
// 1.57 project under a global Bun install gave undefined and "Cannot read properties of undefined (reading 'launch')".
|
||||
import { expect, test } from 'bun:test';
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { chromiumFor } from '../cli/shots/browser';
|
||||
|
||||
const fakePlaywright = (body: string): string => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'sb-pw-'));
|
||||
const pkg = join(dir, 'node_modules', 'playwright');
|
||||
mkdirSync(pkg, { recursive: true });
|
||||
writeFileSync(join(pkg, 'package.json'), JSON.stringify({ name: 'playwright', version: '1.57.0', main: 'index.js' }));
|
||||
writeFileSync(join(pkg, 'index.js'), body);
|
||||
writeFileSync(join(dir, 'package.json'), '{"name":"app","private":true}');
|
||||
return dir;
|
||||
};
|
||||
|
||||
test('chromium from a CommonJS playwright, named or under default; a wrong shape names the file', async () => {
|
||||
const named = fakePlaywright('module.exports = { chromium: { launch() { return "ok"; } } };');
|
||||
const viaDefault = fakePlaywright('const api = { chromium: { launch() { return "ok"; } } }; module.exports = { __esModule: true, default: api };');
|
||||
const broken = fakePlaywright('module.exports = { firefox: {} };');
|
||||
try {
|
||||
expect(typeof (await chromiumFor(named)).launch).toBe('function');
|
||||
expect(typeof (await chromiumFor(viaDefault)).launch).toBe('function');
|
||||
await expect(chromiumFor(broken)).rejects.toThrow(/node_modules[\\/]playwright[\\/]index\.js has no chromium\.launch/);
|
||||
} finally { for (const d of [named, viaDefault, broken]) rmSync(d, { recursive: true, force: true }); }
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue