{"version":3,"file":"lifecycle-BRCkZgmB.cjs","names":[],"sources":["../src/inertia.ts","../src/lifecycle.ts"],"sourcesContent":["export interface MockInertiaPage<TProps = Record<string, unknown>> {\n  component: string\n  props: TProps\n  url: string\n  version?: string\n}\n\nconst defaultPage: MockInertiaPage = {\n  component: 'TestComponent',\n  props: {},\n  url: '/',\n  version: undefined,\n}\n\nlet currentPage: MockInertiaPage = { ...defaultPage }\n\nexport function getInertiaPage<TProps>(): MockInertiaPage<TProps> {\n  return currentPage as MockInertiaPage<TProps>\n}\n\nexport function setInertiaPage<TProps>(\n  page: Partial<MockInertiaPage<TProps>>,\n): void {\n  currentPage = {\n    ...defaultPage,\n    ...page,\n    props: (page.props ?? ({} as TProps)),\n  } as MockInertiaPage\n}\n\nexport function resetInertiaPage(): void {\n  currentPage = { ...defaultPage }\n}\n\nexport function createInertiaReactMock(\n  actual: Record<string, unknown> = {},\n  overrides: Record<string, unknown> = {},\n) {\n  return {\n    ...actual,\n    ...overrides,\n    usePage: () => getInertiaPage(),\n  }\n}\n","export type LifecycleHookFn = (fn: () => void | Promise<void>) => void\n\n/**\n * Test-runner lifecycle hooks used by helpers that register per-test setup,\n * such as `useDatabaseTransactions()` and `useTruncateTables()`.\n */\nexport interface TestLifecycleHooks {\n  beforeEach: LifecycleHookFn\n  afterEach: LifecycleHookFn\n}\n\nlet registeredHooks: TestLifecycleHooks | null = null\n\n/**\n * Register the lifecycle hooks of the active test runner. `@guren/testing/vitest`\n * does this automatically; bun:test globals are picked up without registration.\n */\nexport function setTestLifecycleHooks(hooks: TestLifecycleHooks): void {\n  registeredHooks = hooks\n}\n\n/**\n * Resolve the lifecycle hooks to use: explicitly registered hooks first,\n * then runner-injected globals (bun:test always, vitest with `globals: true`).\n */\nexport function getTestLifecycleHooks(): TestLifecycleHooks {\n  if (registeredHooks) {\n    return registeredHooks\n  }\n\n  const globals = globalThis as Record<string, unknown>\n  if (\n    typeof globals.beforeEach === 'function' &&\n    typeof globals.afterEach === 'function'\n  ) {\n    return {\n      beforeEach: globals.beforeEach as LifecycleHookFn,\n      afterEach: globals.afterEach as LifecycleHookFn,\n    }\n  }\n\n  throw new Error(\n    'Test lifecycle hooks are not available. In vitest, import ' +\n      \"'@guren/testing/vitest' once in your test setup (or enable globals); \" +\n      'bun:test injects the required globals automatically. Alternatively, ' +\n      'pass { beforeEach, afterEach } to the helper explicitly.'\n  )\n}\n"],"mappings":";AAOA,MAAM,cAA+B;CACnC,WAAW;CACX,OAAO,CAAC;CACR,KAAK;CACL,SAAS,KAAA;AACX;AAEA,IAAI,cAA+B,EAAE,GAAG,YAAY;AAEpD,SAAgB,iBAAkD;CAChE,OAAO;AACT;AAEA,SAAgB,eACd,MACM;CACN,cAAc;EACZ,GAAG;EACH,GAAG;EACH,OAAQ,KAAK,SAAU,CAAC;CAC1B;AACF;AAEA,SAAgB,mBAAyB;CACvC,cAAc,EAAE,GAAG,YAAY;AACjC;AAEA,SAAgB,uBACd,SAAkC,CAAC,GACnC,YAAqC,CAAC,GACtC;CACA,OAAO;EACL,GAAG;EACH,GAAG;EACH,eAAe,eAAe;CAChC;AACF;;;AChCA,IAAI,kBAA6C;;;;;AAMjD,SAAgB,sBAAsB,OAAiC;CACrE,kBAAkB;AACpB;;;;;AAMA,SAAgB,wBAA4C;CAC1D,IAAI,iBACF,OAAO;CAGT,MAAM,UAAU;CAChB,IACE,OAAO,QAAQ,eAAe,cAC9B,OAAO,QAAQ,cAAc,YAE7B,OAAO;EACL,YAAY,QAAQ;EACpB,WAAW,QAAQ;CACrB;CAGF,MAAM,IAAI,MACR,6PAIF;AACF"}