mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem - `apps/studio/tests/setup/radix.js` holds the jsdom stubs for `ResizeObserver` and `scrollIntoView` but nothing in it is specific to radix - studio already keeps its jsdom stubs in `tests/setup/polyfills.ts` ## Solution - moves the `ResizeObserver` and `scrollIntoView` stubs into `tests/setup/polyfills.ts` + removes `radix.js` from the vitest setup files - changes the studio-testing skill to name the one dom setup file that remains <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. run `pnpm test:studio` and make sure that the run reports no unhandled errors 2. make sure that the failures are the same as on `master` ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import { ReadableStream, TransformStream } from 'node:stream/web'
|
|
import { TextDecoder, TextEncoder } from 'node:util'
|
|
import { act } from '@testing-library/react'
|
|
import { configMocks } from 'jsdom-testing-mocks'
|
|
import { vi } from 'vitest'
|
|
|
|
configMocks({ act })
|
|
|
|
// Warning: `restoreMocks: true` in vitest.config.ts will
|
|
// cause this global mockImplementation to be **reset**
|
|
// before any tests are run!
|
|
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(),
|
|
})),
|
|
})
|
|
|
|
Object.defineProperties(globalThis, {
|
|
TextDecoder: { value: TextDecoder },
|
|
TextEncoder: { value: TextEncoder },
|
|
CSS: {
|
|
value: {
|
|
supports: (_k: any, _v: any) => false,
|
|
escape: (v: any) => v,
|
|
},
|
|
},
|
|
ReadableStream: { value: ReadableStream },
|
|
TransformStream: { value: TransformStream },
|
|
})
|
|
|
|
if (typeof window.localStorage?.getItem !== 'function') {
|
|
const storage = new Map<string, string>()
|
|
const localStoragePolyfill = {
|
|
getItem: vi.fn((key: string) => storage.get(key) ?? null),
|
|
setItem: vi.fn((key: string, value: string) => {
|
|
storage.set(key, value)
|
|
}),
|
|
removeItem: vi.fn((key: string) => {
|
|
storage.delete(key)
|
|
}),
|
|
clear: vi.fn(() => {
|
|
storage.clear()
|
|
}),
|
|
key: vi.fn((index: number) => Array.from(storage.keys())[index] ?? null),
|
|
get length() {
|
|
return storage.size
|
|
},
|
|
}
|
|
|
|
Object.defineProperty(window, 'localStorage', {
|
|
configurable: true,
|
|
value: localStoragePolyfill,
|
|
})
|
|
|
|
Object.defineProperty(globalThis, 'localStorage', {
|
|
configurable: true,
|
|
value: localStoragePolyfill,
|
|
})
|
|
}
|
|
|
|
window.HTMLElement.prototype.hasPointerCapture = vi.fn()
|
|
window.HTMLElement.prototype.scrollIntoView = () => {}
|
|
|
|
window.ResizeObserver = class ResizeObserver {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
}
|
|
|
|
// base ui scroll area calls getAnimations, which jsdom does not have
|
|
window.Element.prototype.getAnimations ??= () => []
|