mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
* fix logs previewer and msw * refactor api mocking for better dx * update readme * comment out error handler for vitest * rm unnecessary tests * fix custom render nuqs type * add logs search test * rm unnecessary import * update readme with customRender and customRednerHook * rm unnecessary api handler * Move the NODE_ENV to the studio build command in turbo.json. * Update apps/studio/tests/README.md Co-authored-by: Joshen Lim <joshenlimek@gmail.com> * add cursor rule --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { render, renderHook, RenderOptions } from '@testing-library/react'
|
|
import { NuqsTestingAdapter } from 'nuqs/adapters/testing'
|
|
import { TooltipProvider } from 'ui'
|
|
|
|
type AdapterProps = Partial<Parameters<typeof NuqsTestingAdapter>[0]>
|
|
|
|
const CustomWrapper = ({
|
|
children,
|
|
queryClient,
|
|
nuqs,
|
|
}: {
|
|
children: React.ReactNode
|
|
queryClient?: QueryClient
|
|
nuqs?: AdapterProps
|
|
}) => {
|
|
const _queryClient =
|
|
queryClient ??
|
|
new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
retry: false,
|
|
},
|
|
},
|
|
})
|
|
|
|
return (
|
|
<QueryClientProvider client={_queryClient}>
|
|
<NuqsTestingAdapter {...nuqs}>
|
|
<TooltipProvider>{children}</TooltipProvider>
|
|
</NuqsTestingAdapter>
|
|
</QueryClientProvider>
|
|
)
|
|
}
|
|
|
|
type CustomRenderOpts = RenderOptions & {
|
|
queryClient?: QueryClient
|
|
nuqs?: AdapterProps
|
|
}
|
|
|
|
export const customRender = (component: React.ReactElement, renderOptions?: CustomRenderOpts) => {
|
|
return render(component, {
|
|
wrapper: ({ children }) =>
|
|
CustomWrapper({
|
|
queryClient: renderOptions?.queryClient,
|
|
nuqs: renderOptions?.nuqs,
|
|
children,
|
|
}),
|
|
...renderOptions,
|
|
})
|
|
}
|
|
|
|
export const customRenderHook = (hook: () => any, renderOptions?: CustomRenderOpts) => {
|
|
return renderHook(hook, {
|
|
wrapper: ({ children }) =>
|
|
CustomWrapper({
|
|
children,
|
|
queryClient: renderOptions?.queryClient,
|
|
nuqs: renderOptions?.nuqs,
|
|
}),
|
|
...renderOptions,
|
|
})
|
|
}
|