What problem does this solve?
Astro projects currently do not have a first-class Rstest integration. Astro's official unit/component testing story is Vite-based: users load Astro config with getViteConfig() and test .astro component output through the experimental Container API.
Because Rstest is currently Rsbuild/Rspack-based, importing .astro files and using Astro-specific virtual modules/renderers is not supported out of the box.
Proposed solution
Add first-class Astro support, likely as an experimental adapter package:
import { withAstroConfig } from '@rstest/adapter-astro';
import { defineConfig } from '@rstest/core';
export default defineConfig({
extends: withAstroConfig(),
testEnvironment: 'node',
});
The adapter should allow tests like:
import { experimental_AstroContainer as AstroContainer } from 'astro/container';
import { expect, test } from '@rstest/core';
import Card from '../src/components/Card.astro';
test('renders Astro component output', async () => {
const container = await AstroContainer.create();
const html = await container.renderToString(Card, {
slots: {
default: 'Card content',
},
});
expect(html).toContain('Card content');
});
Expected scope
- Load
astro.config.* and reuse test-relevant configuration.
- Support importing
.astro files in Rstest.
- Support Astro Container API tests for props, slots, request, params, locals, and endpoint/page rendering.
- Support official Astro renderers where possible (
@astrojs/react, @astrojs/vue, @astrojs/svelte, @astrojs/preact, @astrojs/solid-js, @astrojs/mdx).
- Add e2e fixtures and docs for Astro projects.
- Optionally detect Astro projects in setup/init guidance.
Implementation notes
There are two likely paths:
- MVP: Rspack loader/plugin backed by
@astrojs/compiler, enough for server-side .astro component tests.
- Higher fidelity: introduce a Vite-backed compile path or Vite adapter, then build
@rstest/adapter-astro on top of Astro's own Vite config helpers.
The first path is smaller and fits Rstest's current architecture. The second path is likely closer to Astro's official testing model, especially for virtual modules, integrations, CSS/assets, and content-related features.
References
What problem does this solve?
Astro projects currently do not have a first-class Rstest integration. Astro's official unit/component testing story is Vite-based: users load Astro config with
getViteConfig()and test.astrocomponent output through the experimental Container API.Because Rstest is currently Rsbuild/Rspack-based, importing
.astrofiles and using Astro-specific virtual modules/renderers is not supported out of the box.Proposed solution
Add first-class Astro support, likely as an experimental adapter package:
The adapter should allow tests like:
Expected scope
astro.config.*and reuse test-relevant configuration..astrofiles in Rstest.@astrojs/react,@astrojs/vue,@astrojs/svelte,@astrojs/preact,@astrojs/solid-js,@astrojs/mdx).Implementation notes
There are two likely paths:
@astrojs/compiler, enough for server-side.astrocomponent tests.@rstest/adapter-astroon top of Astro's own Vite config helpers.The first path is smaller and fits Rstest's current architecture. The second path is likely closer to Astro's official testing model, especially for virtual modules, integrations, CSS/assets, and content-related features.
References