mirror of
https://github.com/supabase/supabase.git
synced 2026-05-06 08:56:46 -04:00
7f5865872a
## Context Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix all related issues
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import '@testing-library/jest-dom/vitest'
|
|
|
|
import { cleanup } from '@testing-library/react'
|
|
import dayjs from 'dayjs'
|
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
|
import timezone from 'dayjs/plugin/timezone'
|
|
import utc from 'dayjs/plugin/utc'
|
|
import { createDynamicRouteParser } from 'next-router-mock/dist/dynamic-routes'
|
|
import { afterAll, afterEach, beforeAll, vi } from 'vitest'
|
|
|
|
import { mswServer } from './lib/msw'
|
|
import { routerMock } from './lib/route-mock'
|
|
|
|
dayjs.extend(utc)
|
|
dayjs.extend(timezone)
|
|
dayjs.extend(relativeTime)
|
|
|
|
// Uncomment this if HTML in errors are being annoying.
|
|
//
|
|
// configure({
|
|
// getElementError: (message, container) => {
|
|
// const error = new Error(message ?? 'Element not found')
|
|
// error.name = 'ElementNotFoundError'
|
|
// return error
|
|
// },
|
|
// })
|
|
|
|
beforeAll(() => {
|
|
mswServer.listen({ onUnhandledRequest: `error` })
|
|
vi.mock('next/router', () => require('next-router-mock'))
|
|
vi.mock('next/navigation', async () => {
|
|
const actual = await vi.importActual('next/navigation')
|
|
return {
|
|
...actual,
|
|
useRouter: () => {
|
|
return {
|
|
push: vi.fn(),
|
|
replace: vi.fn(),
|
|
}
|
|
},
|
|
usePathname: () => vi.fn(),
|
|
useSearchParams: () => ({
|
|
get: vi.fn(),
|
|
}),
|
|
}
|
|
})
|
|
|
|
vi.mock('next/compat/router', () => require('next-router-mock'))
|
|
|
|
// Mock the useParams hook from common module globally
|
|
vi.mock('common', async (importOriginal: any) => {
|
|
const actual = await importOriginal()
|
|
return {
|
|
...(typeof actual === 'object' ? actual : {}),
|
|
useParams: () => ({ ref: 'default' }),
|
|
}
|
|
})
|
|
|
|
routerMock.useParser(createDynamicRouteParser(['/projects/[ref]']))
|
|
})
|
|
|
|
afterEach(() => {
|
|
mswServer.resetHandlers()
|
|
cleanup()
|
|
})
|
|
|
|
afterAll(() => {
|
|
mswServer.close()
|
|
})
|