summaryrefslogtreecommitdiff
path: root/packages/astro/test/vue-component.nodetest.js
blob: c2d753f89ecaa983affc8b3055eada7c7864f06e (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
68
69
70
71
72
73
import assert from 'node:assert/strict';
import { before, describe, it, after } from 'node:test';
import * as cheerio from 'cheerio';
import { isWindows, loadFixture } from './test-utils.js';

describe.skip('Vue component build', { todo: 'This test currently times out, investigate' }, () => {
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/vue-component/',
		});
		await fixture.build();
	});

	it('Can load Vue', async () => {
		const html = await fixture.readFile('/index.html');
		const $ = cheerio.load(html);

		const allPreValues = $('pre')
			.toArray()
			.map((el) => $(el).text());

		// test 1: renders all components correctly
		assert.deepEqual(allPreValues, ['0', '1', '1', '1', '10', '100', '1000']);

		// test 2: renders 3 <astro-island>s
		assert.equal($('astro-island').length, 6);

		// test 3: all <astro-island>s have uid attributes
		assert.equal($('astro-island[uid]').length, 6);

		// test 4: treats <my-button> as a custom element
		assert.equal($('my-button').length, 7);

		// test 5: components with identical render output and props have been deduplicated
		const uniqueRootUIDs = $('astro-island').map((i, el) => $(el).attr('uid'));
		assert.equal(new Set(uniqueRootUIDs).size, 5);

		// test 6: import public files work
		assert.ok($('#vue-img'));
	});
});

if (!isWindows) {
	describe.skip('Vue component dev', { todo: 'This test currently times out, investigate' }, () => {
		let devServer;
		let fixture;

		before(async () => {
			fixture = await loadFixture({
				root: './fixtures/vue-component/',
			});
			devServer = await fixture.startDevServer();
		});

		after(async () => {
			await devServer.stop();
		});

		it('scripts proxy correctly', async () => {
			const html = await fixture.fetch('/').then((res) => res.text());
			const $ = cheerio.load(html);

			for (const script of $('script').toArray()) {
				const { src } = script.attribs;
				if (!src) continue;
				const response = await fixture.fetch(src);
				assert.equal(response.status, 200, `404: ${src}`);
			}
		});
	});
}