Files
supabase/e2e/studio/scripts/common/helpers.ts
Ali Waseem 22cfd2be14 feat: Run E2E tests aganist Platform Pt.1 (#41032)
* added packages for creating projects

* updated scripts

* remove ami version

* cleaned up common

* updated tests

* refactored helpers

* updated env

* updated config

* updated to reference env

* updated global setup

* updated type logic and scripts

* added mocking of hcaptcha

* added log statements

* updated local env

* update env file

* updated env vars

* updated logging

* updated to remove check

* updated print and project names

* updated helpers

* updated url

* updated setup

* updated storage helpers to account for listing files

* updated setup and tests

* updated timeout only for setup

* updated helper to account for different api response

* added ignores for tests

* updated lock file

* updated database spec to add exact

* updated timeouts

* removed check for table grid footer

* updated test runner

* updated is_platform

* updated playwright config

* updated worker settings

* removed dotenvx

* updated README

* updated to remove comment

* Update e2e/studio/scripts/common/retriedFetch.ts

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
2025-12-05 10:50:16 -07:00

47 lines
1.3 KiB
TypeScript

import assert from 'assert'
import { setTimeout } from 'timers/promises'
import { PlatformClient } from './platform.js'
const statusWaiterMilliSeconds = parseInt(process.env.STATUS_WAITER_MILLI_SECONDS ?? '3000')
const statusWaiterRetries = parseInt(
process.env.STATUS_WAITER_RETRIES ?? `${900_000 / statusWaiterMilliSeconds}`
)
export const sleep = (ms: number) => setTimeout(ms)
export type WaitForProjectStatusParams = {
platformClient: PlatformClient
ref: string
expectedStatus: string
retries?: number
}
export async function waitForProjectStatus({
platformClient,
ref,
expectedStatus,
retries = statusWaiterRetries,
}: WaitForProjectStatusParams) {
for (let i = 0; i < retries; i++) {
try {
const statusResp = await platformClient.send(`/v1/projects/${ref}`, {}, undefined, 0)
if (statusResp.status != 200) {
console.log(
`Failed to get project status ${statusResp.statusText} ${
statusResp.status
} ${await statusResp.text()}`
)
}
assert(statusResp.status == 200)
const { status } = await statusResp.json()
assert(status == expectedStatus)
return
} catch {
await sleep(statusWaiterMilliSeconds)
}
}
throw new Error(
`did not reach expected status ${expectedStatus} after retries ${retries} x ${statusWaiterMilliSeconds}ms`
)
}