UNPKG

3.13 kBJavaScriptView Raw
1/*
2 * Copyright 2019 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12/* eslint-env mocha */
13/* eslint-disable no-unused-expressions */
14const assert = require('assert');
15const { assertMarkdown, loadschemas } = require('./testUtils');
16
17const build = require('../lib/readmeBuilder');
18const { loader } = require('../lib/schemaProxy');
19
20describe('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 // eslint-disable-next-line no-unused-expressions
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});