summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-script-style-raw.test.js
blob: 99c17ed8d6fff1b32a2110b6505f7270b93b5033 (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
import mdx from '@astrojs/mdx';
import { expect } from 'chai';
import { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';

const FIXTURE_ROOT = new URL('./fixtures/mdx-script-style-raw/', import.meta.url);

describe('MDX script style raw', () => {
	describe('dev', () => {
		let fixture;
		let devServer;

		before(async () => {
			fixture = await loadFixture({
				root: FIXTURE_ROOT,
				integrations: [mdx()],
			});
			devServer = await fixture.startDevServer();
		});

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

		it('works with with raw script and style strings', async () => {
			const res = await fixture.fetch('/index.html');
			expect(res.status).to.equal(200);

			const html = await res.text();
			const { document } = parseHTML(html);

			const scriptContent = document.getElementById('test-script').innerHTML;
			expect(scriptContent).to.include(
				"console.log('raw script')",
				'script should not be html-escaped'
			);

			const styleContent = document.getElementById('test-style').innerHTML;
			expect(styleContent).to.include(
				'h1[id="script-style-raw"]',
				'style should not be html-escaped'
			);
		});
	});

	describe('build', () => {
		it('works with with raw script and style strings', async () => {
			const fixture = await loadFixture({
				root: FIXTURE_ROOT,
				integrations: [mdx()],
			});
			await fixture.build();

			const html = await fixture.readFile('/index.html');
			const { document } = parseHTML(html);

			const scriptContent = document.getElementById('test-script').innerHTML;
			expect(scriptContent).to.include(
				"console.log('raw script')",
				'script should not be html-escaped'
			);

			const styleContent = document.getElementById('test-style').innerHTML;
			expect(styleContent).to.include(
				'h1[id="script-style-raw"]',
				'style should not be html-escaped'
			);
		});
	});
});