mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
## Problem e2e tests are still flaky and not as fast as they could be ## Solution - [x] Reset supabase instance: this makes the database visualiser tests faster as there are less tables to screenshot - [x] Improve the single file setup utilities so that they never block local tests by cleaning them up before starting - [x] Disable animations while running the tests (less time waiting for animations to complete - [x] Add utility functions that help reproducing flaky tests locally
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import path from 'path'
|
|
import { test as base } from '@playwright/test'
|
|
import dotenv from 'dotenv'
|
|
|
|
import { env } from '../env.config.js'
|
|
|
|
dotenv.config({
|
|
path: path.resolve(import.meta.dirname, '../.env.local'),
|
|
override: true,
|
|
})
|
|
|
|
export interface TestOptions {
|
|
env: string
|
|
ref: string
|
|
apiUrl: string
|
|
}
|
|
|
|
export const test = base.extend<TestOptions>({
|
|
env: env.STUDIO_URL,
|
|
ref: env.PROJECT_REF ?? 'default',
|
|
apiUrl: env.API_URL,
|
|
page: async ({ page }, use) => {
|
|
const ref = env.PROJECT_REF ?? 'default'
|
|
await page.addInitScript((ref) => {
|
|
localStorage.setItem(`table-editor-new-filter-banner-dismissed-${ref}`, JSON.stringify(true))
|
|
}, ref)
|
|
await use(page)
|
|
},
|
|
})
|
|
|
|
/**
|
|
* A function that returns a disposable object. Calling it with using keyword ensures that the cleanup function
|
|
* will be called whether the test succeeded or not.
|
|
*
|
|
* @example
|
|
* await using _ = await withSetupCleanup(
|
|
* () => createTableWithRLS('pw_table', 'pw_column'),
|
|
* async () => {
|
|
* await dropTable('pw_table')
|
|
* }
|
|
* )
|
|
* @param setup The setup function (create tables, etc.)
|
|
* @param cleanup The cleanup function (remove tables, etc.)
|
|
* @returns A disposable object
|
|
*/
|
|
export const withSetupCleanup = async (
|
|
setup: () => Promise<void>,
|
|
cleanup: () => Promise<void>
|
|
) => {
|
|
await setup()
|
|
return {
|
|
async [Symbol.asyncDispose]() {
|
|
await cleanup()
|
|
},
|
|
}
|
|
}
|