summaryrefslogtreecommitdiff
path: root/packages/astro/test/astro-dynamic.test.js
blob: fc104c2bd7fed8c625e165e1aa19dc7d5feab74f (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
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('Dynamic components', () => {
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			projectRoot: './fixtures/astro-dynamic/',
		});
		await fixture.build();
	});

	it('Loads packages that only run code in client', async () => {
		const html = await fixture.readFile('/index.html');

		const $ = cheerio.load(html);
		expect($('script').length).to.eq(2);
	});

	it('Loads pages using client:media hydrator', async () => {
		const root = new URL('http://example.com/media/index.html');
		const html = await fixture.readFile('/media/index.html');
		const $ = cheerio.load(html);

		// test 1: static value rendered
		expect($('script').length).to.equal(2); // One for each
	});

	it('Loads pages using client:only hydrator', async () => {
		const html = await fixture.readFile('/client-only/index.html');
		const $ = cheerio.load(html);

		// test 1: <astro-root> is empty
		expect($('<astro-root>').html()).to.equal('');
		const script = $('script').text();

		// Grab the svelte import
		// const exp = /import\("(.+?)"\)/g;
		// let match, svelteRenderer;
		// while ((match = exp.exec(result.contents))) {
		//   if (match[1].includes('renderers/renderer-svelte/client.js')) {
		//     svelteRenderer = match[1];
		//   }
		// }

		// test 2: Svelte renderer is on the page
		// expect(svelteRenderer).to.be.ok;

		// test 3: Can load svelte renderer
		// const result = await fixture.fetch(svelteRenderer);
		// expect(result.status).to.equal(200);
	});
});