import { getQueriesForElement , prettyDOM } from "@testing-library/dom" ; import { hydrate as solidHydrate , render as solidRender } from "solid-js/web" ; import type { Ui , Result , Options , Ref } from "./types" ; /**
 * Shim for the teardown function
 */ declare var teardown ; if ( ! process . env . STL_SKIP_AUTO_CLEANUP ) { if ( typeof afterEach === "function" ) { afterEach ( async ( ) => { await cleanup ( ) ; } ) ; } else if ( typeof teardown === "function" ) { teardown ( async ( ) => { await cleanup ( ) ; } ) ; } } const mountedContainers = new Set < Ref > ( ) ; function render ( ui , options = { } ) { let { container , baseElement = container , queries , hydrate = false } = options ; if ( ! baseElement ) { baseElement = document . body ; } if ( ! container ) { container = baseElement . appendChild ( document . createElement ( "div" ) ) ; } const dispose = hydrate ? ( ( solidHydrate ( ui , container ) as unknown ) as ( ) => void ) : solidRender ( ui , container ) ; mountedContainers . add ( { container , dispose } ) ; return { container , baseElement , debug : ( el = baseElement , maxLength , options ) => Array . isArray ( el ) ? el . forEach ( e => console . log ( prettyDOM ( e , maxLength , options ) ) ) : console . log ( prettyDOM ( el , maxLength , options ) ) , unmount : dispose , ... getQueriesForElement ( baseElement , queries ) } as Result ; } function cleanupAtContainer ( ref ) { const { container , dispose } = ref ; dispose ( ) ; if ( container . parentNode === document . body ) { document . body . removeChild ( container ) ; } mountedContainers . delete ( ref ) ; } function cleanup ( ) { mountedContainers . forEach ( cleanupAtContainer ) ; } export * from "@testing-library/dom" ; export { render , cleanup } ;