-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathindex.test.mjs
More file actions
120 lines (105 loc) · 2.83 KB
/
index.test.mjs
File metadata and controls
120 lines (105 loc) · 2.83 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import assert from 'node:assert';
import { join } from 'node:path';
import { test } from 'node:test';
import { Validator } from 'jsonschema';
import { SemVer } from 'semver';
import { BASE_URL } from '../../../constants.mjs';
import createGenerator from '../../../generators.mjs';
import createMarkdownLoader from '../../../loaders/markdown.mjs';
import createMarkdownParser from '../../../parsers/markdown.mjs';
import { SCHEMA_FILENAME } from '../constants.mjs';
import jsonAll from '../index.mjs';
import { generateJsonSchema } from '../util/generateJsonSchema.mjs';
const FIXTURES_DIR = join(
import.meta.dirname,
'..',
'json',
'__tests__',
'fixtures'
);
const loader = createMarkdownLoader();
const parser = createMarkdownParser();
test('generator output complies with json schema', async () => {
const validator = new Validator();
const version = 'v1.2.3';
/**
* @type {object}
*/
const schema = generateJsonSchema(version);
const input = [
join(FIXTURES_DIR, 'text-doc.md'),
join(FIXTURES_DIR, 'module.md'),
];
const files = await loader.loadFiles(input);
const docs = await parser.parseApiDocs(files);
const { runGenerators } = createGenerator(docs);
const result = await runGenerators({
generators: ['json-all'],
input,
output: undefined,
version: new SemVer('v1.2.3'),
releases: [],
gitRef: 'a'.repeat(40),
threads: 1,
typeMap: {},
});
assert.ok(validator.validate(result, schema).valid);
});
test('combines json correctly', async () => {
const version = 'v1.2.3';
/**
* @type {Array<import('../../json/generated.d.ts').NodeJsAPIDocumentationSchema>}
*/
const jsonOutput = [
{
$schema: `https://nodejs.org/docs/${version}/api/node-doc-schema.json`,
source: 'doc/api/some-module.md',
type: 'module',
'@name': 'Some Module',
'@module': 'node:module',
classes: [],
},
{
$schema: `https://nodejs.org/docs/${version}/api/node-doc-schema.json`,
source: 'doc/api/some-module.md',
type: 'text',
'@name': 'Some Module',
description: 'asdf',
text: [
{
type: 'text',
'@name': 'asdf',
description: 'bla bla bla',
},
],
},
];
const result = await jsonAll.generate(jsonOutput, {
version: new SemVer(version),
});
assert.deepStrictEqual(result, {
$schema: `${BASE_URL}docs/${version}/api/${SCHEMA_FILENAME}`,
modules: [
{
type: 'module',
'@name': 'Some Module',
'@module': 'node:module',
classes: [],
},
],
text: [
{
type: 'text',
'@name': 'Some Module',
description: 'asdf',
text: [
{
type: 'text',
'@name': 'asdf',
description: 'bla bla bla',
},
],
},
],
});
});