summaryrefslogtreecommitdiff
path: root/packages/integrations/vue/test/app-entrypoint-css.test.js
blob: b629f1d25f5875d44969ed6e0b6ee35160fe2093 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';
import { load as cheerioLoad } from 'cheerio';

describe('App Entrypoint CSS', () => {
	/** @type {import('./test-utils').Fixture} */
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/app-entrypoint-css/',
		});
	})

	describe('build', () => {
		before(async () => {
			await fixture.build();
		})

		it('injects styles referenced in appEntrypoint', async () => {
			const html = await fixture.readFile('/index.html');
			const $ = cheerioLoad(html);

			// test 1: basic component renders
			expect($('#foo > #bar').text()).to.eq('works');

			// test 2: injects the global style on the page
			expect($('style').first().text().trim()).to.eq(':root{background-color:red}');
		});

		it('does not inject styles to pages without a Vue component', async () => {
			const html = await fixture.readFile('/unrelated/index.html');
			const $ = cheerioLoad(html);

			expect($('style').length).to.eq(0);
			expect($('link[rel="stylesheet"]').length).to.eq(0);
		});
	})

	describe('dev', () => {
		let devServer;
		before(async () => {
			devServer = await fixture.startDevServer();
		})
		after(async () => {
			await devServer.stop();
		})

		it('loads during SSR', async () => {
			const html = await fixture.fetch('/').then((res) => res.text());
			const $ = cheerioLoad(html);
			
			// test 1: basic component renders
			expect($('#foo > #bar').text()).to.eq('works');
			// test 2: injects the global style on the page
			expect($('style').first().text().replace(/\s+/g, '')).to.eq(':root{background-color:red;}');
		});

		it('does not inject styles to pages without a Vue component', async () => {
			const html = await fixture.fetch('/unrelated').then((res) => res.text());
			const $ = cheerioLoad(html);

			expect($('style').length).to.eq(0);
			expect($('link[rel="stylesheet"]').length).to.eq(0);
		});
	})
});