Home / File/ postcss.test.js — astro Source File

postcss.test.js — astro Source File

Architecture documentation for postcss.test.js, a javascript file in the astro codebase. 6 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  cbcb88df_4f99_8179_b964_d00ed28f64b3["postcss.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  cbcb88df_4f99_8179_b964_d00ed28f64b3 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  cbcb88df_4f99_8179_b964_d00ed28f64b3 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  cbcb88df_4f99_8179_b964_d00ed28f64b3 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  cbcb88df_4f99_8179_b964_d00ed28f64b3 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  cbcb88df_4f99_8179_b964_d00ed28f64b3 --> deb87372_5629_35f8_9a54_e755a08f776a
  65772cd5_a47a_6e58_cb6d_b6cb79fbd234["eol"]
  cbcb88df_4f99_8179_b964_d00ed28f64b3 --> 65772cd5_a47a_6e58_cb6d_b6cb79fbd234
  style cbcb88df_4f99_8179_b964_d00ed28f64b3 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 eol from 'eol';
import { loadFixture } from './test-utils.js';

describe('PostCSS', () => {
	let fixture;
	let bundledCSS;
	before(
		async () => {
			fixture = await loadFixture({
				root: './fixtures/postcss',
				// test suite was authored when inlineStylesheets defaulted to never
				build: { inlineStylesheets: 'never' },
			});
			await fixture.build();

			// get bundled CSS (will be hashed, hence DOM query)
			const html = await fixture.readFile('/index.html');
			const $ = cheerio.load(html);
			const bundledCSSHREF = $('link[rel=stylesheet][href^=/_astro/]').attr('href');
			bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/')))
				.replace(/\s/g, '')
				.replace('/n', '');
		},
		{ timeout: 45000 },
	);

	/** All test cases check whether nested styles (i.e. &.nested {}) are correctly transformed */
	it('works in Astro page styles', () => {
		assert.match(bundledCSS, /\.astro-page\[data-astro-cid-.*?\]\.nested/);
	});

	it('works in Astro component styles', () => {
		assert.match(bundledCSS, /\.astro-component\[data-astro-cid-.*?\]\.nested/);
	});

	it('works in JSX', () => {
		assert.match(bundledCSS, /\.solid(\.[\w-]+)?\.nested/);
	});

	it('works in Vue', () => {
		assert.match(bundledCSS, /\.vue(\.[\w-]+)?\.nested/);
	});

	it('works in Svelte', () => {
		assert.match(bundledCSS, /\.svelte(\.[\w-]+)?\.nested/);
	});

	it('ignores CSS in public/', async () => {
		const publicCSS = (await fixture.readFile('/global.css'))
			.trim()
			.replace(/\s/g, '')
			.replace('/n', '');
		// neither minified nor prefixed
		assert.equal(eol.lf(publicCSS), '.global{appearance:none;}');
	});
});

Dependencies

Frequently Asked Questions

What does postcss.test.js do?
postcss.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does postcss.test.js depend on?
postcss.test.js imports 6 module(s): cheerio, eol, loadFixture, node:test, strict, test-utils.js.
Where is postcss.test.js in the architecture?
postcss.test.js is located at packages/astro/test/postcss.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