1/**
2 * Tests for design-parser.mjs — frontmatter + body extraction.
3 * Run with: node --test tests/design-parser.test.mjs
4 */
5
6import { describe, it } from 'node:test';
7import assert from 'node:assert/strict';
8import { parseDesignMd } from '../skill/scripts/design-parser.mjs';
9
10describe('parseDesignMd frontmatter branch', () => {
11 it('returns null frontmatter when the file has no YAML header', () => {
12 const md = `# Design System: Demo
13
14## 1. Overview
15
16Some prose.
17`;
18 const model = parseDesignMd(md);
19 assert.equal(model.schemaVersion, 2);
20 assert.equal(model.frontmatter, null);
21 assert.equal(model.title, 'Design System: Demo');
22 });
23
24 it('parses a Stitch-shaped frontmatter and strips it from the body', () => {
25 const md = `---
26name: Demo System
27description: A quiet editorial look.
28colors:
29 primary: "#b8422e"
30 neutral-bg: "#faf7f2"
31typography:
32 display:
33 fontFamily: "Cormorant Garamond, Georgia, serif"
34 fontWeight: 300
35 lineHeight: 1
36 body:
37 fontFamily: "Inter, sans-serif"
38rounded:
39 sm: "4px"
40 md: "8px"
41components:
42 button-primary:
43 backgroundColor: "{colors.primary}"
44 textColor: "{colors.neutral-bg}"
45 rounded: "{rounded.sm}"
46---
47
48# Design System: Demo
49
50## 1. Overview
51
52Opening prose.
53`;
54 const model = parseDesignMd(md);
55 assert.equal(model.schemaVersion, 2);
56 assert.equal(model.title, 'Design System: Demo');
57 assert.ok(model.frontmatter);
58 assert.equal(model.frontmatter.name, 'Demo System');
59 assert.equal(model.frontmatter.description, 'A quiet editorial look.');
60 assert.equal(model.frontmatter.colors.primary, '#b8422e');
61 assert.equal(model.frontmatter.colors['neutral-bg'], '#faf7f2');
62 assert.equal(model.frontmatter.typography.display.fontFamily, 'Cormorant Garamond, Georgia, serif');
63 assert.equal(model.frontmatter.typography.display.fontWeight, 300);
64 assert.equal(model.frontmatter.typography.display.lineHeight, 1);
65 assert.equal(model.frontmatter.rounded.md, '8px');
66 assert.equal(model.frontmatter.components['button-primary'].backgroundColor, '{colors.primary}');
67 });
68
69 it('recovers gracefully when frontmatter has no closing marker', () => {
70 // No `---` terminator: the whole file is treated as body, not partial
71 // frontmatter. The H1 title still resolves from the body.
72 const md = `---
73this is not valid yaml : : :
74no closing marker
75# Design System: Broken
76
77## 1. Overview
78
79Prose.
80`;
81 const model = parseDesignMd(md);
82 assert.equal(model.frontmatter, null);
83 assert.equal(model.title, 'Design System: Broken');
84 });
85
86 it('ignores line-only comments but preserves unquoted hex values', () => {
87 const md = `---
88# Top-level comment
89colors:
90 primary: #b8422e
91 # mid-block comment
92 accent: "#ec4899"
93---
94
95# Design System: Commented
96
97## 1. Overview
98
99Prose.
100`;
101 const model = parseDesignMd(md);
102 assert.equal(model.frontmatter.colors.primary, '#b8422e');
103 assert.equal(model.frontmatter.colors.accent, '#ec4899');
104 });
105});