mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
Removes the remaining Next.js dependencies, compatibility shims, test
mocks, ESLint/TypeScript presets, and webpack/Next workarounds from
Studio following the TanStack Start migration.
Addresses FE-3107.
**Removed:**
- `next` and `next-router-mock` from `apps/studio/package.json` (and
updated `pnpm-lock.yaml`)
- Orphaned `apps/studio/compat/next/script.tsx` shim, `script.test.tsx`,
`compat/**` knip entry, and `nextCompat()` / `ssr.noExternal` `/^next/`
plumbing from `apps/studio/vite.config.ts`
- `apps/studio/tests/lib/route-mock.ts` and all `next-router-mock`
setup/imports across `tests/vitestSetup.ts`,
`tests/lib/custom-render.tsx`, and 12 test files
- `apps/studio/tests/pages/` directory (moved the 3 remaining tests to
`components/interfaces/Organization/Organization.utils.test.ts` and
`apps/studio/tests/routes/`)
- Unused `'use client'` directives across 23 Studio files
- Next.js/webpack workarounds: `graphiqlViteWorkers()` in
`vite.config.ts`, webpack `import.meta.glob` `try/catch` fallback in
`ConnectStepsSection.tsx`, shell `NODE_ENV=test` override in
`vite.config.ts` / root `package.json` / `studio-e2e-test.yml`, Next
`getPathMatch` and `_next` passthrough in `redirects.shared.*`,
`window.next?.router` check in `monaco-graphiql-coexistence.spec.ts`,
and unused `ANALYZE` env var in `apps/studio/turbo.jsonc`
- Next-only Sentry/chunk-load filters (`NEXT_NOT_FOUND`,
`NEXT_REDIRECT`, Next `/org/[slug]/` regex, `/app:\/\//`, dead
`includeThirdPartyErrorFilter` plumbing, webpack chunk error regex) and
stale Next/Pages Router comments, docs, and `#__next` CSS selector
**Changed:**
- `apps/studio/eslint.config.cjs`: switched from
`eslint-config-supabase/next` to the new `eslint-config-supabase/react`
preset (dropping `@next/next/no-img-element: off`, keeping `.next` /
`next-env.d.ts` ignored for local checkouts with stale pre-migration
build artifacts)
- `apps/studio/tsconfig.json`: extends `tsconfig/base.json` directly
instead of `tsconfig/nextjs.json` (identical resolved compiler options)
- `apps/studio/.github/eslint-rule-baselines.json`: pruned 33 stale
`pages/...` and `types/next.ts` entries without changing any rule
thresholds
- `apps/studio/tests/lib/custom-render.tsx`: backed
`TestFrameworkProvider` with TanStack Router instead of
`next-router-mock`
-
`apps/studio/components/interfaces/Integrations/GraphQL/GraphiQLTab.tsx`:
imports `graphiql/setup-workers/vite` directly
- `apps/studio/styles/globals.css`: replaced `@source
'../pages/**/*.{js,ts,jsx,tsx}'` with `@source
'../routes/**/*.{js,ts,jsx,tsx}'`
- `apps/studio/turbo.jsonc`: declared `"NEXT_PUBLIC_*"` in
`tasks.build.env` now that Turborepo infers `nitro` instead of `nextjs`
-
`apps/studio/components/interfaces/Organization/Organization.utils.ts`:
narrowed `buildOrgUrl`'s `slug` parameter to `string[] | undefined`
**Added:**
- `packages/eslint-config-supabase/shared.js` and
`packages/eslint-config-supabase/react.js` (plus `presets.test.ts`),
decoupling non-Next React apps from `eslint-config-next` with verified
zero non-`@next/*` rule drift while keeping
`eslint-config-supabase/next` unchanged for the Next.js apps
## To test
- Run `pnpm --filter eslint-config-supabase run test` and confirm preset
parity tests pass
- Run `pnpm --filter studio run lint`, `pnpm --filter studio run
lint:ratchet`, `pnpm --filter studio run typecheck`, `pnpm knip
--workspace apps/studio`, and `pnpm --filter studio run test`
- Run `pnpm --filter studio run build` and verify the production build,
prerendered routes, chunk-cycle check, and GraphiQL web workers succeed
- Smoke-test Studio locally (`pnpm dev:studio`): verify GraphiQL loads
cleanly, ConnectSheet framework steps render, and Tailwind styles on
route pages are intact
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
221 lines
8.8 KiB
TypeScript
221 lines
8.8 KiB
TypeScript
import { QueryClient } from '@tanstack/react-query'
|
|
import { screen, waitFor } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import type { platformComponents } from 'api-types'
|
|
import { FeatureFlagContext, LOCAL_STORAGE_KEYS } from 'common'
|
|
import { HttpResponse } from 'msw'
|
|
import { ResizablePanelGroup } from 'ui'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { UserPanel } from './UserPanel'
|
|
import { FeaturePreviewContextProvider } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
|
|
import type { User } from '@/data/auth/users-infinite-query'
|
|
import { miscKeys } from '@/data/misc/keys'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
|
|
import { mockPermissions } from '@/tests/lib/msw-permissions'
|
|
import { NO_PERMISSIONS } from '@/tests/lib/permissions-fixtures'
|
|
import { createMockProfile, createMockProfileContext } from '@/tests/lib/profile-helpers'
|
|
|
|
const mockUser: User = {
|
|
id: '11111111-1111-1111-1111-111111111111',
|
|
email: 'user@example.com',
|
|
providers: ['email'],
|
|
created_at: '2026-01-01T12:00:00Z',
|
|
raw_user_meta_data: { locale: 'en', preferences: { theme: 'dark' } },
|
|
raw_app_meta_data: { providers: ['email'] },
|
|
}
|
|
|
|
vi.mock('./UserLogs', () => ({
|
|
UserLogs: () => <div data-testid="user-logs" />,
|
|
}))
|
|
|
|
const renderPanel = (
|
|
disabledFeatures: string[] = [],
|
|
{ otel = false, unifiedLogs = false }: { otel?: boolean | null; unifiedLogs?: boolean } = {}
|
|
) => {
|
|
localStorage.setItem(LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS, JSON.stringify(unifiedLogs))
|
|
mockPermissions(NO_PERMISSIONS)
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/auth/:ref/config',
|
|
response: () => HttpResponse.json<APIErrorBody>({ message: 'Unavailable' }, { status: 403 }),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref',
|
|
response: {
|
|
cloud_provider: 'AWS',
|
|
db_host: 'db.default.supabase.co',
|
|
high_availability: false,
|
|
id: 1,
|
|
inserted_at: '2026-01-01T00:00:00Z',
|
|
integration_source: null,
|
|
is_branch_enabled: false,
|
|
is_physical_backups_enabled: false,
|
|
name: 'Test project',
|
|
organization_id: 1,
|
|
ref: 'default',
|
|
region: 'us-east-1',
|
|
restUrl: 'https://default.supabase.co',
|
|
status: 'ACTIVE_HEALTHY',
|
|
subscription_id: 'subscription-1',
|
|
updated_at: '2026-01-01T00:00:00Z',
|
|
connectionString: 'postgresql://postgres:password@localhost:5432/postgres',
|
|
},
|
|
})
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/pg-meta/:ref/query',
|
|
response: () => HttpResponse.json<User[]>([mockUser]),
|
|
})
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
queryClient.setQueryData(miscKeys.enabledFeaturesOverride(), { disabled_features: [] })
|
|
|
|
const content = (backend = otel) => (
|
|
<FeatureFlagContext.Provider
|
|
value={{
|
|
configcat: backend === null ? {} : { otelUnifiedLogs: backend },
|
|
posthog: {},
|
|
hasLoaded: true,
|
|
}}
|
|
>
|
|
<FeaturePreviewContextProvider>
|
|
<ResizablePanelGroup orientation="horizontal">
|
|
<UserPanel />
|
|
</ResizablePanelGroup>
|
|
</FeaturePreviewContextProvider>
|
|
</FeatureFlagContext.Provider>
|
|
)
|
|
const rendered = customRender(content(), {
|
|
queryClient,
|
|
initialUrl: '/project/default/auth/users',
|
|
nuqs: { searchParams: `?show=${mockUser.id}` },
|
|
profileContext: createMockProfileContext({
|
|
profile: createMockProfile({ disabled_features: disabledFeatures }),
|
|
}),
|
|
})
|
|
return {
|
|
...rendered,
|
|
queryClient,
|
|
updateBackend: (backend: boolean) => rendered.rerender(content(backend)),
|
|
}
|
|
}
|
|
|
|
function setIsHoverDevice(isHoverDevice: boolean) {
|
|
window.matchMedia = ((query: string) => ({
|
|
matches: isHoverDevice && query.includes('hover: hover'),
|
|
media: query,
|
|
onchange: null,
|
|
addListener: () => {},
|
|
removeListener: () => {},
|
|
addEventListener: () => {},
|
|
removeEventListener: () => {},
|
|
dispatchEvent: () => false,
|
|
})) as unknown as typeof window.matchMedia
|
|
}
|
|
|
|
describe('UserPanel', () => {
|
|
afterEach(() => {
|
|
localStorage.removeItem(LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS)
|
|
setIsHoverDevice(false)
|
|
})
|
|
|
|
it('shows the legacy Logs tab when logs are enabled', async () => {
|
|
const { queryClient } = renderPanel()
|
|
expect(await screen.findByRole('tab', { name: 'Overview' })).toBeInTheDocument()
|
|
expect(screen.getByRole('tab', { name: 'Logs' })).toBeInTheDocument()
|
|
expect(screen.getByRole('tab', { name: 'Raw JSON' })).toBeInTheDocument()
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
})
|
|
|
|
it('hides the legacy Logs tab when logs are disabled', async () => {
|
|
const { queryClient } = renderPanel(['logs:all'])
|
|
expect(await screen.findByRole('tab', { name: 'Overview' })).toBeInTheDocument()
|
|
expect(screen.queryByRole('tab', { name: 'Logs' })).not.toBeInTheDocument()
|
|
expect(screen.getByRole('tab', { name: 'Raw JSON' })).toBeInTheDocument()
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
})
|
|
|
|
it('keeps the overview copy menu on hover devices', async () => {
|
|
const user = userEvent.setup()
|
|
const copy = vi.spyOn(navigator.clipboard, 'writeText')
|
|
setIsHoverDevice(true)
|
|
const { queryClient } = renderPanel()
|
|
const emailField = await screen.findByRole('button', { name: 'Email user@example.com' })
|
|
emailField.focus()
|
|
await user.keyboard('{Enter}')
|
|
await user.click(await screen.findByRole('menuitem', { name: 'Copy Email' }))
|
|
expect(copy).toHaveBeenLastCalledWith(mockUser.email)
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
})
|
|
|
|
it('copies overview fields and complete raw JSON from the selected user', async () => {
|
|
const user = userEvent.setup()
|
|
const copy = vi.spyOn(navigator.clipboard, 'writeText')
|
|
const { queryClient } = renderPanel()
|
|
expect(
|
|
await screen.findByRole('button', { name: 'Email user@example.com' })
|
|
).toBeInTheDocument()
|
|
const emailField = screen.getByRole('button', { name: 'Email user@example.com' })
|
|
emailField.focus()
|
|
await user.keyboard('{Enter}')
|
|
await user.click(await screen.findByRole('menuitem', { name: 'Copy Email' }))
|
|
expect(copy).toHaveBeenLastCalledWith(mockUser.email)
|
|
expect(screen.getByText('U')).toBeInTheDocument()
|
|
expect(screen.getByRole('button', { name: 'Close panel' })).toBeInTheDocument()
|
|
await user.click(screen.getByRole('tab', { name: 'Raw JSON' }))
|
|
await user.click(await screen.findByRole('button', { name: 'Copy user as JSON' }))
|
|
expect(copy).toHaveBeenCalledTimes(2)
|
|
expect(JSON.parse(copy.mock.calls[1][0])).toEqual(mockUser)
|
|
expect(screen.queryByPlaceholderText('Filter...')).not.toBeInTheDocument()
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
})
|
|
it.each([true, null])(
|
|
'shows recent user logs after Raw JSON with backend flag %s',
|
|
async (otel) => {
|
|
const user = userEvent.setup()
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/projects/:ref/analytics/endpoints/logs.all.otel',
|
|
response: () =>
|
|
HttpResponse.json<platformComponents['schemas']['AnalyticsResponse_Output']>({
|
|
result: [],
|
|
}),
|
|
})
|
|
const { queryClient } = renderPanel([], { otel, unifiedLogs: true })
|
|
await screen.findByRole('tab', { name: 'Logs' })
|
|
expect(screen.getAllByRole('tab').map((tab) => tab.textContent)).toEqual([
|
|
'Overview',
|
|
'Raw JSON',
|
|
'Logs',
|
|
])
|
|
await user.click(screen.getByRole('tab', { name: 'Logs' }))
|
|
expect(await screen.findByText('No logs in the last 24 hours')).toBeVisible()
|
|
expect(screen.queryByRole('link', { name: 'View logs' })).not.toBeInTheDocument()
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
}
|
|
)
|
|
it('keeps Logs selected when switching between legacy and unified logs', async () => {
|
|
const user = userEvent.setup()
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/projects/:ref/analytics/endpoints/logs.all.otel',
|
|
response: () =>
|
|
HttpResponse.json<platformComponents['schemas']['AnalyticsResponse_Output']>({
|
|
result: [],
|
|
}),
|
|
})
|
|
const { updateBackend, queryClient } = renderPanel([], { otel: false, unifiedLogs: true })
|
|
await user.click(await screen.findByRole('tab', { name: 'Logs' }))
|
|
expect(await screen.findByTestId('user-logs')).toBeVisible()
|
|
updateBackend(true)
|
|
expect(await screen.findByText('No logs in the last 24 hours')).toBeVisible()
|
|
expect(screen.getByRole('tab', { name: 'Logs' })).toHaveAttribute('aria-selected', 'true')
|
|
updateBackend(false)
|
|
expect(await screen.findByTestId('user-logs')).toBeVisible()
|
|
expect(screen.getByRole('tab', { name: 'Logs' })).toHaveAttribute('aria-selected', 'true')
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
})
|
|
})
|