1- import { generateDocs } from '../index' ;
1+ import { extract , organise } from '../index' ;
22
33describe ( 'index' , ( ) => {
44 const noTags = `
@@ -17,7 +17,7 @@ describe('index', () => {
1717 }
1818 ` ;
1919
20- describe ( 'single comment ' , ( ) => {
20+ describe ( 'extract() ' , ( ) => {
2121 it ( 'returns empty array if the section name is not defined' , ( ) => {
2222 const code = `
2323 /**
@@ -33,10 +33,10 @@ describe('index', () => {
3333 background-color: blue;
3434 }
3535 ` ;
36- expect ( generateDocs ( code ) ) . toEqual ( [ ] ) ;
36+ expect ( extract ( code ) ) . toEqual ( [ ] ) ;
3737 } ) ;
3838
39- it ( 'returns the section data ' , ( ) => {
39+ it ( 'returns the extracted comment ' , ( ) => {
4040 const code = `
4141 /**
4242 * @name Button
@@ -69,14 +69,14 @@ describe('index', () => {
6969 }
7070 ] ,
7171 markup : '<div class="{{modifier}}">Button</div>' ,
72- subsections : [ ]
72+ section : null
7373 }
7474 ] ;
7575
76- expect ( generateDocs ( code ) ) . toEqual ( expected ) ;
76+ expect ( extract ( code ) ) . toEqual ( expected ) ;
7777 } ) ;
7878
79- it ( 'returns the section data without description' , ( ) => {
79+ it ( 'returns the comment without description' , ( ) => {
8080 const code = `
8181 /**
8282 * @name Button
@@ -108,14 +108,14 @@ describe('index', () => {
108108 }
109109 ] ,
110110 markup : '<div class="{{modifier}}">Button</div>' ,
111- subsections : [ ]
111+ section : null
112112 }
113113 ] ;
114114
115- expect ( generateDocs ( code ) ) . toEqual ( expected ) ;
115+ expect ( extract ( code ) ) . toEqual ( expected ) ;
116116 } ) ;
117117
118- it ( 'returns the section data without class descriptions' , ( ) => {
118+ it ( 'returns the comment without class descriptions' , ( ) => {
119119 const code = `
120120 /**
121121 * @name Button
@@ -148,14 +148,14 @@ describe('index', () => {
148148 }
149149 ] ,
150150 markup : '<div class="{{modifier}}">Button</div>' ,
151- subsections : [ ]
151+ section : null
152152 }
153153 ] ;
154154
155- expect ( generateDocs ( code ) ) . toEqual ( expected ) ;
155+ expect ( extract ( code ) ) . toEqual ( expected ) ;
156156 } ) ;
157157
158- it ( 'returns the section data without classes' , ( ) => {
158+ it ( 'returns the comment without classes' , ( ) => {
159159 const code = `
160160 /**
161161 * @name Button
@@ -174,14 +174,14 @@ describe('index', () => {
174174 description : 'Button component.' ,
175175 classes : [ ] ,
176176 markup : '<div class="{{modifier}}">Button</div>' ,
177- subsections : [ ]
177+ section : null
178178 }
179179 ] ;
180180
181- expect ( generateDocs ( code ) ) . toEqual ( expected ) ;
181+ expect ( extract ( code ) ) . toEqual ( expected ) ;
182182 } ) ;
183183
184- it ( 'returns the section data without markup' , ( ) => {
184+ it ( 'returns the comment without markup' , ( ) => {
185185 const code = `
186186 /**
187187 * @name Button
@@ -211,34 +211,16 @@ describe('index', () => {
211211 }
212212 ] ,
213213 markup : null ,
214- subsections : [ ]
214+ section : null
215215 }
216216 ] ;
217217
218- expect ( generateDocs ( code ) ) . toEqual ( expected ) ;
219- } ) ;
220-
221- it ( 'throws when the section does not exist' , ( ) => {
222- const code = `
223- /**
224- * @name Button
225- *
226- * @class .btn Button class.
227- * @class .btn--primary Primary button class.
228- *
229- * @markup
230- * <div class="{{modifier}}">Button</div>
231- *
232- * @section Not a valid section.
233- */
234- ` ;
235-
236- expect ( ( ) => generateDocs ( code ) ) . toThrowError ( 'Section "Not a valid section." does not exist' ) ;
218+ expect ( extract ( code ) ) . toEqual ( expected ) ;
237219 } ) ;
238220 } ) ;
239221
240- describe ( 'multiple comments ' , ( ) => {
241- it ( 'builds the section hierarchy tree ' , ( ) => {
222+ describe ( 'organise() ' , ( ) => {
223+ it ( 'builds the subsections ' , ( ) => {
242224 const code = `
243225 /**
244226 * @name Root section.
@@ -265,79 +247,71 @@ describe('index', () => {
265247 * @name Another root section.
266248 */
267249 ` ;
268- const expected = [
269- {
270- name : 'Root section.' ,
271- description : null ,
272- classes : [ ] ,
273- markup : null ,
274- subsections : [
275- {
276- name : 'Foo' ,
277- description : null ,
278- classes : [ ] ,
279- markup : null ,
280- subsections : [
281- {
282- name : 'Bar' ,
283- description : 'Bar component.' ,
284- classes : [
285- {
286- name : '.bar' ,
287- description : 'Bar.' ,
288- markup : '<div class="bar">Bar</div>'
289- }
290- ] ,
291- markup : '<div class="{{modifier}}">Bar</div>' ,
292- subsections : [ ]
293- }
294- ]
295- }
296- ]
297- } ,
298- {
299- name : 'Another root section.' ,
300- description : null ,
301- classes : [ ] ,
302- markup : null ,
303- subsections : [ ]
304- }
305- ] ;
306- expect ( generateDocs ( code ) ) . toEqual ( expected ) ;
250+ const expected = {
251+ roots : [ 'Root section.' , 'Another root section.' ] ,
252+ sections : [
253+ {
254+ name : 'Root section.' ,
255+ description : null ,
256+ classes : [ ] ,
257+ markup : null ,
258+ subsections : [ 'Foo' ]
259+ } ,
260+ {
261+ name : 'Foo' ,
262+ description : null ,
263+ classes : [ ] ,
264+ markup : null ,
265+ subsections : [ 'Bar' ]
266+ } ,
267+ {
268+ name : 'Bar' ,
269+ description : 'Bar component.' ,
270+ classes : [
271+ {
272+ name : '.bar' ,
273+ description : 'Bar.' ,
274+ markup : '<div class="bar">Bar</div>'
275+ }
276+ ] ,
277+ markup : '<div class="{{modifier}}">Bar</div>' ,
278+ subsections : [ ]
279+ } ,
280+ {
281+ name : 'Another root section.' ,
282+ description : null ,
283+ classes : [ ] ,
284+ markup : null ,
285+ subsections : [ ]
286+ }
287+ ]
288+ } ;
289+ expect ( organise ( extract ( code ) ) ) . toEqual ( expected ) ;
307290 } ) ;
308- } ) ;
309291
310- it ( 'returns an empty array when no docs' , ( ) => {
311- expect ( generateDocs ( noTags ) ) . toEqual ( [ ] ) ;
312- } ) ;
313-
314- it ( 'returns the root sections' , ( ) => {
315- const code = `
316- /**
317- * @name Some section.
318- */
292+ it ( 'returns an empty array when no docs' , ( ) => {
293+ expect ( organise ( extract ( noTags ) ) ) . toEqual ( {
294+ roots : [ ] ,
295+ sections : [ ]
296+ } ) ;
297+ } ) ;
319298
320- /**
321- * @name Other section.
322- */
323- ` ;
324- const expected = [
325- {
326- name : 'Some section.' ,
327- description : null ,
328- classes : [ ] ,
329- markup : null ,
330- subsections : [ ]
331- } ,
332- {
333- name : 'Other section.' ,
334- description : null ,
335- classes : [ ] ,
336- markup : null ,
337- subsections : [ ]
338- }
339- ] ;
299+ it ( 'throws when the section does not exist' , ( ) => {
300+ const code = `
301+ /**
302+ * @name Button
303+ *
304+ * @class .btn Button class.
305+ * @class .btn--primary Primary button class.
306+ *
307+ * @markup
308+ * <div class="{{modifier}}">Button</div>
309+ *
310+ * @section Not a valid section.
311+ */
312+ ` ;
340313
341- expect ( generateDocs ( code ) ) . toEqual ( expected ) ;
314+ expect ( ( ) => organise ( extract ( code ) ) ) . toThrowError ( 'Section "Not a valid section." does not exist' ) ;
315+ } ) ;
342316 } ) ;
343317} ) ;
0 commit comments