1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const assert = require('assert');
|
15 | const { assertMarkdown, loadschemas } = require('./testUtils');
|
16 |
|
17 | const build = require('../lib/readmeBuilder');
|
18 | const { loader } = require('../lib/schemaProxy');
|
19 |
|
20 | describe('Testing Readme Builder', () => {
|
21 | it('Readme Builder is a function', () => {
|
22 | assert.equal(typeof build, 'function');
|
23 | });
|
24 |
|
25 | it('Readme Builder does nothing when not required', () => {
|
26 | const builder = build({ readme: false });
|
27 | assert.equal(builder(), null);
|
28 | });
|
29 |
|
30 | it('Readme Builder builds a README for type', async () => {
|
31 | const schemas = await loadschemas('type');
|
32 | const builder = build({ readme: true });
|
33 | const result = builder(schemas);
|
34 |
|
35 | assertMarkdown(result)
|
36 | .contains('# README')
|
37 | .print();
|
38 | });
|
39 |
|
40 | it('Readme Builder builds a medium README for multiple Schemas', async () => {
|
41 | const schemas = await loadschemas('readme-1');
|
42 | const builder = build({ readme: true });
|
43 | const result = builder(schemas);
|
44 |
|
45 | assertMarkdown(result)
|
46 | .contains('# README')
|
47 | .contains('The schemas linked above')
|
48 | .fuzzy`
|
49 | ## Top-level Schemas
|
50 |
|
51 | * [Abstract](./abstract.md "This is an abstract schema") – ${null}
|
52 | * [Complex References](./complex.md "This is an example schema that uses types defined in other schemas") – ${null}
|
53 | * [Simple](./simple.md "This is a very simple example of a JSON schema") – ${null}
|
54 | `;
|
55 | });
|
56 |
|
57 | it('Readme Builder builds a small README for a single Schema', () => {
|
58 | const builder = build({ readme: true });
|
59 | const schemaloader = loader();
|
60 | const schemas = [
|
61 | schemaloader({
|
62 | type: 'object',
|
63 | title: 'Test Schema',
|
64 | description: 'Not much',
|
65 | properties: {
|
66 | foo: {
|
67 | const: 1,
|
68 | },
|
69 | obj: {
|
70 | type: 'object',
|
71 | title: 'An Object',
|
72 | },
|
73 | arr: {
|
74 | type: 'array',
|
75 | title: 'An Array',
|
76 | },
|
77 | },
|
78 | }, 'example.schema.json'),
|
79 | ];
|
80 |
|
81 | const result = builder(schemas);
|
82 |
|
83 | assertMarkdown(result)
|
84 | .contains('# README')
|
85 | .matches(/Top-level Schemas/)
|
86 | .has('heading > text')
|
87 | .equals('heading > text', {
|
88 | type: 'text',
|
89 | value: 'README',
|
90 | })
|
91 | .fuzzy`# README
|
92 |
|
93 | ## Top-level Schemas
|
94 |
|
95 | * [Test Schema](./example.md "Not much") – ${undefined}
|
96 |
|
97 | ## Other Schemas
|
98 |
|
99 | ### Objects
|
100 |
|
101 |
|
102 |
|
103 | ### Arrays`;
|
104 | });
|
105 | });
|