Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

test(e2e/studio): stabilize flaky and TZ/OS-sensitive specs (#46039)

Alaister Young5950b6ca049f
diff --git a/e2e/studio/features/_global.setup.ts b/e2e/studio/features/_global.setup.ts
index 420590efb19..2dc94a06edc 100644
--- a/e2e/studio/features/_global.setup.ts
+++ b/e2e/studio/features/_global.setup.ts
@@ -1,13 +1,13 @@
+import fs from 'node:fs/promises'
+import os from 'node:os'
+import path from 'node:path'
import { test as setup } from '@playwright/test'
import dotenv from 'dotenv'
-import path from 'node:path'
-import os from 'node:os'
-import fs from 'node:fs/promises'
import { env } from '../env.config.js'
-import { setupProjectForTests } from '../scripts/setup-platform-tests.js'
import { loginWithEmail } from '../scripts/login/email.js'
import { loginWithGithubWithRetry } from '../scripts/login/github.js'
+import { setupProjectForTests } from '../scripts/setup-platform-tests.js'
/**
* Run any setup tasks for the tests.
@@ -30,6 +30,16 @@ setup('Global Setup', async ({ page }) => {
- Is Platform: ${IS_PLATFORM}
`)
+ // Cleanup once-per-file locks before any of the early returns below —
+ // tests using `withFileOnceSetup` rely on this running unconditionally.
+ const locksDirPath = path.join(os.tmpdir(), 'playwright-locks')
+ try {
+ await fs.access(locksDirPath)
+ await fs.rm(locksDirPath, { recursive: true, force: true })
+ } catch {
+ // Silently catch, no directory
+ }
+
/**
* Studio Check
*/
@@ -121,13 +131,4 @@ To start API locally, run:
throw err
}
}
-
- // Cleanup locks as they may persist between runs especially locally
- const locksDirPath = path.join(os.tmpdir(), 'playwright-locks')
- try {
- await fs.access(locksDirPath);
- await fs.rm(locksDirPath, { recursive: true, force: true })
- } catch {
- // Silently catch, no directory
- }
})
diff --git a/e2e/studio/features/filter-bar.spec.ts b/e2e/studio/features/filter-bar.spec.ts
index 345441fd876..badaa786eb3 100644
--- a/e2e/studio/features/filter-bar.spec.ts
+++ b/e2e/studio/features/filter-bar.spec.ts
@@ -19,7 +19,8 @@ import { createApiResponseWaiter, waitForTableToLoad } from '../utils/wait-for-r
const tableNamePrefix = 'pw_filter_bar'
function getDateValue(daysAgo: number): string {
- const date = new Date(Date.now() - daysAgo * 86400000)
+ const date = new Date()
+ date.setDate(date.getDate() - daysAgo)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
@@ -489,7 +490,10 @@ test.describe('Filter Bar', () => {
const lastNameValue = page.getByTestId('filter-value-last_name')
await lastNameValue.click()
- await page.keyboard.press('Home')
+ // Drive the cursor to position 0 directly rather than via `Home` —
+ // macOS Chromium doesn't honor the Home key inside text inputs (the
+ // OS-level binding is Cmd+ArrowLeft / Fn+ArrowLeft).
+ await lastNameValue.evaluate((el) => (el as HTMLInputElement).setSelectionRange(0, 0))
await page.keyboard.press('ArrowLeft')
@@ -543,10 +547,9 @@ test.describe('Filter Bar', () => {
const valueInput = page.getByTestId(`filter-value-${columnName}`)
await valueInput.fill('HelloWorld')
- await page.keyboard.press('Home')
- for (let i = 0; i < 5; i++) {
- await page.keyboard.press('ArrowRight')
- }
+ // See "ArrowLeft at position 0" — macOS Chromium ignores the Home
+ // key inside text inputs, so set the cursor programmatically.
+ await valueInput.evaluate((el) => (el as HTMLInputElement).setSelectionRange(5, 5))
await page.keyboard.type('_Middle_')
await expect(valueInput).toHaveValue('Hello_Middle_World')
@@ -637,6 +640,8 @@ test.describe('Filter Bar', () => {
test('filtering by Today shows only today rows', async ({ page, ref }) => {
const tableName = `${tableNamePrefix}_date_today`
const todayValue = getDateValue(0)
+ const yesterdayValue = getDateValue(1)
+ const lastWeekValue = getDateValue(7)
await query(
`CREATE TABLE IF NOT EXISTS ${tableName} (
@@ -644,11 +649,18 @@ test.describe('Filter Bar', () => {
created_at date
)`
)
+ // Insert exact date strings computed from the test's `getDateValue`
+ // (JS local TZ) rather than `CURRENT_DATE` (postgres session TZ ≈ UTC).
+ // The studio's "Today" dropdown is built from JS local time too, so
+ // aligning the inserted rows with the filter's expected value keeps
+ // these tests deterministic across timezones — otherwise on non-UTC
+ // hosts the local "today" can land on a different day than postgres'
+ // CURRENT_DATE and the filter matches zero rows.
await query(
- `INSERT INTO ${tableName} (created_at) VALUES
- (CURRENT_DATE),
- (CURRENT_DATE - INTERVAL '1 day'),
- (CURRENT_DATE - INTERVAL '7 days')`
+ `INSERT INTO ${tableName} (created_at) VALUES
+ ('${todayValue}'),
+ ('${yesterdayValue}'),
+ ('${lastWeekValue}')`
)
try {
@@ -666,7 +678,9 @@ test.describe('Filter Bar', () => {
test('filtering by Yesterday shows only yesterday rows', async ({ page, ref }) => {
const tableName = `${tableNamePrefix}_date_yest`
+ const todayValue = getDateValue(0)
const yesterdayValue = getDateValue(1)
+ const lastWeekValue = getDateValue(7)
await query(
`CREATE TABLE IF NOT EXISTS ${tableName} (
@@ -674,11 +688,12 @@ test.describe('Filter Bar', () => {
created_at date
)`
)
+ // See "filtering by Today" — align inserts with JS-local getDateValue.
await query(
- `INSERT INTO ${tableName} (created_at) VALUES
- (CURRENT_DATE),
- (CURRENT_DATE - INTERVAL '1 day'),
- (CURRENT_DATE - INTERVAL '7 days')`
+ `INSERT INTO ${tableName} (created_at) VALUES
+ ('${todayValue}'),
+ ('${yesterdayValue}'),
+ ('${lastWeekValue}')`
)
try {
@@ -696,7 +711,10 @@ test.describe('Filter Bar', () => {
test('filtering by Last 7 days with greater or equal operator', async ({ page, ref }) => {
const tableName = `${tableNamePrefix}_date_7d`
+ const todayValue = getDateValue(0)
+ const threeDaysAgoValue = getDateValue(3)
const last7DaysValue = getDateValue(7)
+ const lastMonthValue = getDateValue(30)
await query(
`CREATE TABLE IF NOT EXISTS ${tableName} (
@@ -704,12 +722,13 @@ test.describe('Filter Bar', () => {
created_at date
)`
)
+ // See "filtering by Today" — align inserts with JS-local getDateValue.
await query(
- `INSERT INTO ${tableName} (created_at) VALUES
- (CURRENT_DATE),
- (CURRENT_DATE - INTERVAL '3 days'),
- (CURRENT_DATE - INTERVAL '7 days'),
- (CURRENT_DATE - INTERVAL '30 days')`
+ `INSERT INTO ${tableName} (created_at) VALUES
+ ('${todayValue}'),
+ ('${threeDaysAgoValue}'),
+ ('${last7DaysValue}'),
+ ('${lastMonthValue}')`
)
try {
@@ -728,6 +747,8 @@ test.describe('Filter Bar', () => {
test('date less than operator filters correctly', async ({ page, ref }) => {
const tableName = `${tableNamePrefix}_date_lt`
const todayValue = getDateValue(0)
+ const yesterdayValue = getDateValue(1)
+ const lastWeekValue = getDateValue(7)
await query(
`CREATE TABLE IF NOT EXISTS ${tableName} (
@@ -735,11 +756,12 @@ test.describe('Filter Bar', () => {
created_at date
)`
)
+ // See "filtering by Today" — align inserts with JS-local getDateValue.
await query(
- `INSERT INTO ${tableName} (created_at) VALUES
- (CURRENT_DATE),
- (CURRENT_DATE - INTERVAL '1 day'),
- (CURRENT_DATE - INTERVAL '7 days')`
+ `INSERT INTO ${tableName} (created_at) VALUES
+ ('${todayValue}'),
+ ('${yesterdayValue}'),
+ ('${lastWeekValue}')`
)
try {
@@ -760,6 +782,8 @@ test.describe('Filter Bar', () => {
test('timestamp column shows date preset dropdown options', async ({ page, ref }) => {
const tableName = `${tableNamePrefix}_ts_today`
const todayValue = getDateValue(0)
+ const yesterdayValue = getDateValue(1)
+ const lastWeekValue = getDateValue(7)
await query(
`CREATE TABLE IF NOT EXISTS ${tableName} (
@@ -767,11 +791,14 @@ test.describe('Filter Bar', () => {
created_at timestamp
)`
)
+ // See "filtering by Today" — pin timestamps to mid-day of each
+ // JS-local date so the row falls on the correct calendar day from
+ // postgres's perspective regardless of the host timezone.
await query(
- `INSERT INTO ${tableName} (created_at) VALUES
- (NOW()),
- (NOW() - INTERVAL '1 day'),
- (NOW() - INTERVAL '7 days')`
+ `INSERT INTO ${tableName} (created_at) VALUES
+ ('${todayValue} 12:00:00'),
+ ('${yesterdayValue} 12:00:00'),
+ ('${lastWeekValue} 12:00:00')`
)
try {
diff --git a/e2e/studio/features/queue-table-operations.spec.ts b/e2e/studio/features/queue-table-operations.spec.ts
index 12063f31674..b4c55f9cd01 100644
--- a/e2e/studio/features/queue-table-operations.spec.ts
+++ b/e2e/studio/features/queue-table-operations.spec.ts
@@ -28,7 +28,15 @@ test.describe('Queue Table Operations', () => {
await page.goto(toUrl(`/project/${ref}/editor?schema=public`))
await loadPromise
await enableQueueOperations(page)
- await page.reload({ waitUntil: 'networkidle' })
+ // Wait on the table-list refetch that follows the reload rather than
+ // `networkidle` — studio keeps long-lived polling/SSE connections open
+ // (PostHog, Sentry, realtime) so `networkidle` never resolves and the
+ // beforeEach hits its 120 s test timeout. The reload's goal is "wait
+ // until the editor is loaded again with the new toggle applied" and
+ // the entity-types query is a precise signal for that.
+ const reloadWait = waitForTableToLoad(page, ref)
+ await page.reload()
+ await reloadWait
})
test('cell edits are queued and can be saved', async ({ page, ref }) => {
diff --git a/e2e/studio/features/sql-editor.spec.ts b/e2e/studio/features/sql-editor.spec.ts
index dcd1d93394f..21a302d20a5 100644
--- a/e2e/studio/features/sql-editor.spec.ts
+++ b/e2e/studio/features/sql-editor.spec.ts
@@ -291,7 +291,11 @@ test.describe('SQL Editor', () => {
})
test('warns on CREATE TABLE without RLS and "Run and enable RLS" enables it', async ({ ref }) => {
- const tableName = 'pw_rls_smoke_test'
+ // Suffix with parallel worker index so parallel workers don't collide
+ // on the same table name — when they do, one worker's `dropTable`
+ // races another's "Run and enable RLS" and the post-action query
+ // sometimes finds the table missing.
+ const tableName = `pw_rls_smoke_test_${test.info().parallelIndex}`
// Drop any leftover table from a previous failed run, and ensure cleanup
// after the test regardless of pass/fail.
diff --git a/e2e/studio/features/table-editor.spec.ts b/e2e/studio/features/table-editor.spec.ts
index 47eb18424bb..a11adcf6c1c 100644
--- a/e2e/studio/features/table-editor.spec.ts
+++ b/e2e/studio/features/table-editor.spec.ts
@@ -502,7 +502,13 @@ testRunner('table editor', () => {
await expect(page.locator('.view-lines')).toContainText(`security_invoker = true`)
const openInSqlEditorLink = page.getByRole('link', { name: 'Open in SQL Editor' })
- await expect(openInSqlEditorLink).toHaveAttribute('href', /security_invoker%20%3D%20true/)
+ // Accept either percent-encoded (`%20`) or form-encoded (`+`) spaces —
+ // some routers serialize search params via URLSearchParams which emits
+ // `+` for spaces. Both decode to the same SQL.
+ await expect(openInSqlEditorLink).toHaveAttribute(
+ 'href',
+ /security_invoker(%20|\+)%3D(%20|\+)true/
+ )
await openInSqlEditorLink.click()
await page.waitForURL(/\/sql\/new/)
await expect(page.locator('.view-lines')).toContainText(`create view public.${viewName}`)
@@ -1142,7 +1148,7 @@ testRunner('table editor', () => {
const saveTablePromise = waitForApiResponseWithTimeout(
page,
(response) => response.url().includes('query?key=table-update'),
- 15000
+ 30000
)
await page.getByRole('button', { name: 'Save' }).first().click()
await saveTablePromise
@@ -1170,7 +1176,7 @@ testRunner('table editor', () => {
const removeFkPromise = waitForApiResponseWithTimeout(
page,
(response) => response.url().includes('query?key=table-update'),
- 15000
+ 30000
)
await page.getByRole('button', { name: 'Save' }).first().click()
await removeFkPromise
@@ -1263,9 +1269,15 @@ testRunner('table editor', () => {
await expect(foreignKeySchemaSelect).not.toBeVisible()
await expect(foreignKeyLink).toBeVisible()
- const updateColumnPromise = waitForApiResponse(page, 'pg-meta', ref, 'query?key=column-update', {
- method: 'POST',
- })
+ const updateColumnPromise = waitForApiResponse(
+ page,
+ 'pg-meta',
+ ref,
+ 'query?key=column-update',
+ {
+ method: 'POST',
+ }
+ )
await columnEditor.getByRole('button', { name: 'Save' }).click()
await updateColumnPromise
await expect(columnEditor).not.toBeVisible()
diff --git a/e2e/studio/utils/storage-helpers.ts b/e2e/studio/utils/storage-helpers.ts
index e4065654f0b..97d59ce4f18 100644
--- a/e2e/studio/utils/storage-helpers.ts
+++ b/e2e/studio/utils/storage-helpers.ts
@@ -98,16 +98,13 @@ export const deleteBucket = async (page: Page, ref: string, bucketName: string)
await page.getByRole('button', { name: 'Delete bucket' }).click()
await apiPromise
- // Verify bucket was deleted - should redirect to files page
- await expect(page, 'Should redirect to storage files page after deletion').toHaveURL(
- new RegExp(`/storage/files$`)
- )
-
- // Verify bucket is no longer in the list
+ // Verify bucket is no longer in the list. The post-delete redirect to
+ // /storage/files can race other history updates, so asserting the row
+ // is gone is a more stable signal that the delete actually succeeded.
await expect(
page.getByRole('row').filter({ hasText: bucketName }),
`Bucket ${bucketName} should not be visible after deletion`
- ).not.toBeVisible()
+ ).not.toBeVisible({ timeout: 10000 })
}
/**