Files
supabase/apps/studio/tests/vitestSetup.ts
T
3c588294a6 Improve Integration Test Setup and re-add LogPreviewer tests (#35358)
* 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>
2025-05-06 09:50:56 +02:00

65 lines
1.6 KiB
TypeScript

import '@testing-library/jest-dom/vitest'
import { cleanup, configure } from '@testing-library/react'
import { createDynamicRouteParser } from 'next-router-mock/dist/dynamic-routes'
import { afterAll, afterEach, beforeAll, vi } from 'vitest'
import { routerMock } from './lib/route-mock'
import { mswServer } from './lib/msw'
mswServer.listen({ onUnhandledRequest: 'error' })
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})
// 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(() => {
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'))
routerMock.useParser(createDynamicRouteParser(['/projects/[ref]']))
})
afterAll(() => mswServer.close())
afterEach(() => mswServer.resetHandlers())
afterEach(() => {
cleanup()
})