Skip to content

Feature: add first-class Astro support #1209

@Nsttt

Description

@Nsttt

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:

  1. MVP: Rspack loader/plugin backed by @astrojs/compiler, enough for server-side .astro component tests.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions