1+ import { expect } from 'chai' ;
2+ import { temporaryDir , shell , exists , read } from '../helpers' ;
3+ import * as fs from 'fs' ;
4+ import * as path from 'path' ;
5+
6+ const tmp = temporaryDir ( ) ;
7+
8+ describe ( 'CLI Markdown files generation' , ( ) => {
9+ const distFolder = tmp . name + '-markdown-files' ;
10+ const fixtureFolder = tmp . name + '-markdown-fixture' ;
11+
12+ describe ( 'when CHANGELOG, CONTRIBUTING, and LICENSE markdown files exist' , ( ) => {
13+ let stdoutString = undefined ;
14+ let menuFile ;
15+
16+ before ( function ( done ) {
17+ // Create fixture folder with markdown files
18+ tmp . create ( fixtureFolder ) ;
19+ tmp . create ( distFolder ) ;
20+
21+ // Copy sample files for basic Angular app
22+ const srcFolder = path . join ( fixtureFolder , 'src' ) ;
23+ fs . mkdirSync ( srcFolder , { recursive : true } ) ;
24+
25+ // Copy source file
26+ fs . copyFileSync (
27+ './test/fixtures/sample-files/app.module.ts' ,
28+ path . join ( srcFolder , 'app.module.ts' )
29+ ) ;
30+
31+ // Create a proper tsconfig.json
32+ const tsconfigContent = {
33+ "compilerOptions" : {
34+ "target" : "es5" ,
35+ "module" : "commonjs" ,
36+ "moduleResolution" : "node" ,
37+ "emitDecoratorMetadata" : true ,
38+ "experimentalDecorators" : true ,
39+ "sourceMap" : true ,
40+ "lib" : [ "es2015" , "dom" ]
41+ } ,
42+ "include" : [
43+ "src/**/*.ts"
44+ ] ,
45+ "exclude" : [
46+ "node_modules"
47+ ]
48+ } ;
49+ fs . writeFileSync (
50+ path . join ( fixtureFolder , 'tsconfig.json' ) ,
51+ JSON . stringify ( tsconfigContent , null , 2 )
52+ ) ;
53+
54+ const ls = shell ( 'node' , [
55+ './bin/index-cli.js' ,
56+ '-p' ,
57+ path . join ( fixtureFolder , 'tsconfig.json' ) ,
58+ '-d' ,
59+ distFolder
60+ ] ) ;
61+
62+ if ( ls . stderr . toString ( ) !== '' ) {
63+ console . error ( `shell error: ${ ls . stderr . toString ( ) } ` ) ;
64+ done ( 'error' ) ;
65+ }
66+ stdoutString = ls . stdout . toString ( ) ;
67+ menuFile = read ( `${ distFolder } /js/menu-wc.js` ) ;
68+ done ( ) ;
69+ } ) ;
70+
71+ after ( ( ) => {
72+ tmp . clean ( distFolder ) ;
73+ tmp . clean ( fixtureFolder ) ;
74+ } ) ;
75+
76+ it ( 'should display generated message' , ( ) => {
77+ expect ( stdoutString ) . to . contain ( 'Documentation generated' ) ;
78+ } ) ;
79+
80+ it ( 'should find and process CHANGELOG.md file' , ( ) => {
81+ expect ( stdoutString ) . to . contain ( 'CHANGELOG.md file found' ) ;
82+ } ) ;
83+
84+ it ( 'should find and process CONTRIBUTING.md file' , ( ) => {
85+ expect ( stdoutString ) . to . contain ( 'CONTRIBUTING.md file found' ) ;
86+ } ) ;
87+
88+ it ( 'should find and process LICENSE.md file' , ( ) => {
89+ expect ( stdoutString ) . to . contain ( 'LICENSE.md file found' ) ;
90+ } ) ;
91+
92+ it ( 'should generate changelog.html page' , ( ) => {
93+ const changelogExists = exists ( `${ distFolder } /changelog.html` ) ;
94+ expect ( changelogExists ) . to . be . true ;
95+ const changelogContent = read ( `${ distFolder } /changelog.html` ) ;
96+ // Note: reads from project root CHANGELOG.md, not fixture
97+ expect ( changelogContent ) . to . contain ( 'changelog' ) ;
98+ } ) ;
99+
100+ it ( 'should generate contributing.html page' , ( ) => {
101+ const contributingExists = exists ( `${ distFolder } /contributing.html` ) ;
102+ expect ( contributingExists ) . to . be . true ;
103+ const contributingContent = read ( `${ distFolder } /contributing.html` ) ;
104+ expect ( contributingContent ) . to . contain ( 'Contributing' ) ;
105+ } ) ;
106+
107+ it ( 'should generate license.html page' , ( ) => {
108+ const licenseExists = exists ( `${ distFolder } /license.html` ) ;
109+ expect ( licenseExists ) . to . be . true ;
110+ const licenseContent = read ( `${ distFolder } /license.html` ) ;
111+ expect ( licenseContent ) . to . contain ( 'License' ) ;
112+ } ) ;
113+
114+ it ( 'should include CHANGELOG link in menu' , ( ) => {
115+ expect ( menuFile ) . to . contain ( 'changelog.html' ) ;
116+ expect ( menuFile ) . to . contain ( 'CHANGELOG' ) ;
117+ } ) ;
118+
119+ it ( 'should include CONTRIBUTING link in menu' , ( ) => {
120+ expect ( menuFile ) . to . contain ( 'contributing.html' ) ;
121+ expect ( menuFile ) . to . contain ( 'CONTRIBUTING' ) ;
122+ } ) ;
123+
124+ it ( 'should include LICENSE link in menu' , ( ) => {
125+ expect ( menuFile ) . to . contain ( 'license.html' ) ;
126+ expect ( menuFile ) . to . contain ( 'LICENSE' ) ;
127+ } ) ;
128+ } ) ;
129+
130+ describe ( 'regression test for markdown menu entries' , ( ) => {
131+ let menuFile ;
132+
133+ before ( function ( done ) {
134+ tmp . create ( distFolder + '-regression' ) ;
135+
136+ // Run compodoc - it will find project's markdown files from root
137+ const ls = shell ( 'node' , [
138+ './bin/index-cli.js' ,
139+ '-p' ,
140+ './test/fixtures/sample-files/tsconfig.simple.json' ,
141+ '-d' ,
142+ distFolder + '-regression'
143+ ] ) ;
144+
145+ if ( ls . stderr . toString ( ) !== '' ) {
146+ console . error ( `shell error: ${ ls . stderr . toString ( ) } ` ) ;
147+ done ( 'error' ) ;
148+ }
149+ menuFile = read ( `${ distFolder } -regression/js/menu-wc.js` ) ;
150+ done ( ) ;
151+ } ) ;
152+
153+ after ( ( ) => tmp . clean ( distFolder + '-regression' ) ) ;
154+
155+ it ( 'should populate markdowns array when markdown files are found' , ( ) => {
156+ // REGRESSION TEST: This verifies that Configuration.mainData.markdowns.push()
157+ // is properly called for each markdown file (lines 367-372 in application.ts)
158+ // The bug was that this code was removed, causing markdown files to not
159+ // appear in the navigation menu. This test ensures they are present.
160+ expect ( menuFile ) . to . contain ( 'changelog.html' ) ;
161+ expect ( menuFile ) . to . contain ( 'contributing.html' ) ;
162+ expect ( menuFile ) . to . contain ( 'license.html' ) ;
163+ } ) ;
164+ } ) ;
165+ } ) ;
0 commit comments