{"version":3,"file":"pure.mjs","names":["coreRender"],"sources":["../src/pure.ts"],"sourcesContent":["import { type Locator, type LocatorSelectors, page, server, utils } from 'vitest/browser'\nimport { cleanup, render as coreRender, wrapperSetup } from '@testing-library/svelte-core'\nimport type { Component, ComponentImport, ComponentOptions, Exports, Rerender, SetupOptions } from '@testing-library/svelte-core/types'\n\nconst { debug, getElementLocatorSelectors } = utils\n\n/** The rendered component and bound testing functions. */\ninterface RenderResult<C extends Component, W extends Component = never> extends LocatorSelectors {\n  container: HTMLElement\n  baseElement: HTMLElement\n  component: Exports<C>\n  wrapper: Exports<W>\n  debug: (el?: HTMLElement) => void\n  /** Update the component props and record a `svelte.rerender` trace mark. */\n  rerender: Rerender<C>\n  /** Unmount the component and record a `svelte.unmount` trace mark. */\n  unmount: () => Promise<void>\n  locator: Locator\n}\n\n/**\n * Render a component into the document and record a `svelte.render` trace mark.\n *\n * @param Component - The component to render.\n * @param options - Customize how Svelte renders the component.\n * @param renderOptions - Customize how the document and queries are set up.\n * @returns The rendered component and bound testing functions.\n */\nasync function render<C extends Component, W extends Component = never>(Component: ComponentImport<C>, options: ComponentOptions<C> = {}, renderOptions: SetupOptions<W> = {}): Promise<RenderResult<C, W>> {\n  if (renderOptions.wrapper) {\n    await wrapperSetup()\n  }\n\n  const { baseElement, container, component, wrapper, rerender, unmount } = coreRender(Component, options, renderOptions)\n  ensureTestIdAttribute(baseElement)\n  ensureTestIdAttribute(container)\n\n  const queries = getElementLocatorSelectors(baseElement)\n  const locator = page.elementLocator(container)\n\n  const result: RenderResult<C, W> = {\n    baseElement,\n    component,\n    wrapper,\n    container,\n    locator,\n    rerender: async (props) => {\n      await rerender(props)\n      await mark(locator, 'svelte.rerender', result.rerender)\n    },\n    unmount: async () => {\n      unmount()\n      await mark(locator, 'svelte.unmount', result.unmount)\n    },\n    debug: (el = baseElement) => {\n      debug(el)\n    },\n    ...queries,\n  }\n\n  await mark(locator, 'svelte.render', render)\n\n  return result\n}\n\nasync function mark(locator: Locator, name: string, fn: Function): Promise<void> {\n  if (!locator.mark) {\n    return\n  }\n\n  const error = new Error(name)\n  if ('captureStackTrace' in Error && typeof Error.captureStackTrace === 'function') {\n    Error.captureStackTrace(error, fn)\n  }\n\n  await locator.mark(name, error)\n}\n\nlet idx = 0\n\nfunction ensureTestIdAttribute(element: HTMLElement) {\n  const attributeId = server.config.browser.locators.testIdAttribute\n  if (!element.hasAttribute(attributeId)) {\n    element.setAttribute(attributeId, `__vitest_${idx++}__`)\n  }\n}\n\nexport { cleanup, render, type RenderResult }\nexport type { Component, ComponentImport, ComponentOptions, Exports, Rerender, SetupOptions } from '@testing-library/svelte-core/types'\n"],"mappings":";;;AAIA,MAAM,EAAE,OAAO,+BAA+B;;;;;;;;;AAwB9C,eAAe,OAAyD,WAA+B,UAA+B,CAAC,GAAG,gBAAiC,CAAC,GAAgC;CAC1M,IAAI,cAAc,SAChB,MAAM,aAAa;CAGrB,MAAM,EAAE,aAAa,WAAW,WAAW,SAAS,UAAU,YAAYA,SAAW,WAAW,SAAS,aAAa;CACtH,sBAAsB,WAAW;CACjC,sBAAsB,SAAS;CAE/B,MAAM,UAAU,2BAA2B,WAAW;CACtD,MAAM,UAAU,KAAK,eAAe,SAAS;CAE7C,MAAM,SAA6B;EACjC;EACA;EACA;EACA;EACA;EACA,UAAU,OAAO,UAAU;GACzB,MAAM,SAAS,KAAK;GACpB,MAAM,KAAK,SAAS,mBAAmB,OAAO,QAAQ;EACxD;EACA,SAAS,YAAY;GACnB,QAAQ;GACR,MAAM,KAAK,SAAS,kBAAkB,OAAO,OAAO;EACtD;EACA,QAAQ,KAAK,gBAAgB;GAC3B,MAAM,EAAE;EACV;EACA,GAAG;CACL;CAEA,MAAM,KAAK,SAAS,iBAAiB,MAAM;CAE3C,OAAO;AACT;AAEA,eAAe,KAAK,SAAkB,MAAc,IAA6B;CAC/E,IAAI,CAAC,QAAQ,MACX;CAGF,MAAM,QAAQ,IAAI,MAAM,IAAI;CAC5B,IAAI,uBAAuB,SAAS,OAAO,MAAM,sBAAsB,YACrE,MAAM,kBAAkB,OAAO,EAAE;CAGnC,MAAM,QAAQ,KAAK,MAAM,KAAK;AAChC;AAEA,IAAI,MAAM;AAEV,SAAS,sBAAsB,SAAsB;CACnD,MAAM,cAAc,OAAO,OAAO,QAAQ,SAAS;CACnD,IAAI,CAAC,QAAQ,aAAa,WAAW,GACnC,QAAQ,aAAa,aAAa,YAAY,MAAM,GAAG;AAE3D"}