parse-frontmatter-json.test.mjs
27 lines 914 B
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 17 hours ago
1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { parseFrontmatterJsonText, materializeWireFrontmatter } from '../lib/parse-frontmatter-json.mjs';
4
5 test('plain object', () => {
6 assert.equal(parseFrontmatterJsonText('{"title":"x"}').title, 'x');
7 });
8
9 test('BOM + object', () => {
10 assert.equal(parseFrontmatterJsonText('\uFEFF{"title":"x"}').title, 'x');
11 });
12
13 test('JSON string whose value is JSON object text', () => {
14 const wire = JSON.stringify(JSON.stringify({ title: 'Hub probe', tags: 't' }));
15 const fm = parseFrontmatterJsonText(wire);
16 assert.equal(fm.title, 'Hub probe');
17 assert.equal(fm.tags, 't');
18 });
19
20 test('materialize passes object through', () => {
21 assert.equal(materializeWireFrontmatter({ a: 1 }).a, 1);
22 });
23
24 test('empty and legacy', () => {
25 assert.deepEqual(parseFrontmatterJsonText(''), {});
26 assert.deepEqual(parseFrontmatterJsonText('{}'), {});
27 });
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 17 hours ago