Files
supabase/apps/studio/components/layouts/AppLayout/StatusBanner.test.tsx
Alaister YoungandAlaister Young fcbdda8107 chore: migrate formatter from Prettier to oxfmt (#53835)
Migrate code formatting across the monorepo from Prettier to `oxfmt`
(`0.79.0`, pinned) for much faster formatting checks locally and in CI
while keeping code churn minimal (78 files total, 0.7% of the repo).

Studio's `@ianvs/prettier-plugin-sort-imports` ordering
(`<BUILTIN_MODULES>`, `<THIRD_PARTY_MODULES>`, blank line, then `@/` and
relative imports) is preserved via `oxfmt`'s native `sortImports`
override for `apps/studio/**/*.{js,jsx,ts,tsx}`.

### Performance (before vs after, uncached)

| Benchmark | Prettier (`3.8.x`) | oxfmt (`0.79.0`) | Speedup |
| --- | ---: | ---: | ---: |
| CI formatting step (`blacksmith-4vcpu-ubuntu-2404`, full repo) | `73s`
| **`7s`** | **~10×** |
| Local `apps/studio` JS/TS (`5,157` files) | `17.74s` | **`0.36s`** |
**~49×** |
| Local full monorepo (`11,131` files) | — | **`2.39s`** | — |

**Added:**

- `.oxfmtrc.jsonc` at repo root with Prettier-matching options,
`sortPackageJson: false`, the Studio `sortImports` override, and ignore
patterns migrated from `.prettierignore`
- `oxfmt` (`0.79.0` exact pin) in `pnpm-workspace.yaml` catalog and
workspace `devDependencies` / `dependencies`
- Shared `.agents/scripts/format_and_lint.sh` hook script and
`.agents/hooks.json` (used by both Claude Code and Antigravity)

**Changed:**

- Replaced `test:prettier` with `format:check` and switched `format` in
root `package.json` to `oxfmt`
- Updated `packages/api-types` (`codegen`,
`verify-production-types.mjs`), `apps/design-system` (`build:registry`),
`apps/docs` (`CodeSample.ts`, `generate-sitemap.ts`, `next.config.mjs`,
`spec/Makefile`), `apps/www` (`generate-sitemap.mjs`), and
`packages/build-icons` (`generateIconFiles.mjs`) from Prettier to
`oxfmt`
- Updated `.github/workflows/prettier.yml` (keeping the `format` job ID
intact), `.github/workflows/autofix_linters.yml`,
`.claude/settings.json`, `AGENTS.md`, `CONTRIBUTING.md`, and
`.github/copilot-instructions.md`
- Applied one-time `oxfmt` formatting pass in a separate commit (78
files: 30 `i18n/README.*.md` trailing spaces, 19 Studio files, 17 other
TS/TSX/generated types, 8 MD/MDX, 3 `package.json`, 2 example CSS files)

**Removed:**

- `prettier`, `@ianvs/prettier-plugin-sort-imports`, and
`prettier-plugin-sql-cst` from `devDependencies` (note: `.sql` files
were not part of the CI formatting glob; `eslint-config-prettier` is
kept for ESLint)
- `prettier.config.mjs`, `.prettierignore`, and
`.claude/scripts/format_and_lint.sh`

## To test

- Run `pnpm run format:check` and confirm it passes cleanly across all
matched files
- Run `pnpm --filter api-types test`, `pnpm --filter docs exec vitest
run features/directives/CodeSample.test.ts`, and `pnpm --filter www exec
vitest run generate-sitemap.test.ts`
- Edit an `apps/studio` file with out-of-order imports and run `pnpm run
format` to confirm builtin/third-party vs `@/`/relative grouping matches
prior behavior
- Check that the `Check Code Formatting` CI workflow passes on this PR

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-24 12:51:31 +08:00

205 lines
6.5 KiB
TypeScript

import { QueryClient } from '@tanstack/react-query'
import { fireEvent, screen, waitFor } from '@testing-library/react'
import { platformComponents as components } from 'api-types'
import { http, HttpResponse } from 'msw'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import { StatusBanner } from './StatusBanner'
import { platformKeys } from '@/data/platform/keys'
import { BASE_PATH } from '@/lib/constants'
import type { StatusPageResponse } from '@/lib/status-page/status-page.schema'
import { createMockOrganizationResponse } from '@/tests/helpers'
import { customRender } from '@/tests/lib/custom-render'
import { addAPIMock, mswServer } from '@/tests/lib/msw'
import { createMockProfileContext } from '@/tests/lib/profile-helpers'
type OrganizationResponse = components['schemas']['OrganizationResponse_Output']
type OrganizationProjectsResponse = components['schemas']['OrganizationProjectsResponse_Output']
type OrgProject = OrganizationProjectsResponse['projects'][number]
type OrgDatabase = OrgProject['databases'][number]
function mockProject(
ref: string,
databases: Array<{ region: string; type: 'PRIMARY' | 'READ_REPLICA' }>
): OrgProject {
return {
cloud_provider: 'AWS',
databases: databases.map(({ region, type }): OrgDatabase => ({
cloud_provider: 'AWS',
identifier: ref,
region,
status: 'ACTIVE_HEALTHY',
type,
})),
inserted_at: new Date().toISOString(),
integration_source: null,
is_branch: false,
name: ref,
ref,
region: databases[0]?.region ?? 'us-east-1',
status: 'ACTIVE_HEALTHY',
}
}
function buildStatusPage(overrides: Partial<StatusPageResponse> = {}): StatusPageResponse {
return {
page_title: 'Supabase status',
page_url: 'https://status.supabase.com/',
ongoing_incidents: [],
in_progress_maintenances: [],
scheduled_maintenances: [],
...overrides,
}
}
function buildIncident(
overrides: Partial<StatusPageResponse['ongoing_incidents'][number]> = {}
): StatusPageResponse['ongoing_incidents'][number] {
return {
id: 'inc-1',
name: 'Elevated errors',
url: 'https://status.supabase.com/incidents/inc-1',
last_update_at: '2026-01-01T00:00:00Z',
last_update_message: null,
affected_components: [],
status: 'investigating',
current_worst_impact: 'full_outage',
visible: true,
show_banner: true,
...overrides,
}
}
const INCIDENT_TITLE = 'We are investigating a technical issue'
const mockOrgProjectEndpoints = () => {
addAPIMock({
method: 'get',
path: '/platform/organizations',
response: () =>
HttpResponse.json<OrganizationResponse[]>([
createMockOrganizationResponse({ slug: 'org-a' }),
]),
})
addAPIMock({
method: 'get',
path: '/platform/organizations/:slug/projects',
response: () =>
HttpResponse.json<OrganizationProjectsResponse>({
pagination: { count: 1, limit: 100, offset: 0 },
projects: [mockProject('project-a', [{ region: 'us-east-1', type: 'PRIMARY' }])],
}),
})
}
const { mockUseFlag } = vi.hoisted(() => ({
mockUseFlag: vi.fn().mockReturnValue(false),
}))
vi.mock(import('common'), async (importOriginal) => {
const actual = await importOriginal()
return { ...actual, useFlag: mockUseFlag }
})
vi.mock(import('@/lib/constants'), async (importOriginal) => {
const actual = await importOriginal()
return { ...actual, IS_PLATFORM: true }
})
describe('StatusBanner', () => {
beforeEach(() => {
window.localStorage.clear()
})
test('renders nothing while orgs are loading', async () => {
mswServer.use(
http.get(`${BASE_PATH}/api/status-page`, () =>
HttpResponse.json<StatusPageResponse>(
buildStatusPage({ ongoing_incidents: [buildIncident()] })
)
)
)
const { promise: orgsRequested, resolve: releaseOrgsResponse } = Promise.withResolvers<void>()
addAPIMock({
method: 'get',
path: '/platform/organizations',
response: async () => {
await orgsRequested
return HttpResponse.json<OrganizationResponse[]>([
createMockOrganizationResponse({ slug: 'org-a' }),
])
},
})
addAPIMock({
method: 'get',
path: '/platform/organizations/:slug/projects',
response: () =>
HttpResponse.json<OrganizationProjectsResponse>({
pagination: { count: 1, limit: 100, offset: 0 },
projects: [mockProject('project-a', [{ region: 'us-east-1', type: 'PRIMARY' }])],
}),
})
customRender(<StatusBanner />, { profileContext: createMockProfileContext() })
expect(screen.queryByText(INCIDENT_TITLE)).not.toBeInTheDocument()
releaseOrgsResponse()
await waitFor(() => {
expect(screen.getByText(INCIDENT_TITLE)).toBeInTheDocument()
})
})
test('dismissing persists the incident key, and a new incident brings the banner back', async () => {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
mswServer.use(
http.get(`${BASE_PATH}/api/status-page`, () =>
HttpResponse.json<StatusPageResponse>(
buildStatusPage({ ongoing_incidents: [buildIncident({ id: 'inc-1' })] })
)
)
)
mockOrgProjectEndpoints()
customRender(<StatusBanner />, { profileContext: createMockProfileContext(), queryClient })
await screen.findByText(INCIDENT_TITLE)
fireEvent.click(screen.getByRole('button', { name: 'Dismiss banner' }))
await waitFor(() => {
expect(screen.queryByText(INCIDENT_TITLE)).not.toBeInTheDocument()
})
expect(JSON.parse(window.localStorage.getItem('status-banner-dismissed-keys') ?? '[]')).toEqual(
['incident:inc-1']
)
mswServer.use(
http.get(`${BASE_PATH}/api/status-page`, () =>
HttpResponse.json<StatusPageResponse>(
buildStatusPage({
ongoing_incidents: [buildIncident({ id: 'inc-2', name: 'A different incident' })],
})
)
)
)
await queryClient.invalidateQueries({ queryKey: platformKeys.statusPage() })
await waitFor(() => {
expect(screen.getByText(INCIDENT_TITLE)).toBeInTheDocument()
})
})
test('the emergency override renders without fetching anything', async () => {
mockUseFlag.mockImplementation((name: string) => name === 'ongoingIncident')
customRender(<StatusBanner />, { profileContext: createMockProfileContext() })
expect(await screen.findByText(INCIDENT_TITLE)).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Dismiss banner' })).not.toBeInTheDocument()
})
})