summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/test/content-collections.test.js
blob: aad389e0ccd21945a86cd52a2251668b14de508f (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { parse as parseDevalue } from 'devalue';
import { expect } from 'chai';
import { loadFixture, fixLineEndings } from '../../../astro/test/test-utils.js';
import markdoc from '../dist/index.js';

function formatPost(post) {
	return {
		...post,
		body: fixLineEndings(post.body),
	};
}

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

describe('Markdoc - Content Collections', () => {
	let baseFixture;

	before(async () => {
		baseFixture = await loadFixture({
			root,
			integrations: [markdoc()],
		});
	});

	describe('dev', () => {
		let devServer;

		before(async () => {
			devServer = await baseFixture.startDevServer();
		});

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

		it('loads entry', async () => {
			const res = await baseFixture.fetch('/entry.json');
			const post = parseDevalue(await res.text());
			expect(formatPost(post)).to.deep.equal(post1Entry);
		});

		it('loads collection', async () => {
			const res = await baseFixture.fetch('/collection.json');
			const posts = parseDevalue(await res.text());
			expect(posts).to.not.be.null;

			expect(posts.sort().map((post) => formatPost(post))).to.deep.equal([
				post1Entry,
				post2Entry,
				post3Entry,
			]);
		});
	});

	describe('build', () => {
		before(async () => {
			await baseFixture.build();
		});

		it('loads entry', async () => {
			const res = await baseFixture.readFile('/entry.json');
			const post = parseDevalue(res);
			expect(formatPost(post)).to.deep.equal(post1Entry);
		});

		it('loads collection', async () => {
			const res = await baseFixture.readFile('/collection.json');
			const posts = parseDevalue(res);
			expect(posts).to.not.be.null;
			expect(posts.sort().map((post) => formatPost(post))).to.deep.equal([
				post1Entry,
				post2Entry,
				post3Entry,
			]);
		});
	});
});

const post1Entry = {
	id: 'post-1.mdoc',
	slug: 'post-1',
	collection: 'blog',
	data: {
		schemaWorks: true,
		title: 'Post 1',
	},
	body: '\n## Post 1\n\nThis is the contents of post 1.\n',
};

const post2Entry = {
	id: 'post-2.mdoc',
	slug: 'post-2',
	collection: 'blog',
	data: {
		schemaWorks: true,
		title: 'Post 2',
	},
	body: '\n## Post 2\n\nThis is the contents of post 2.\n',
};

const post3Entry = {
	id: 'post-3.mdoc',
	slug: 'post-3',
	collection: 'blog',
	data: {
		schemaWorks: true,
		title: 'Post 3',
	},
	body: '\n## Post 3\n\nThis is the contents of post 3.\n',
};