summaryrefslogtreecommitdiff
path: root/packages/astro/test/units/dev/hydration.test.js
blob: 0a176b4db0fe8a6705188b1954926c31a3842e08 (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
import { expect } from 'chai';

import { runInContainer } from '../../../dist/core/dev/index.js';
import { createFs, createRequestAndResponse } from '../test-utils.js';
import svelte from '../../../../integrations/svelte/dist/index.js';
import { defaultLogging } from '../../test-utils.js';

const root = new URL('../../fixtures/alias/', import.meta.url);

describe('dev container', () => {
	it('should not crash when reassigning a hydrated component', async () => {
		const fs = createFs(
			{
				'/src/pages/index.astro': `
				---
				import Svelte from '../components/Client.svelte';
				const Foo = Svelte;
				const Bar = Svelte;
				---
				<html>
					<head><title>testing</title></head>
					<body>
						<Foo client:load />
						<Bar client:load />
					</body>
				</html>
			`,
			},
			root
		);

		await runInContainer(
			{
				fs,
				root,
				logging: {
					...defaultLogging,
					// Error is expected in this test
					level: 'silent',
				},
				userConfig: {
					integrations: [svelte()],
				},
			},
			async (container) => {
				const { req, res, done } = createRequestAndResponse({
					method: 'GET',
					url: '/',
				});
				container.handle(req, res);
				await done;
				expect(res.statusCode).to.equal(
					200,
					"We get a 200 because the error occurs in the template, but we didn't crash!"
				);
			}
		);
	});
});