summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-frontmatter.js
blob: 3021f926fb89546e6b185893e948f09f86a6b155 (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
import mdx from '@astrojs/mdx';

import { expect } from 'chai';
import { loadFixture } from '../../../astro/test/test-utils.js';

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

describe('MDX frontmatter', () => {
	it('builds when "frontmatter.property" is in JSX expression', async () => {
		const fixture = await loadFixture({
			root: FIXTURE_ROOT,
			integrations: [mdx()],
		});
		await fixture.build();
		expect(true).to.equal(true);
	});

	it('extracts frontmatter to "frontmatter" export', async () => {
		const fixture = await loadFixture({
			root: FIXTURE_ROOT,
			integrations: [mdx()],
		});
		await fixture.build();

		const { titles } = JSON.parse(await fixture.readFile('/glob.json'));
		expect(titles).to.include('Using YAML frontmatter');
	});

	it('extracts frontmatter to "customFrontmatter" export when configured', async () => {
		const fixture = await loadFixture({
			root: new URL('./fixtures/mdx-custom-frontmatter-name/', import.meta.url),
			integrations: [
				mdx({
					frontmatterOptions: {
						name: 'customFrontmatter',
					},
				}),
			],
		});
		await fixture.build();

		const { titles } = JSON.parse(await fixture.readFile('/glob.json'));
		expect(titles).to.include('Using YAML frontmatter');
	});
});