@@ -2,7 +2,12 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
22import fs from 'node:fs' ;
33import path from 'node:path' ;
44import { DocsParser } from '../src/DocsParser.js' ;
5- import type { ModuleDocumentationContainer } from '../src/ParsedDocumentation.js' ;
5+ import type {
6+ ModuleDocumentationContainer ,
7+ ClassDocumentationContainer ,
8+ ElementDocumentationContainer ,
9+ StructureDocumentationContainer ,
10+ } from '../src/ParsedDocumentation.js' ;
611
712describe ( 'DocsParser' , ( ) => {
813 let tempDir : string ;
@@ -71,16 +76,15 @@ A \`string\` property that indicates the current application's name.
7176 expect ( ( appModule as ModuleDocumentationContainer ) . process . main ) . toBe ( true ) ;
7277 expect ( appModule ?. description ) . toContain ( 'Control your application' ) ;
7378
74- if ( appModule && appModule . type === 'Module' ) {
75- expect ( appModule . events ) . toHaveLength ( 1 ) ;
76- expect ( appModule . events [ 0 ] . name ) . toBe ( 'ready' ) ;
79+ const module = appModule as ModuleDocumentationContainer ;
80+ expect ( module . events ) . toHaveLength ( 1 ) ;
81+ expect ( module . events [ 0 ] . name ) . toBe ( 'ready' ) ;
7782
78- expect ( appModule . methods ) . toHaveLength ( 1 ) ;
79- expect ( appModule . methods [ 0 ] . name ) . toBe ( 'quit' ) ;
83+ expect ( module . methods ) . toHaveLength ( 1 ) ;
84+ expect ( module . methods [ 0 ] . name ) . toBe ( 'quit' ) ;
8085
81- expect ( appModule . properties ) . toHaveLength ( 1 ) ;
82- expect ( appModule . properties [ 0 ] . name ) . toBe ( 'name' ) ;
83- }
86+ expect ( module . properties ) . toHaveLength ( 1 ) ;
87+ expect ( module . properties [ 0 ] . name ) . toBe ( 'name' ) ;
8488 } ) ;
8589
8690 it ( 'should parse a class documentation' , async ( ) => {
@@ -133,20 +137,19 @@ Emitted when the window is closed.
133137 expect ( browserWindowClass ) . toBeDefined ( ) ;
134138 expect ( browserWindowClass ?. type ) . toBe ( 'Class' ) ;
135139
136- if ( browserWindowClass && browserWindowClass . type === 'Class' ) {
137- expect ( browserWindowClass . constructorMethod ) . toBeDefined ( ) ;
138- expect ( browserWindowClass . constructorMethod ? .parameters ) . toHaveLength ( 1 ) ;
140+ const cls = browserWindowClass as ClassDocumentationContainer ;
141+ expect ( cls . constructorMethod ) . toBeDefined ( ) ;
142+ expect ( cls . constructorMethod ! . parameters ) . toHaveLength ( 1 ) ;
139143
140- expect ( browserWindowClass . instanceMethods ) . toHaveLength ( 2 ) ;
141- expect ( browserWindowClass . instanceMethods [ 0 ] . name ) . toBe ( 'close' ) ;
142- expect ( browserWindowClass . instanceMethods [ 1 ] . name ) . toBe ( 'show' ) ;
144+ expect ( cls . instanceMethods ) . toHaveLength ( 2 ) ;
145+ expect ( cls . instanceMethods [ 0 ] . name ) . toBe ( 'close' ) ;
146+ expect ( cls . instanceMethods [ 1 ] . name ) . toBe ( 'show' ) ;
143147
144- expect ( browserWindowClass . instanceProperties ) . toHaveLength ( 1 ) ;
145- expect ( browserWindowClass . instanceProperties [ 0 ] . name ) . toBe ( 'id' ) ;
148+ expect ( cls . instanceProperties ) . toHaveLength ( 1 ) ;
149+ expect ( cls . instanceProperties [ 0 ] . name ) . toBe ( 'id' ) ;
146150
147- expect ( browserWindowClass . instanceEvents ) . toHaveLength ( 1 ) ;
148- expect ( browserWindowClass . instanceEvents [ 0 ] . name ) . toBe ( 'closed' ) ;
149- }
151+ expect ( cls . instanceEvents ) . toHaveLength ( 1 ) ;
152+ expect ( cls . instanceEvents [ 0 ] . name ) . toBe ( 'closed' ) ;
150153 } ) ;
151154
152155 it ( 'should parse a class with static methods and properties' , async ( ) => {
@@ -190,14 +193,13 @@ Pops up this menu.
190193 const menuClass = result . find ( ( c ) => c . name === 'Menu' ) ;
191194 expect ( menuClass ) . toBeDefined ( ) ;
192195
193- if ( menuClass && menuClass . type === 'Class' ) {
194- expect ( menuClass . staticMethods ) . toHaveLength ( 1 ) ;
195- expect ( menuClass . staticMethods [ 0 ] . name ) . toBe ( 'buildFromTemplate' ) ;
196- expect ( menuClass . staticMethods [ 0 ] . returns ) . toBeDefined ( ) ;
196+ const cls = menuClass as ClassDocumentationContainer ;
197+ expect ( cls . staticMethods ) . toHaveLength ( 1 ) ;
198+ expect ( cls . staticMethods [ 0 ] . name ) . toBe ( 'buildFromTemplate' ) ;
199+ expect ( cls . staticMethods [ 0 ] . returns ) . toBeDefined ( ) ;
197200
198- expect ( menuClass . staticProperties ) . toHaveLength ( 1 ) ;
199- expect ( menuClass . staticProperties [ 0 ] . name ) . toBe ( 'applicationMenu' ) ;
200- }
201+ expect ( cls . staticProperties ) . toHaveLength ( 1 ) ;
202+ expect ( cls . staticProperties [ 0 ] . name ) . toBe ( 'applicationMenu' ) ;
201203 } ) ;
202204
203205 it ( 'should handle module with exported class in multi-package mode' , async ( ) => {
@@ -275,16 +277,15 @@ Fired when the navigation is done.
275277 expect ( webviewElement ?. type ) . toBe ( 'Element' ) ;
276278 expect ( webviewElement ?. extends ) . toBe ( 'HTMLElement' ) ;
277279
278- if ( webviewElement && webviewElement . type === 'Element' ) {
279- expect ( webviewElement . methods ) . toHaveLength ( 1 ) ;
280- expect ( webviewElement . methods [ 0 ] . name ) . toBe ( 'loadURL' ) ;
280+ const element = webviewElement as ElementDocumentationContainer ;
281+ expect ( element . methods ) . toHaveLength ( 1 ) ;
282+ expect ( element . methods [ 0 ] . name ) . toBe ( 'loadURL' ) ;
281283
282- expect ( webviewElement . properties ) . toHaveLength ( 1 ) ;
283- expect ( webviewElement . properties [ 0 ] . name ) . toBe ( 'src' ) ;
284+ expect ( element . properties ) . toHaveLength ( 1 ) ;
285+ expect ( element . properties [ 0 ] . name ) . toBe ( 'src' ) ;
284286
285- expect ( webviewElement . events ) . toHaveLength ( 1 ) ;
286- expect ( webviewElement . events [ 0 ] . name ) . toBe ( 'did-finish-load' ) ;
287- }
287+ expect ( element . events ) . toHaveLength ( 1 ) ;
288+ expect ( element . events [ 0 ] . name ) . toBe ( 'did-finish-load' ) ;
288289 } ) ;
289290
290291 it ( 'should handle process tags correctly' , async ( ) => {
@@ -356,14 +357,13 @@ Additional description after the property list.
356357 expect ( rectangleStructure ) . toBeDefined ( ) ;
357358 expect ( rectangleStructure ?. type ) . toBe ( 'Structure' ) ;
358359
359- if ( rectangleStructure && rectangleStructure . type === 'Structure' ) {
360- expect ( rectangleStructure . properties ) . toHaveLength ( 4 ) ;
361- expect ( rectangleStructure . properties [ 0 ] . name ) . toBe ( 'x' ) ;
362- expect ( rectangleStructure . properties [ 0 ] . type ) . toBe ( 'Integer' ) ;
363- expect ( rectangleStructure . properties [ 1 ] . name ) . toBe ( 'y' ) ;
364- expect ( rectangleStructure . properties [ 2 ] . name ) . toBe ( 'width' ) ;
365- expect ( rectangleStructure . properties [ 3 ] . name ) . toBe ( 'height' ) ;
366- }
360+ const struct = rectangleStructure as StructureDocumentationContainer ;
361+ expect ( struct . properties ) . toHaveLength ( 4 ) ;
362+ expect ( struct . properties [ 0 ] . name ) . toBe ( 'x' ) ;
363+ expect ( struct . properties [ 0 ] . type ) . toBe ( 'Integer' ) ;
364+ expect ( struct . properties [ 1 ] . name ) . toBe ( 'y' ) ;
365+ expect ( struct . properties [ 2 ] . name ) . toBe ( 'width' ) ;
366+ expect ( struct . properties [ 3 ] . name ) . toBe ( 'height' ) ;
367367 } ) ;
368368
369369 it ( 'should parse a structure with optional properties' , async ( ) => {
@@ -380,13 +380,11 @@ Additional description after the property list.
380380 const parser = new DocsParser ( tempDir , '1.0.0' , [ ] , [ structurePath ] , 'single' ) ;
381381 const result = await parser . parse ( ) ;
382382
383- const optionsStructure = result . find ( ( s ) => s . name === 'Options' ) ;
383+ const optionsStructure = result . find ( ( s ) => s . name === 'Options' ) as StructureDocumentationContainer ;
384384
385- if ( optionsStructure && optionsStructure . type === 'Structure' ) {
386- expect ( optionsStructure . properties [ 0 ] . required ) . toBe ( false ) ;
387- expect ( optionsStructure . properties [ 1 ] . required ) . toBe ( false ) ;
388- expect ( optionsStructure . properties [ 2 ] . required ) . toBe ( true ) ;
389- }
385+ expect ( optionsStructure . properties [ 0 ] . required ) . toBe ( false ) ;
386+ expect ( optionsStructure . properties [ 1 ] . required ) . toBe ( false ) ;
387+ expect ( optionsStructure . properties [ 2 ] . required ) . toBe ( true ) ;
390388 } ) ;
391389
392390 it ( 'should handle structure with extends clause' , async ( ) => {
0 commit comments