tailwindcss.test.js — astro Source File
Architecture documentation for tailwindcss.test.js, a javascript file in the astro codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 93afb8a4_ad1b_b1df_85da_d61f60f3bb31["tailwindcss.test.js"] 0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"] 93afb8a4_ad1b_b1df_85da_d61f60f3bb31 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15 dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"] 93afb8a4_ad1b_b1df_85da_d61f60f3bb31 --> dd4f09ce_3fd7_8295_f616_8876cda4555c e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"] 93afb8a4_ad1b_b1df_85da_d61f60f3bb31 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607 6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"] 93afb8a4_ad1b_b1df_85da_d61f60f3bb31 --> 6b0635f9_51ea_77aa_767b_7857878e98a6 deb87372_5629_35f8_9a54_e755a08f776a["cheerio"] 93afb8a4_ad1b_b1df_85da_d61f60f3bb31 --> deb87372_5629_35f8_9a54_e755a08f776a style 93afb8a4_ad1b_b1df_85da_d61f60f3bb31 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Tailwind', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/tailwindcss/',
});
});
// test HTML and CSS contents for accuracy
describe('build', () => {
let $;
let bundledCSS;
before(async () => {
await fixture.build();
// get bundled CSS (will be hashed, hence DOM query)
const html = await fixture.readFile('/index.html');
$ = cheerio.load(html);
const bundledCSSHREF = $('link[rel=stylesheet][href^=/_astro/]').attr('href');
bundledCSS = await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/'));
});
it('resolves CSS in src/styles', async () => {
assert.match(bundledCSS, /\.bg-purple-600\{/, 'includes used component classes');
// tests a random tailwind class that isn't used on the page
assert.doesNotMatch(bundledCSS, /\.bg-blue-600\{/, 'purges unused classes');
// tailwind escapes colons, `lg:py-3` compiles to `lg\:py-3`
assert.match(bundledCSS, /\.lg\\:py-3\{/, 'includes responsive classes');
// tailwind escapes brackets, `font-[900]` compiles to `font-\[900\]`
assert.match(bundledCSS, /\.font-\\\[900\\\]\{/, 'supports arbitrary value classes');
// custom theme colors were included
assert.match(bundledCSS, /\.text-midnight\{/, 'includes custom theme colors');
assert.match(bundledCSS, /\.bg-dawn\{/, 'includes custom theme colors');
});
it('maintains classes in HTML', async () => {
const button = $('button');
assert.equal(button.hasClass('text-white'), true, 'basic class');
assert.equal(button.hasClass('lg:py-3'), true, 'responsive class');
assert.equal(button.hasClass('font-[900]'), true, 'arbitrary value');
});
it('handles complex classes in HTML', async () => {
const button = $('#complex');
assert.equal(button.hasClass('w-10/12'), true, 'solidus');
assert.equal(button.hasClass('2xl:w-[80%]'), true, 'complex class');
});
it('handles MDX pages (with integration)', async () => {
const html = await fixture.readFile('/mdx-page/index.html');
const $md = cheerio.load(html);
const bundledCSSHREF = $md('link[rel=stylesheet][href^=/_astro/]').attr('href');
const mdBundledCSS = await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/'));
assert.match(mdBundledCSS, /\.bg-purple-600\{/, 'includes used component classes');
});
});
});
Domain
Dependencies
- cheerio
- loadFixture
- node:test
- strict
- test-utils.js
Source
Frequently Asked Questions
What does tailwindcss.test.js do?
tailwindcss.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does tailwindcss.test.js depend on?
tailwindcss.test.js imports 5 module(s): cheerio, loadFixture, node:test, strict, test-utils.js.
Where is tailwindcss.test.js in the architecture?
tailwindcss.test.js is located at packages/astro/test/tailwindcss.test.js (domain: IntegrationAdapters, directory: packages/astro/test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free