← Files JUJIES ArbeitsblätterARCHIVED FILE

tests/check-browser-runtime.mjs

2.73 KB · Nov 11, 2026 · 13:26 UTC

↓ Download file

import assert from 'node:assert/strict';
import {launchBrowser} from '../skills/arbeitsblatt-html/scripts/browser-runtime.mjs';

const missing=()=>new Error("browserType.launch: Executable doesn't exist at missing");
function fixture({existing=[],defaultError=missing(),installError}={}) {
 const calls=[],downloads=[],browser={close:async()=>{}};
 const pw={chromium:{executablePath:()=>'/browser/full-chromium',launch:async options=>{calls.push(options);if(!options.executablePath&&defaultError)throw defaultError;return browser;}}};
 const require={resolve:()=>'/modules/playwright/package.json'};
 const run=(cmd,args)=>{if(args[0]?.endsWith('cli.js')){downloads.push([cmd,args]);if(installError)throw installError;defaultError=null;return '';}throw new Error('not found');};
 return {options:{pw,require,run,exists:p=>existing.includes(p)},calls,downloads,browser};
}
let f=fixture({defaultError:null});assert.equal(await launchBrowser(f.options),f.browser);assert.equal(f.downloads.length,0);
f=fixture({existing:['/browser/full-chromium']});await launchBrowser(f.options);assert.equal(f.calls[1].executablePath,'/browser/full-chromium');assert.equal(f.downloads.length,0);
f=fixture({existing:['/explicit/chrome']});await launchBrowser({...f.options,executablePath:'/explicit/chrome'});assert.equal(f.calls.length,1);
f=fixture();await assert.rejects(launchBrowser({...f.options,executablePath:'relative'}),/absolute/);assert.equal(f.calls.length,0);
f=fixture();await assert.rejects(launchBrowser(f.options),/Kein Chromium/);assert.equal(f.downloads.length,0);
f=fixture();await launchBrowser({...f.options,installBrowser:true});assert.deepEqual(f.downloads[0],[process.execPath,['/modules/playwright/cli.js','install','chromium','--only-shell']]);assert.equal(f.calls.length,2);
f=fixture({installError:new Error('network blocked')});await assert.rejects(launchBrowser({...f.options,installBrowser:true}),/network blocked/);
f=fixture({defaultError:new Error('sandbox permission denied')});await assert.rejects(launchBrowser({...f.options,installBrowser:true}),/permission denied/);assert.equal(f.downloads.length,0);
f=fixture({installError:Object.assign(new Error('download failed'),{stdout:'Official CDN: 100% of 0 MiB',stderr:'End of central directory record signature not found. file is truncated.'})});
const events=[];
await assert.rejects(launchBrowser({...f.options,installBrowser:true,onRuntime:r=>events.push(r)}),/ungültiges oder abgeschnittenes ZIP/);
assert.equal(f.downloads.length,1);assert.equal(events.at(-1).reason,'invalid-browser-archive');
assert.equal(events.at(-1).stdout,'Official CDN: 100% of 0 MiB');assert.match(events.at(-1).stderr,/central directory/);
console.log(JSON.stringify({ok:true,cases:9,downloadOptIn:true,unrelatedFailuresPreserved:true}));

SHA-256: 6fc6182e1c268d3c4b45da2263fcd15cf90e0a2dce53c15491d8197f7bff65d2