* Setup playwright for e2e tests Fixes #12 * Chromium * First working test, clean up * Merge actions * New headless mode * Clean up, bugfix * Bug fixes, cleaner sendMessage code * Rebase * Rebase * Load tokens and open public page * Test CI * Working test * Lint * Try to address flakyness * Clean up test * Comment * No export * More clean up * More clean up * Adds authorized pop up test * Adds comment * Add snapshots * New linux screenshots
64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
// From https://playwright.dev/docs/chrome-extensions#testing
|
|
import {
|
|
test as base,
|
|
chromium,
|
|
Worker,
|
|
type BrowserContext,
|
|
} from '@playwright/test'
|
|
import path from 'path'
|
|
import * as dotenv from 'dotenv'
|
|
dotenv.config()
|
|
|
|
export const test = base.extend<{
|
|
context: BrowserContext
|
|
extensionId: string
|
|
background: Worker
|
|
authorizedBackground: Worker
|
|
}>({
|
|
context: async ({}, use) => {
|
|
const pathToExtension = path.join(__dirname, '..', 'build')
|
|
const context = await chromium.launchPersistentContext('', {
|
|
headless: false,
|
|
args: [
|
|
`--headless=new`, // headless mode that allows for extensions
|
|
`--disable-extensions-except=${pathToExtension}`,
|
|
`--load-extension=${pathToExtension}`,
|
|
],
|
|
})
|
|
await use(context)
|
|
await context.close()
|
|
},
|
|
background: async ({ context }, use) => {
|
|
let [background] = context.serviceWorkers()
|
|
if (!background)
|
|
background = await context.waitForEvent('serviceworker')
|
|
|
|
// Wait for the chrome object to be available
|
|
await new Promise(resolve => setTimeout(resolve, 100))
|
|
await use(background)
|
|
},
|
|
authorizedBackground: async ({ background }, use) => {
|
|
// Load the env tokens in storage for auth
|
|
const githubToken = process.env.GITHUB_TOKEN
|
|
const kittycadToken = process.env.KITTYCAD_TOKEN
|
|
await background.evaluate(
|
|
async ([githubToken, kittycadToken]) => {
|
|
await chrome.storage.local.set({
|
|
ktk: kittycadToken, // from src/chrome/storage.ts
|
|
gtk: githubToken, // from src/chrome/storage.ts
|
|
})
|
|
},
|
|
[githubToken, kittycadToken]
|
|
)
|
|
|
|
// Wait for background auth
|
|
await new Promise(resolve => setTimeout(resolve, 2000))
|
|
await use(background)
|
|
},
|
|
extensionId: async ({ background }, use) => {
|
|
const extensionId = background.url().split('/')[2]
|
|
await use(extensionId)
|
|
},
|
|
})
|
|
export const expect = test.expect
|