Files
YouTubeDL/tests/browser-components.test.mjs
DepressedCat 5f2aad00f4
Check extension and helper / check (push) Canceled after 0s
Publish YouTubeDL 1.4.5 and website on Gitea
2026-10-10 23:53:17 +03:00

54 lines
3.3 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs/promises";
import path from "node:path";
import os from "node:os";
import { fileURLToPath } from "node:url";
import { chromium } from "playwright";
const root=path.dirname(path.dirname(fileURLToPath(import.meta.url)));
const artifacts=path.join(root,'test-artifacts');
await fs.mkdir(artifacts,{recursive:true});
const profile=await fs.mkdtemp(path.join(os.tmpdir(),'ytdl-components-test-'));
const context=await chromium.launchPersistentContext(profile,{
headless:true,viewport:{width:1000,height:900},
executablePath:'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
ignoreDefaultArgs:['--disable-extensions'],args:['--enable-unsafe-extension-debugging'],
});
try {
const cdp=await context.browser().newBrowserCDPSession();
const {id}=await cdp.send('Extensions.loadUnpacked',{path:path.join(root,'extension')});
const worker=context.serviceWorkers()[0] || await context.waitForEvent('serviceworker');
await worker.evaluate(() => chrome.storage.local.set({ onboarding: { state: "complete", version: 1 } }));
const page=await context.newPage(); let installerDownloads=0;
page.on('download',()=>installerDownloads++);
await page.goto(`chrome-extension://${id}/downloader.html`);
await page.locator('#helper-panel[data-state="running"]').waitFor({timeout:90000});
await page.locator('#helper-panel > summary').click();
assert.equal(await page.locator('#helper-install').textContent(),'Переустановить');
const automatic=await page.locator('#auto-update').isChecked();
if(automatic) await page.locator('#auto-update').uncheck();
await page.locator('#helper-update').click();
const deadline=Date.now()+240000; let job;
while(Date.now()<deadline) {
const jobs=await worker.evaluate(async()=>Object.values((await chrome.storage.local.get('jobs')).jobs || {}));
job=jobs.find(item=>item.kind==='update');
if(job && job.status!=='running') break;
await new Promise(resolve=>setTimeout(resolve,200));
}
assert.ok(job); assert.equal(job.status,'complete',job.error);
assert.equal(installerDownloads,0,'Update components must use the helper, not download the embedded EXE');
await page.locator('#helper-panel[data-state="running"]').waitFor({timeout:90000});
await page.locator('#helper-update:not([disabled])').waitFor({timeout:30000});
assert.equal(await page.locator('.dependency-row[data-status="installed"]').count(),5);
assert.equal(await page.locator('#engine option[value="nvenc"]').isDisabled(),false);
assert.equal(await page.locator('#engine option[value="amf"]').isDisabled(),true);
await page.locator('#auto-update').setChecked(automatic);
await page.locator('.dependencies summary').click();
await page.screenshot({path:path.join(artifacts,'component-updater.png'),animations:'disabled'});
await fs.writeFile(path.join(artifacts,'browser-components.json'),JSON.stringify({updateButton:'passed',installerDownloads,job,automatic},null,2));
console.log('Browser component update passed: real native request, official version check, completed progress, ready tools, preserved automatic-update setting, no EXE download.');
} finally {
await context.close();
if(path.dirname(path.resolve(profile))===path.resolve(os.tmpdir()) && path.basename(profile).startsWith('ytdl-components-test-')) await fs.rm(profile,{recursive:true,force:true});
}