summaryrefslogtreecommitdiff
path: root/packages/astro/test/postcss.test.js
blob: 862d37c2f798c8b34835eb39a414e2cf06d43ada (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { expect } from 'chai';
import cheerio from 'cheerio';
import eol from 'eol';
import { loadFixture } from './test-utils.js';

describe('PostCSS', () => {
	const PREFIXED_CSS = `{-webkit-appearance:none;appearance:none}`;

	let fixture;
	let bundledCSS;
	before(async () => {
		fixture = await loadFixture({
			projectRoot: './fixtures/postcss',
			renderers: ['@astrojs/renderer-solid', '@astrojs/renderer-svelte', '@astrojs/renderer-vue'],
		});
		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^=/assets/]').attr('href');
		bundledCSS = await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/'));
	});

	it('works in Astro page styles', () => {
		expect(bundledCSS).to.match(new RegExp(`.astro-page.astro-[^{]+${PREFIXED_CSS}`));
	});

	it('works in Astro component styles', () => {
		expect(bundledCSS).to.match(new RegExp(`.astro-component.astro-[^{]+${PREFIXED_CSS}`));
	});

	it('works in JSX', () => {
		expect(bundledCSS).to.match(new RegExp(`.solid[^{]*${PREFIXED_CSS}`));
	});

	it('works in Vue', () => {
		expect(bundledCSS).to.match(new RegExp(`.vue[^{]*${PREFIXED_CSS}`));
	});

	it('works in Svelte', () => {
		expect(bundledCSS).to.match(new RegExp(`.svelte.s[^{]+${PREFIXED_CSS}`));
	});

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