Skip to content

Commit 2e18282

Browse files
committed
feat(metadata): add tests for capturing YAML frontmatter
1 parent 21e0ea7 commit 2e18282

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/generators/metadata/utils/__tests__/parse.test.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,40 @@ describe('parseApiDoc', () => {
239239
assert.strictEqual(results.length, 0);
240240
});
241241
});
242+
243+
describe('top-level nodes (YAML frontmatter)', () => {
244+
it('captures top-level frontmatter in the first entry', () => {
245+
const tree = u('root', [
246+
u('yaml', 'layout: home\ncontributors: [shams]'),
247+
h('First Heading'),
248+
u('paragraph', [u('text', 'First content.')]),
249+
h('Second Heading', 2),
250+
u('paragraph', [u('text', 'Second content.')]),
251+
]);
252+
const results = parseApiDoc({ path, tree }, typeMap);
253+
254+
assert.strictEqual(results.length, 2);
255+
256+
const firstContent = results[0].content.children;
257+
assert.strictEqual(firstContent.length, 3);
258+
assert.strictEqual(firstContent[0].type, 'yaml');
259+
assert.strictEqual(firstContent[1].type, 'heading');
260+
261+
const secondContent = results[1].content.children;
262+
assert.strictEqual(secondContent.length, 2);
263+
assert.strictEqual(secondContent[0].type, 'heading');
264+
});
265+
266+
it('works correctly without top-level frontmatter', () => {
267+
const tree = u('root', [
268+
h('First Heading'),
269+
u('paragraph', [u('text', 'First content.')]),
270+
]);
271+
const results = parseApiDoc({ path, tree }, typeMap);
272+
273+
assert.strictEqual(results.length, 1);
274+
assert.strictEqual(results[0].content.children.length, 2);
275+
assert.strictEqual(results[0].content.children[0].type, 'heading');
276+
});
277+
});
242278
});

0 commit comments

Comments
 (0)