#vitest causing build failures
4 messages · Page 1 of 1 (latest)
Hi @icy saddle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Here are some common Vitest-related issues in Astro projects and how to address them:
1. Astro Components in Client Environments (Astro v6)
In Astro 6, rendering Astro components in Vitest client environments (like jsdom or happy-dom) is no longer supported. Tests that render Astro components must now run in a node environment. [Vitest client environments]
Update your Vitest config:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node', // changed from 'jsdom' or 'happy-dom'
},
});
2. Vitest Version Compatibility (Astro v6)
Using Astro's getViteConfig() helper with Astro v6 requires at least Vitest v3.2 or v4.1 beta 5. Make sure your Vitest version meets this requirement. [Vite 7.0 upgrade]
3. Setting Up Vitest Correctly
Use Astro's getViteConfig() helper in your vitest.config.ts to properly integrate Vitest with your Astro project settings: [Vitest setup]
/// <reference types="vitest/config" />
import { getViteConfig } from 'astro/config';
export default getViteConfig({
test: {
// Vitest configuration options
},
});
You can also pass a second argument to customize the Astro configuration used in tests:
export default getViteConfig(
{ test: { /* Vitest configuration options */ } },
{
site: '<https://example.com/',>
trailingSlash: 'always',
},
);