UNPKG

@igor.dvlpr/astro-render-component

Version:

๐Ÿค– Plug-and-play Astro component renderer for fast, zero-config testing in any DOM-like JS/TS environment. ๐Ÿฌ

132 lines (87 loc) โ€ข 4.32 kB
<div align="center"> <img src="https://raw.githubusercontent.com/igorskyflyer/npm-astro-render-component/main/assets/astro-render-component.png" alt="Icon of Astro Render Component" width="256" height="256"> <h1 align="center">Astro Render Component</h1> </div> <br> <div align="center"> ๐Ÿค– Plug-and-play Astro component renderer for fast, zero-config testing in any DOM-like JS/TS environment. ๐Ÿฌ </div> <br> <br> ## ๐Ÿ“ƒ Table of Contents - [Features](#-features) - [Usage](#-usage) - [Example](#๏ธ-example) - [Changelog](#-changelog) - [Support](#-support) - [License](#-license) - [Related](#-related) - [Author](#-author) --- ## ๐Ÿค– Features - ๐Ÿ”ง Server-side rendering of Astro components in non-Astro environments like Vitest or Node.js - ๐Ÿงช Test-friendly API for rendering `.astro` components with props, slots, and hydration strategies - ๐Ÿช„ Zero-config usageโ€”just import and render, no need for full Astro setup - ๐Ÿงฉ Supports static, lazy, and client-only hydration modes - ๐Ÿง  Typed API with JSDoc annotations for IntelliSense and DX-first workflows - ๐Ÿ•ธ๏ธ Compatible with Astro v5+, leveraging the experimental [AstroContainer API](https://docs.astro.build/en/reference/container-reference/) - ๐Ÿš€ Ideal for unit and integration testing of UI components <br> ## ๐Ÿ•ต๐Ÿผ Usage Install the package using your favorite package manager: ```bash npm install "@igor.dvlpr/astro-render-component" # or pnpm add "@igor.dvlpr/astro-render-component" # or yarn add "@igor.dvlpr/astro-render-component" ``` Bring your own testing framework, e.g. [Vitest](https://vitest.dev/) and your own DOM-like environment, e.g. [Happy-Dom](https://www.npmjs.com/package/happy-dom) and start rendering your Astro components in order to test them. --- ## ๐Ÿ—’๏ธ Example ```ts // @โ€‹vitest-environment happy-dom import { renderAstroComponent } from '@igor.dvlpr/astro-render-component' import MyComponent from '../components/MyComponent.astro' import { expect } from 'vitest' const fragment = await renderAstroComponent(MyComponent, { props: { title: 'Hello' } }) expect(fragment.querySelector('h1')?.textContent).toBe('Hello') ``` --- ## ๐Ÿ“ Changelog ๐Ÿ“‘ The changelog is available here: [CHANGELOG.md](https://github.com/igorskyflyer/npm-astro-render-component/blob/main/CHANGELOG.md). --- ## ๐Ÿชช License Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-astro-render-component/blob/main/LICENSE.txt). --- ## ๐Ÿ’– Support <div align="center"> I work hard for every project, including this one and your support means a lot to me! <br> Consider buying me a coffee. โ˜• <br> <br> <a href="https://ko-fi.com/igorskyflyer" target="_blank"><img src="https://raw.githubusercontent.com/igorskyflyer/igorskyflyer/main/assets/ko-fi.png" alt="Donate to igorskyflyer" width="180" height="46"></a> <br> <br> <em>Thank you for supporting my efforts!</em> ๐Ÿ™๐Ÿ˜Š </div> --- ## ๐Ÿงฌ Related [@igor.dvlpr/astro-easynav-button](https://www.npmjs.com/package/@igor.dvlpr/astro-easynav-button) > _๐Ÿงญ Add an easy-to-use navigational button (jump to top/bottom) to your Astro site. ๐Ÿ”ผ_ <br> [@igor.dvlpr/astro-post-excerpt](https://www.npmjs.com/package/@igor.dvlpr/astro-post-excerpt) > _โญ An Astro component that renders post excerpts for your Astro blog - directly from your Markdown and MDX files. Astro v2+ collections are supported as well! ๐Ÿ’Ž_ <br> [@igor.dvlpr/chars-in-string](https://www.npmjs.com/package/@igor.dvlpr/chars-in-string) > _๐Ÿช Provides ways of testing whether an array of chars is present inside a given String. โ˜„_ <br> [@igor.dvlpr/magic-queryselector](https://www.npmjs.com/package/@igor.dvlpr/magic-queryselector) > _๐Ÿช„ A TypeScript-types patch for querySelector/querySelectorAll, make them return types you expect them to! ๐Ÿ”ฎ_ <br> [@igor.dvlpr/vscode-folderpicker](https://www.npmjs.com/package/@igor.dvlpr/vscode-folderpicker) > _โœจ Provides a custom Folder Picker API + UI for Visual Studio Code. ๐ŸŽจ_ --- ## ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Author Created by **Igor Dimitrijeviฤ‡** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).