Skip to content

Commit 2501b4f

Browse files
author
tomas_backbase
committed
Fix #1663
1 parent 09f772e commit 2501b4f

File tree

4 files changed

+215
-107
lines changed

4 files changed

+215
-107
lines changed

src/app/application.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ export class Application {
364364
depth: 0,
365365
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
366366
});
367+
Configuration.mainData.markdowns.push({
368+
name: markdowns[i],
369+
uppername: markdowns[i].toUpperCase(),
370+
depth: 0,
371+
pageType: COMPODOC_DEFAULTS.PAGE_TYPES.ROOT
372+
});
367373
}
368374
i++;
369375
loop();

src/app/compiler/angular/deps/helpers/symbol-helper.spec.ts

Lines changed: 0 additions & 107 deletions
This file was deleted.

test/src/app/compiler/angular/deps/helpers/symbol.helper.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,48 @@ describe(SymbolHelper.name, () => {
6565
expect(result).to.equal('TestProvider');
6666
});
6767
});
68+
69+
describe('buildIdentifierName', () => {
70+
it('should handle RouterModule.forRoot', () => {
71+
sourceFile = project.createSourceFile(sourceFileName, `const router = RouterModule.forRoot;`);
72+
73+
const variableDeclaration = sourceFile.getVariableDeclaration("router")!;
74+
const propertyAccess = variableDeclaration.getInitializer()!.compilerNode as ts.PropertyAccessExpression;
75+
const result = helper.buildIdentifierName(propertyAccess, '');
76+
77+
expect(result).to.equal('RouterModule.forRoot');
78+
});
79+
});
80+
81+
describe('parseSymbolElements', () => {
82+
it('should handle CallExpression and remove args', () => {
83+
sourceFile = project.createSourceFile(sourceFileName, `const router = RouterModule.forRoot('arg1');`);
84+
85+
const variableDeclaration = sourceFile.getVariableDeclaration("router")!;
86+
const callExp = variableDeclaration.getInitializer()!.compilerNode as ts.CallExpression;
87+
const result = helper.parseSymbolElements(callExp);
88+
89+
expect(result).to.equal('RouterModule.forRoot(args)');
90+
});
91+
92+
it('should handle sub-Module', () => {
93+
sourceFile = project.createSourceFile(sourceFileName, `const sharedModule = Shared.Module;`);
94+
95+
const variableDeclaration = sourceFile.getVariableDeclaration("sharedModule")!;
96+
const propertyAccess = variableDeclaration.getInitializer()!.compilerNode as ts.PropertyAccessExpression;
97+
const result = helper.parseSymbolElements(propertyAccess);
98+
99+
expect(result).to.equal('Shared.Module');
100+
});
101+
102+
it('should handle string literal', () => {
103+
sourceFile = project.createSourceFile(sourceFileName, `const cssPath = "./app.component.css";`);
104+
105+
const variableDeclaration = sourceFile.getVariableDeclaration("cssPath")!;
106+
const stringLiteral = variableDeclaration.getInitializer()!.compilerNode as ts.StringLiteral;
107+
const result = helper.parseSymbolElements(stringLiteral);
108+
109+
expect(result).to.equal('./app.component.css');
110+
});
111+
});
68112
});
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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

Comments
 (0)