Files
supabase/apps/studio/tests
Alaister YoungandAlaister Young a8b2f23091 fix(studio): restore deployment update metadata (#51048)
Deployment update checks now receive a timestamp from GitHub’s
documented commit API instead of silently falling back to `unknown` when
its website response changes. Valid deployment metadata is cached for
ten minutes; development and failed lookups are uncached so they can
recover.

**Changed:**

- Validate and normalize the committer date in the shared Next/TanStack
handler, preserving the existing response shape and `unknown` fallback.
- Exclude only the exact deployment-metadata endpoint from TanStack’s
private API cache default; authenticated APIs and server functions
retain it.
- Keep the client update query unpinned and its existing toast threshold
unchanged.

**Added:**

- Shared-handler tests through both Next and the TanStack adapter for
dates, malformed payloads, upstream failures, and recovery.
- Tests using the installed Vercel route compiler for root and
`/dashboard` cache rules, security headers, and empty Next
configuration.

## To test

- On the TanStack preview, request
`/dashboard/api/get-deployment-commit`; compare its SHA and UTC
timestamp with the deployed commit’s GitHub committer date.
- Repeat the request to check CDN caching. Vercel consumes `s-maxage`,
so use cache-hit/age evidence as well as client-visible headers.
- Confirm another API route and a server-function path retain `private,
no-store`.
- Open an existing project, reload it while clean, and inspect the
untouched support form for metadata-related errors.

Validation: 60 focused tests, Studio typecheck, scoped ESLint,
formatting, knip, and both framework production builds passed. Live
unauthenticated GitHub lookup with the configured API version returned
the expected committer date. Full source lint ratchet also passed,
excluding only generated build directories. Local TanStack browser
checks passed for clean project/reload, general settings, untouched
support form, and naturally emitted development metadata formatting; no
errors or unexpected update toast appeared. The positive two-deployment
toast and submitted support-version formatting were not exercised.
Deployed native Next previews returned the exact commit SHA and expected
UTC timestamp; repeated metadata requests produced CDN HIT responses
(ages 26 and 100 seconds). Build logs establish that the staging preview
also ran Next, so it does not validate TanStack edge header behavior. A
separate preview-only redeployment with a deployment-scoped TanStack
override was confirmed to run Vite. It returned the same correct
SHA/timestamp, a repeat CDN cache HIT, and private, no-store on the
neighboring UTC API. No project settings or production aliases were
changed. Installed Vercel compiler tests cover the remaining
root/base-path and server-function rules. No new environment variable,
token, or dependency is required.

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-10-07 19:31:02 +02:00
..
2026-09-11 12:17:49 +08:00

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')