|
| 1 | +import fs from "node:fs"; |
| 2 | +import os from "node:os"; |
| 3 | +import path from "node:path"; |
| 4 | + |
| 5 | +import { chromium } from "playwright"; |
| 6 | + |
| 7 | +async function run() { |
| 8 | + const extensionPath = process.cwd(); |
| 9 | + const userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "car-ext-")); |
| 10 | + |
| 11 | + const context = await chromium.launchPersistentContext(userDataDir, { |
| 12 | + channel: "chromium", |
| 13 | + headless: true, |
| 14 | + args: [ |
| 15 | + `--disable-extensions-except=${extensionPath}`, |
| 16 | + `--load-extension=${extensionPath}` |
| 17 | + ] |
| 18 | + }); |
| 19 | + |
| 20 | + try { |
| 21 | + let serviceWorker = context.serviceWorkers()[0]; |
| 22 | + if (!serviceWorker) { |
| 23 | + serviceWorker = await context.waitForEvent("serviceworker", { timeout: 15_000 }); |
| 24 | + } |
| 25 | + |
| 26 | + const extensionId = new URL(serviceWorker.url()).host; |
| 27 | + const dashboardUrl = `chrome-extension://${extensionId}/ui/dashboard.html`; |
| 28 | + const settingsUrl = `chrome-extension://${extensionId}/ui/settings.html`; |
| 29 | + |
| 30 | + const dashboardPage = await context.newPage(); |
| 31 | + await dashboardPage.goto(dashboardUrl, { waitUntil: "domcontentloaded" }); |
| 32 | + |
| 33 | + const heading = await dashboardPage.textContent("h1"); |
| 34 | + const timelineCount = await dashboardPage.locator("#timeline").count(); |
| 35 | + const status = await dashboardPage.evaluate(async () => |
| 36 | + chrome.runtime.sendMessage({ type: "get-runtime-status" }) |
| 37 | + ); |
| 38 | + |
| 39 | + const settingsPage = await context.newPage(); |
| 40 | + await settingsPage.goto(settingsUrl, { waitUntil: "domcontentloaded" }); |
| 41 | + const settingsHeading = await settingsPage.textContent("h1"); |
| 42 | + |
| 43 | + const result = { |
| 44 | + extensionId, |
| 45 | + dashboardHeading: heading, |
| 46 | + timelinePresent: timelineCount > 0, |
| 47 | + runtimeStatusOk: status?.ok === true, |
| 48 | + retentionDays: status?.retentionDays, |
| 49 | + paused: status?.paused, |
| 50 | + settingsHeading |
| 51 | + }; |
| 52 | + |
| 53 | + console.log(JSON.stringify(result, null, 2)); |
| 54 | + |
| 55 | + if ( |
| 56 | + result.dashboardHeading !== "Chrome Activity Reader" || |
| 57 | + !result.timelinePresent || |
| 58 | + result.runtimeStatusOk !== true || |
| 59 | + result.settingsHeading !== "Settings" |
| 60 | + ) { |
| 61 | + process.exitCode = 1; |
| 62 | + } |
| 63 | + } finally { |
| 64 | + await context.close(); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +run().catch((error) => { |
| 69 | + console.error("Extension smoke test failed:", error); |
| 70 | + process.exitCode = 1; |
| 71 | +}); |
0 commit comments