Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript
1.2 KB
Raw Blame
// Use the /vitest subpath export: extends Vitest's Assertion interface
// (not Jest's), so `expect(el).toBeInTheDocument()` / `toBeDisabled()` etc.
// type-check cleanly under `tsc --noEmit`. The bare `@testing-library/jest-dom`
// entry point only declares types against the Jest global.
import '@testing-library/jest-dom/vitest'

function createMemoryStorage(): Storage {
  const store = new Map<string, string>()
  return {
    get length() {
      return store.size
    },
    clear() {
      store.clear()
    },
    getItem(key: string) {
      return store.get(key) ?? null
    },
    key(index: number) {
      return Array.from(store.keys())[index] ?? null
    },
    removeItem(key: string) {
      store.delete(key)
    },
    setItem(key: string, value: string) {
      store.set(key, String(value))
    },
  }
}

if (
  typeof window !== 'undefined' &&
  (typeof window.localStorage?.getItem !== 'function' ||
    typeof window.localStorage?.setItem !== 'function' ||
    typeof window.localStorage?.removeItem !== 'function' ||
    typeof window.localStorage?.clear !== 'function')
) {
  Object.defineProperty(window, 'localStorage', {
    configurable: true,
    value: createMemoryStorage(),
  })
}