Skip to content

Commit

Permalink
chore: add logs for extensions in test
Browse files Browse the repository at this point in the history
  • Loading branch information
guansss committed Nov 3, 2023
1 parent c35617e commit 7d2892e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const EXT = getEnv("EXT")

export const STRICT_CSP_PAGE = "/strict-csp.html"

declare const chrome: any // available in the page context

export const test = baseTest.extend<{
extensionId: string
devServer: (options: UseDevServerOptions) => Promise<UseDevServerContext>
Expand All @@ -43,6 +45,31 @@ export const test = baseTest.extend<{
],
})

persistentContext.on("page", (page) => {
page.on("console", (msg) => {
const urlPath = new URL(page.url(), "http://foo").pathname.slice(1)
const text = `<${urlPath}> ${msg.text()}`

if (msg.type() === "error" || msg.type() === "warning") {
console.error(text)
} else {
console.log(text)
}
})
})

const extPage = await persistentContext.newPage()
await extPage.goto("chrome://extensions")
const extensions = await extPage.evaluate(async () => {
return (await chrome.management.getAll()).map((ext: any) => ({
id: ext.id,
name: ext.name,
})) as { id: string; name: string }[]
})
extensions.forEach((ext) => {
console.log(`Installed extension: ${ext.name} (${ext.id})`)
})

await use(persistentContext)
await persistentContext.close()
},
Expand All @@ -52,6 +79,7 @@ export const test = baseTest.extend<{

const extensionId = background.url().split("/")[2]
expect(extensionId).toBeTruthy()
console.log(`Found extension with ID: ${extensionId}`)
await use(extensionId!)
},
devServer: async ({}, use) => {
Expand Down

0 comments on commit 7d2892e

Please sign in to comment.