This document describes the testing infrastructure used in the Tailwind CSS repository, including the test frameworks, organization, and execution patterns. The testing setup supports multiple languages (TypeScript and Rust) and multiple test types (unit, integration, UI, and performance benchmarking).
The repository uses a multi-language testing strategy to validate both the TypeScript integration layer and the Rust performance-critical components.
Sources: packages/tailwindcss/playwright.config.ts1-13 packages/@tailwindcss-browser/playwright.config.ts1-7 integrations/vite/vue.test.ts4-5
UI tests are conducted using Playwright to ensure that Tailwind CSS correctly generates and applies styles in real browser environments. This is particularly critical for the @tailwindcss/browser package and features that depend on browser-specific behaviors like the hover variant. packages/tailwindcss/playwright.config.ts12-13 packages/@tailwindcss-browser/playwright.config.ts6-7
The Playwright configuration accounts for browser-specific quirks. For example, Firefox in headless mode is configured to simulate pointer capabilities to ensure media queries like (hover: hover) evaluate correctly by setting ui.primaryPointerCapabilities to 0x02 | 0x04. packages/tailwindcss/playwright.config.ts44-71
Tests for the CDN/Browser version use a specialized createServer utility to mock a web server using h3 and listhen that serves the compiled Tailwind browser script. packages/@tailwindcss-browser/tests/ui.spec.ts108-176
MutationObserver in the browser build correctly detects class changes and updates styles via page.evaluate. packages/@tailwindcss-browser/tests/ui.spec.ts25-36@theme blocks within <style type="text/tailwindcss"> tags triggers a style recalculation. packages/@tailwindcss-browser/tests/ui.spec.ts64-883000 + workerIndex. packages/@tailwindcss-browser/tests/ui.spec.ts162-168Sources: packages/@tailwindcss-browser/tests/ui.spec.ts16-23 packages/tailwindcss/playwright.config.ts65-67 packages/@tailwindcss-browser/tests/ui.spec.ts162-168
Integration tests validate the interaction between different packages (e.g., Vite, Svelte, Vue, PostCSS) and real-world usage scenarios. These tests utilize a custom testing harness to manage temporary file systems and process execution.
The test function in the integration suite provides a rich TestContext that automates the setup of complex project structures. integrations/vite/svelte.test.ts3-94
fs object containing package.json, vite.config.ts, and source files using template tags like json, ts, html, and css. integrations/vite/svelte.test.ts6-93pnpm vite build) and verify the output in the dist directory. integrations/vite/vue.test.ts65-69spawn to keep a process alive and fs.write to trigger rebuilds, asserting changes via retryAssertion. integrations/vite/svelte.test.ts206-235The following diagram illustrates how the system manages the lifecycle of an integration test for a build tool like Vite.
Sources: integrations/vite/svelte.test.ts95-107 integrations/vite/vue.test.ts65-73 integrations/vite/ssr.test.ts57-70
The following diagram bridges high-level testing concepts to the specific code entities and configurations in the repository.
Sources: packages/tailwindcss/playwright.config.ts12 packages/@tailwindcss-browser/tests/ui.spec.ts108 integrations/vite/source-maps.test.ts67 integrations/vite/svelte.test.ts1
| Component | Path | Description |
|---|---|---|
| Vite Integration | integrations/vite/ | Comprehensive tests for Vite plugin, including SSR, CSS Modules, and multi-root setups. integrations/vite/ssr.test.ts1-7 integrations/vite/css-modules.test.ts1-5 |
| Framework Adapters | integrations/vite/vue.test.ts | Validates SFC support, scoped styles, and @apply behavior in Vue/Svelte. integrations/vite/vue.test.ts46-62 |
| Source Map Testing | integrations/vite/source-maps.test.ts | Verifies that generated utilities map back to utilities.css or user source files. integrations/vite/source-maps.test.ts67-91 |
| Asset Handling | integrations/vite/url-rewriting.test.ts | Ensures url() paths in CSS are correctly rewritten during the build process. integrations/vite/url-rewriting.test.ts8-107 |
| Legacy Config Support | integrations/vite/config.test.ts | Validates that v4 can still ingest tailwind.config.js (CJS/ESM) via the @config directive. integrations/vite/config.test.ts3-50 |
Sources: integrations/vite/vue.test.ts1-178 integrations/vite/source-maps.test.ts1-93 integrations/vite/url-rewriting.test.ts1-108 integrations/vite/config.test.ts1-130
Refresh this wiki