v1.1.0: pooled runtime, 959 tests, production hardening (0 squash)

This commit is contained in:
John Dvorak
2025-08-15 10:00:00 -07:00
commit 92deb689cd
321 changed files with 79170 additions and 0 deletions
@@ -0,0 +1,43 @@
/**
* Custom renderer adapter for Imhotep Playwright.
*
* Allows users to provide their own mount function for arbitrary
* render targets. This is the escape hatch for frameworks not
* explicitly supported by built-in adapters.
*/
import { Page } from 'playwright'
import type { SceneTarget } from 'imhotep-core/scene-target'
import { RendererAdapter } from './renderers.js'
export interface CustomAdapterOptions {
/** Unique identifier for this adapter instance. */
id?: string
/** User-provided mount function. */
mount: (page: Page, target: SceneTarget, input: unknown) => Promise<void>
/** Optional user-provided unmount function. */
unmount?: (page: Page) => Promise<void>
}
export function createCustomAdapter(options: CustomAdapterOptions): RendererAdapter {
return {
id: options.id ?? 'custom',
async mount(page: Page, target: SceneTarget, input: unknown): Promise<void> {
if (target.kind !== 'custom-renderer' && target.kind !== 'react-component' && target.kind !== 'vue-component') {
throw new Error(
`Custom adapter received unsupported target kind: ${target.kind}. ` +
`Expected 'custom-renderer', 'react-component', or 'vue-component'. ` +
`If you registered this adapter for a specific renderer, ensure the target matches.`
)
}
await options.mount(page, target, input)
},
async unmount(page: Page): Promise<void> {
if (options.unmount) {
await options.unmount(page)
}
},
}
}