Skip to content

Commit f160dc2

Browse files
committed
tmp
1 parent 64812d9 commit f160dc2

20 files changed

+328
-146
lines changed

.c8rc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"**/fixtures",
66
"src/generators/legacy-html/assets",
77
"src/generators/web/ui",
8-
"**/*.d.ts"
8+
"**/*.d.ts",
9+
"tools/"
910
]
1011
}

src/generators/json/__tests__/index.test.mjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,4 @@ describe('generator output complies with json schema', () => {
4949
assert.ok(validator.validate(result[0], schema).valid);
5050
});
5151
}
52-
53-
// TODO:
54-
// - create fixtures that cover various different types of docs we see
55-
// - run them through the generator
56-
// - validate the response with https://www.npmjs.com/package/jsonschema
5752
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
import { test } from 'node:test';
4+
import assert from 'node:assert';
5+
import { createModuleSectionBuilder } from '../../utils/createModuleSection.mjs';
6+
import { DOC_NODE_VERSION } from '../../../../constants.mjs';
7+
8+
const createModuleSection = createModuleSectionBuilder();
9+
10+
test('adds expected properties', () => {
11+
/**
12+
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
13+
*/
14+
const entry = { api: 'something' };
15+
16+
/**
17+
* @type {import('../../generated.d.ts').Module}
18+
*/
19+
const section = {};
20+
createModuleSection(entry, section);
21+
22+
assert.deepStrictEqual(
23+
section['@see'],
24+
`https://nodejs.org/dist/${DOC_NODE_VERSION}/doc/api/${entry.api}.html`
25+
);
26+
assert.deepStrictEqual(section['@module'], `node:${entry.api}`);
27+
});

src/generators/json/__tests__/utils/createPropertySection.test.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ describe('extracts type correctly', () => {
5858
children: [
5959
{
6060
type: 'paragraph',
61-
// children:
62-
}
63-
]
64-
}
65-
]
66-
}
61+
// children:
62+
},
63+
],
64+
},
65+
],
66+
},
6767
],
6868
},
6969
tags: [],
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { test } from 'node:test';
5+
import assert from 'node:assert';
6+
import { createSectionBuilder } from '../../utils/createSection.mjs';
7+
import { DOC_NODE_VERSION } from '../../../../constants.mjs';
8+
9+
const createSection = createSectionBuilder();
10+
11+
test('empty `module` section', () => {
12+
/**
13+
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
14+
*/
15+
const entry = {
16+
hierarchyChildren: [],
17+
api: 'bla',
18+
slug: 'asd',
19+
api_doc_source: 'doc/api/something.md',
20+
changes: [],
21+
heading: {
22+
type: 'heading',
23+
depth: 1,
24+
children: [],
25+
data: {
26+
text: 'Some title',
27+
name: 'Some title',
28+
depth: 1,
29+
slug: 'some-title',
30+
type: undefined,
31+
},
32+
},
33+
stability: {
34+
type: 'root',
35+
children: [],
36+
},
37+
content: {
38+
type: 'root',
39+
children: [],
40+
},
41+
tags: [],
42+
yaml_position: {},
43+
};
44+
45+
assert.deepStrictEqual(createSection(entry, [entry]), {
46+
$schema: `https://nodejs.org/doc/${DOC_NODE_VERSION}/api/node-doc-schema.json`,
47+
source: 'doc/api/something.md',
48+
'@module': 'node:bla',
49+
'@see': `https://nodejs.org/dist/${DOC_NODE_VERSION}/doc/api/bla.html`,
50+
type: 'module',
51+
'@name': 'Some title',
52+
classes: [],
53+
events: [],
54+
globals: [],
55+
methods: [],
56+
properties: [],
57+
});
58+
});
59+
60+
test('empty `text` section', () => {
61+
/**
62+
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
63+
*/
64+
const entry = {
65+
hierarchyChildren: [],
66+
api: 'bla',
67+
slug: 'asd',
68+
api_doc_source: 'doc/api/something.md',
69+
changes: [],
70+
heading: {
71+
type: 'heading',
72+
depth: 1,
73+
children: [],
74+
data: {
75+
text: 'Some title',
76+
name: 'Some title',
77+
depth: 1,
78+
slug: 'some-title',
79+
type: 'misc',
80+
},
81+
},
82+
stability: {
83+
type: 'root',
84+
children: [],
85+
},
86+
content: {
87+
type: 'root',
88+
children: [],
89+
},
90+
tags: [],
91+
yaml_position: {},
92+
};
93+
94+
assert.deepStrictEqual(createSection(entry, [entry]), {
95+
$schema: `https://nodejs.org/doc/${DOC_NODE_VERSION}/api/node-doc-schema.json`,
96+
source: 'doc/api/something.md',
97+
type: 'text',
98+
'@name': 'Some title',
99+
});
100+
});

src/generators/json/__tests__/utils/createSectionBase.test.mjs

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,46 @@ describe('determines the correct type for a section', () => {
9191
'@name': 'Some title',
9292
});
9393
});
94+
95+
test('doc/api/process.md determined as module and not a global', () => {
96+
/**
97+
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
98+
*/
99+
const entry = {
100+
hierarchyChildren: [],
101+
api: 'process',
102+
slug: 'asd',
103+
api_doc_source: 'doc/api/something.md',
104+
changes: [],
105+
heading: {
106+
type: 'heading',
107+
depth: 1,
108+
children: [],
109+
data: {
110+
text: 'Process',
111+
name: 'Process',
112+
depth: 1,
113+
slug: 'process',
114+
type: 'global',
115+
},
116+
},
117+
stability: {
118+
type: 'root',
119+
children: [],
120+
},
121+
content: {
122+
type: 'root',
123+
children: [],
124+
},
125+
tags: [],
126+
yaml_position: {},
127+
};
128+
129+
assert.deepStrictEqual(createSectionBase(entry), {
130+
type: 'module',
131+
'@name': 'Process',
132+
});
133+
});
94134
});
95135

96136
for (const entryType in ENTRY_TO_SECTION_TYPE) {
@@ -302,8 +342,13 @@ describe('extracts description and examples correctly', () => {
302342
},
303343
{
304344
type: 'link',
305-
label: 'world',
306345
url: 'https://nodejs.org',
346+
children: [
347+
{
348+
type: 'text',
349+
value: 'world',
350+
},
351+
],
307352
},
308353
{
309354
type: 'paragraph',
@@ -328,6 +373,68 @@ describe('extracts description and examples correctly', () => {
328373
);
329374
});
330375

376+
test('description with `emphasis` ', () => {
377+
/**
378+
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
379+
*/
380+
const entry = {
381+
hierarchyChildren: [],
382+
api: 'bla',
383+
slug: 'asd',
384+
api_doc_source: 'doc/api/something.md',
385+
changes: [],
386+
heading: {
387+
type: 'heading',
388+
depth: 2,
389+
children: [],
390+
data: {
391+
text: 'Some title',
392+
name: 'Some title',
393+
depth: 2,
394+
slug: 'some-title',
395+
type: 'module',
396+
},
397+
},
398+
stability: {
399+
type: 'root',
400+
children: [],
401+
},
402+
content: {
403+
type: 'root',
404+
children: [
405+
{
406+
type: 'text',
407+
value: 'this should be ignored',
408+
},
409+
{
410+
type: 'paragraph',
411+
children: [
412+
{
413+
type: 'text',
414+
value: 'hello',
415+
},
416+
],
417+
},
418+
{
419+
type: 'emphasis',
420+
children: [
421+
{
422+
type: 'text',
423+
value: 'world',
424+
},
425+
],
426+
},
427+
],
428+
},
429+
tags: [],
430+
yaml_position: {},
431+
};
432+
433+
const section = createSectionBase(entry);
434+
435+
assert.strictEqual(section.description, 'hello _world_');
436+
});
437+
331438
test('extracts code examples', () => {
332439
/**
333440
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}

src/generators/json/index.mjs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { writeFile } from 'node:fs/promises';
55
import { join } from 'node:path';
66
import { groupNodesByModule } from '../../utils/generators.mjs';
77
import { createSectionBuilder } from './utils/createSection.mjs';
8+
import { parseSchema } from './utils/parseSchema.mjs';
89

910
/**
1011
* This generator is responsible for generating the JSON representation of the
@@ -83,16 +84,17 @@ export default {
8384
}
8485
}
8586

86-
await Promise.all(writeFilePromises);
87-
8887
if (output) {
89-
// // Parse the JSON schema into an object
90-
// const schema = await jsoncParse(schemaString);
88+
await Promise.all(writeFilePromises);
89+
90+
// Parse the JSON schema into an object
91+
const schema = await parseSchema();
92+
9193
// Write the parsed JSON schema to the output directory
92-
// await writeFile(
93-
// join(output, 'node-doc-schema.json'),
94-
// JSON.stringify(schema)
95-
// );
94+
await writeFile(
95+
join(output, 'node-doc-schema.json'),
96+
JSON.stringify(schema)
97+
);
9698
}
9799

98100
return generatedValues;

src/generators/json/utils/createClassSection.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { GeneratorError } from '../../../utils/generator-error.mjs';
44
import { findParentSection } from './findParentSection.mjs';
55

66
/**
7-
* @typedef {import('../../legacy-json/types.d.ts').HierarchizedEntry} HierarchizedEntry
7+
* @typedef {import('../../../utils/buildHierarchy.mjs').HierarchizedEntry} HierarchizedEntry
88
*/
99

1010
export const createClassSectionBuilder = () => {

src/generators/json/utils/createEventSection.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { findParentSection } from './findParentSection.mjs';
55
import { stringifyNode } from './stringifyNode.mjs';
66

77
/**
8-
* @typedef {import('../../legacy-json/types.d.ts').HierarchizedEntry} HierarchizedEntry
8+
* @typedef {import('../../../utils/buildHierarchy.mjs').HierarchizedEntry} HierarchizedEntry
99
*/
1010

1111
export const createEventSectionBuilder = () => {
@@ -62,7 +62,6 @@ export const createEventSectionBuilder = () => {
6262
);
6363
}
6464

65-
// todo why does delimiter.value === ' ' = false even when that's the case ????????
6665
if (rest[0]?.type === 'link') {
6766
// Type _should_ be a link with maybe a description following
6867
const [type, ...descriptionNodes] = rest;

0 commit comments

Comments
 (0)