Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
122 lines
3.7 KiB
TypeScript
122 lines
3.7 KiB
TypeScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import { Browser, BrowserContext, Page, test } from '@playwright/test'
|
|
import { Editor } from './Editor'
|
|
import { ErrorPage } from './ErrorPages'
|
|
import { HomePage } from './HomePage'
|
|
import { ShareMenu } from './ShareMenu'
|
|
import { Sidebar } from './Sidebar'
|
|
import { WorkspaceInviteDialog } from './WorkspaceInviteDialog'
|
|
|
|
export type UserName = 'huppy' | 'suppy'
|
|
type UserProps = { user: UserName; index: number } | undefined
|
|
|
|
export function sleep(ms: number): Promise<void> {
|
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
}
|
|
|
|
export async function openNewTab(
|
|
browser: Browser,
|
|
opts: { url?: string; userProps: UserProps; allowClipboard?: boolean }
|
|
) {
|
|
return await test.step('open new incognito page', async () => {
|
|
const { url, userProps, allowClipboard } = opts
|
|
let newContext: BrowserContext
|
|
if (userProps === undefined) {
|
|
newContext = await browser.newContext({ storageState: undefined })
|
|
} else {
|
|
const storageStateFileName = getStorageStateFileName(userProps.index, userProps.user)
|
|
const storageState = JSON.parse(fs.readFileSync(storageStateFileName, 'utf-8'))
|
|
newContext = await browser.newContext({ storageState })
|
|
}
|
|
|
|
if (allowClipboard) {
|
|
await newContext.grantPermissions(['clipboard-read', 'clipboard-write'])
|
|
}
|
|
const newPage = await newContext.newPage()
|
|
const {
|
|
newSidebar,
|
|
newEditor,
|
|
newHomePage,
|
|
newShareMenu,
|
|
newWorkspaceInviteDialog,
|
|
errorPage,
|
|
} = createFixtures(newPage)
|
|
if (url) {
|
|
await newPage.goto(url)
|
|
} else {
|
|
await newHomePage.goto()
|
|
}
|
|
await newHomePage.isLoaded()
|
|
return {
|
|
newPage,
|
|
newContext,
|
|
newSidebar,
|
|
newHomePage,
|
|
newEditor,
|
|
newShareMenu,
|
|
newWorkspaceInviteDialog,
|
|
errorPage,
|
|
}
|
|
})
|
|
}
|
|
|
|
export function getStorageStateFileName(index: number, user: UserName) {
|
|
return path.join(__dirname, `../.auth/${user}${index + 1}.json`)
|
|
}
|
|
|
|
export function areUrlsEqual(
|
|
url1: string,
|
|
url2: string,
|
|
opts: { ignoreSearch?: boolean } = { ignoreSearch: true }
|
|
) {
|
|
if (opts.ignoreSearch) {
|
|
const url1Obj = new URL(url1)
|
|
const url2Obj = new URL(url2)
|
|
return url1Obj.origin === url2Obj.origin && url1Obj.pathname === url2Obj.pathname
|
|
}
|
|
return url1 === url2
|
|
}
|
|
|
|
export function createFixtures(page: Page) {
|
|
const newSidebar = new Sidebar(page)
|
|
const newEditor = new Editor(page, newSidebar)
|
|
const newHomePage = new HomePage(page, newEditor)
|
|
const newShareMenu = new ShareMenu(page)
|
|
const newWorkspaceInviteDialog = new WorkspaceInviteDialog(page)
|
|
const errorPage = new ErrorPage(page)
|
|
return { newSidebar, newEditor, newHomePage, newShareMenu, newWorkspaceInviteDialog, errorPage }
|
|
}
|
|
|
|
export function getRandomName() {
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
|
let result = ''
|
|
for (let i = 0; i < 10; i++) {
|
|
const randomIndex = Math.floor(Math.random() * characters.length)
|
|
result += characters[randomIndex]
|
|
}
|
|
return result
|
|
}
|
|
|
|
const PROPAGATE_CHANGES_TIMEOUT = 100
|
|
/**
|
|
* Ensures that the provided expectations are met both before and after a page reload.
|
|
*
|
|
* @param fn - An asynchronous function containing the expectations to be tested.
|
|
* @param page - The Playwright Page object representing the browser page.
|
|
*
|
|
* The function performs the following steps:
|
|
* 1. Executes the provided expectations and ensures they pass.
|
|
* 2. Waits for a specified timeout to allow optimistic changes to propagate to the server.
|
|
* 3. Reloads the page.
|
|
* 4. Executes the provided expectations again and ensures they pass.
|
|
*/
|
|
export async function expectBeforeAndAfterReload(fn: () => Promise<void>, page: Page) {
|
|
await fn()
|
|
await sleep(PROPAGATE_CHANGES_TIMEOUT)
|
|
await page.reload()
|
|
const { newHomePage } = createFixtures(page)
|
|
await newHomePage.isLoaded()
|
|
await fn()
|
|
}
|