forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildApiDocLink.test.mjs
More file actions
88 lines (75 loc) · 2.28 KB
/
buildApiDocLink.test.mjs
File metadata and controls
88 lines (75 loc) · 2.28 KB
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
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getEntryDescription, buildApiDocLink } from '../buildApiDocLink.mjs';
describe('getEntryDescription', () => {
it('returns llmDescription when available', () => {
const entry = {
llmDescription: 'LLM generated description',
content: { children: [] },
};
const result = getEntryDescription(entry);
assert.equal(result, 'LLM generated description');
});
it('extracts first paragraph when no llmDescription', () => {
const entry = {
content: {
children: [
{
type: 'paragraph',
children: [{ type: 'text', value: 'First paragraph' }],
},
],
},
};
const result = getEntryDescription(entry);
assert.ok(result.length > 0);
});
it('returns empty string when no paragraph found', () => {
const entry = {
content: {
children: [
{ type: 'heading', children: [{ type: 'text', value: 'Title' }] },
],
},
};
const result = getEntryDescription(entry);
assert.equal(result, '');
});
it('removes newlines from description', () => {
const entry = {
content: {
children: [
{
type: 'paragraph',
children: [{ type: 'text', value: 'Line 1\nLine 2\r\nLine 3' }],
},
],
},
};
const result = getEntryDescription(entry);
assert.equal(result.includes('\n'), false);
assert.equal(result.includes('\r'), false);
});
});
describe('buildApiDocLink', () => {
it('builds markdown link with description', () => {
const entry = {
heading: { data: { name: 'Test API' } },
api_doc_source: 'doc/api/test.md',
llmDescription: 'Test description',
};
const result = buildApiDocLink(entry);
assert.ok(result.includes('[Test API]'));
assert.ok(result.includes('/docs/latest/api/test.md'));
assert.ok(result.includes('Test description'));
});
it('handles doc path replacement', () => {
const entry = {
heading: { data: { name: 'API Method' } },
api_doc_source: 'doc/some/path.md',
content: { children: [] },
};
const result = buildApiDocLink(entry);
assert.ok(result.includes('/docs/latest/some/path.md'));
});
});