Files
supabase/apps/studio/tests/README.md
Jordi Enric 55c3fdb49a E2E Testing Setup Consolidation (#35080)
* add new e2e folder

* add local supabase and confitional storage

* fix e2e selfhosted

* update actions

* add correct e2e folder

* fix e2e actions

* fix action project ids

* fix permissions

* fix script

* fix playwright install

* playwright root

* pnpm i

* fix api rul

* add env docs

* update run script

* only install deps for e2e

* use same dep

* only install deps for tests

* upd lockfile

* use official vercel integration

* use vercel cli

* remove old folder

* fix script

* rm filter

* rename e2e studio package

* fix install browsers

* add polling for vercel build

* use vercel-preview-url package

* undo actions

* rename ci env to ci

* chore:add rls check and make playwright test less flakey (#35348)

* update ci action

* fix paths

* fix browser install

* run ci against staging

* try caching builds

* fix envs

* fix env check

* fix sign in

* fix sign in url

* fix envs and url

* fix caching

* fix race condition in sign in page

* fix race condition in sign in page

* add check to see if being redirected

* fix caching, check IS_PLATFORM var

* log is_platform

* try vercel build

* fix vercel project id

* fix path

* add temp vercel.json file

* fix paths

* undo project id stuff

* rm cwd

* fix path

* fix paths again

* fix path

* fix base url

* try different fix

* fix config base url

* fix base studio url issues

* retain video on fails

* Update e2e/studio/README.md

Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>

* Update e2e/studio/README.md

Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>

* fix env file naming

* undo caching

* rm old tests folder

* fix readme scripts

* rm vercel deploy for now, just run build locally

* fix url

* fix build script

* fix is_platform

* fix stuck studio start

* fix env vars

* retain network and logs on fail for better debugging

* add apiurl env

* back to vercel

* disable catpcha

* fix test

* update environment configuration to remove default URLs for CI and streamline API base URL handling

* fix typeerr

* fix urls in home.spec

* fix urls in logs.spec

* fix urls in sqleditor spec

* fix table editor spec

* add tourl util

* use staging api in ci

* re add base url env var

* fix url in projects page

* fix url in sql editor spec

* fix sign in not waiting for cookies omfg

* fix env var name

* fix sql-editor test

* simplify table removal

* add opt out telemetry step

* fix logs tests

* fix table editor spec

* remove flaky steps from table editor tests

* use vercel deployment events instead of build

* add studio check

* fix condition

* debug event

* rm if

* trigger deploy

* undo ac

* make opt out button step optional, some envs dont hav eit

* use testid for sql run button

* use id instaed of timestamp in logs tests

* empty

* rm retries

* up glbal timeout

* chore: fix failing sql-editor playwright test (#35767)

* chore: fix failing sql-editor playwright test

* chore: minor fixes

* Chore/update playwright config (#35826)

chore: update playwright config

* rm supabase project from e2e tests

* refactor and simplify environments

* fix sql editor test

* fix ci env vars

* fix

* fix on windows

* update readme

* add playwright install script to readme

* rm turbopack trace flag

* npm to pnpm for scripts

* delete ivan lines

---------

Co-authored-by: Michael Ong <minghao_3728@hotmail.com>
Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>
2025-06-03 17:37:39 +02:00

2.2 KiB

UI Testing Notes

Rules

  • All tests should be run consistently (avoid situations whereby tests fails "sometimes")

  • Group tests in folders based on the feature they are testing. Avoid file/folder based folder names since those can change and we will forget to update the tests.

Examples: /logs /reports /projects /database-settings /auth

Custom Render and Custom Render Hook

customRender and customRenderHook are wrappers around render and renderHook that add some necessary providers like QueryClientProvider, TooltipProvider and NuqsTestingAdapter.

Generally use those instead of the default render and renderHook functions.

import { customRender, customRenderHook } from 'tests/lib/custom-render'

customRender(<MyComponent />)
customRenderHook(() => useMyHook())

Mocking API Requests

To mock API requests, we use the msw library.

Global mocks can be found in tests/lib/msw-global-api-mocks.ts.

To mock an endpoint you can use the addAPIMock function. Make sure to add the mock in the beforeEach hook. It won't work with beforeAll if you have many tests.

beforeEach(() => {
  addAPIMock({
    method: 'get',
    path: '/api/my-endpoint',
    response: {
      data: { foo: 'bar' },
    },
  })
})

API Mocking Tips:

  • Keep mocks in the same folder as the tests that use them
  • Add a test to verify the mock is working

This will make debugging and updating the mocks easier.

test('mock is working', async () => {
  const response = await fetch('/api/my-endpoint')
  expect(response.json()).resolves.toEqual({ data: { foo: 'bar' } })
})

Mocking Nuqs URL Parameters

To render a component that uses Nuqs with some predefined query parameters, you can use customRender with the nuqs prop.


customRender(<MyComponent />, {
  nuqs: {
    searchParams: {
      search: 'hello world',
    },
  },
})

<Popover> vs <Dropdown>

When simulating clicks on these components, do the following:

// for Popovers
import userEvent from '@testing-library/user-event'
await userEvent.click('Hello world')

// for Dropdowns
import clickDropdown from 'tests/helpers'
clickDropdown('Hello world')