Skip to content

Commit

Permalink
fix(deps): coverage and constructor properties
Browse files Browse the repository at this point in the history
fix #259
  • Loading branch information
vogloblinsky committed Aug 10, 2017
1 parent bafc187 commit 0653fb2
Show file tree
Hide file tree
Showing 7 changed files with 517 additions and 451 deletions.
383 changes: 196 additions & 187 deletions dist/index-cli.js

Large diffs are not rendered by default.

383 changes: 196 additions & 187 deletions dist/index.js

Large diffs are not rendered by default.

139 changes: 72 additions & 67 deletions src/app/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ export class Application {

return new Promise((resolve, reject) => {
/*
* loop with components, classes, injectables, interfaces, pipes
* loop with components, directives, classes, injectables, interfaces, pipes
*/
var files = [],
totalProjectStatementDocumented = 0,
Expand All @@ -955,76 +955,81 @@ export class Application {
status = 'good';
}
return status;
};
},
processComponentsAndDirectives = function(list) {
_.forEach(list, (element) => {
if (!element.propertiesClass ||
!element.methodsClass ||
!element.inputsClass ||
!element.outputsClass) {
return;
}
let cl:any = {
filePath: element.file,
type: element.type,
linktype: element.type,
name: element.name
},
totalStatementDocumented = 0,
totalStatements = element.propertiesClass.length + element.methodsClass.length + element.inputsClass.length + element.outputsClass.length + 1; // +1 for element decorator comment

if (element.constructorObj) {
totalStatements += 1;
if (element.constructorObj && element.constructorObj.description && element.constructorObj.description !== '') {
totalStatementDocumented += 1;
}
}
if (element.description && element.description !== '') {
totalStatementDocumented += 1;
}

_.forEach(this.configuration.mainData.components, (component) => {
if (!component.propertiesClass ||
!component.methodsClass ||
!component.inputsClass ||
!component.outputsClass) {
return;
}
let cl:any = {
filePath: component.file,
type: component.type,
linktype: component.type,
name: component.name
},
totalStatementDocumented = 0,
totalStatements = component.propertiesClass.length + component.methodsClass.length + component.inputsClass.length + component.outputsClass.length + 1; // +1 for component decorator comment
_.forEach(element.propertiesClass, (property) => {
if (property.modifierKind === 111) { // Doesn't handle private for coverage
totalStatements -= 1;
}
if(property.description && property.description !== '' && property.modifierKind !== 111) {
totalStatementDocumented += 1;
}
});
_.forEach(element.methodsClass, (method) => {
if (method.modifierKind === 111) { // Doesn't handle private for coverage
totalStatements -= 1;
}
if(method.description && method.description !== '' && method.modifierKind !== 111) {
totalStatementDocumented += 1;
}
});
_.forEach(element.inputsClass, (input) => {
if (input.modifierKind === 111) { // Doesn't handle private for coverage
totalStatements -= 1;
}
if(input.description && input.description !== '' && input.modifierKind !== 111) {
totalStatementDocumented += 1;
}
});
_.forEach(element.outputsClass, (output) => {
if (output.modifierKind === 111) { // Doesn't handle private for coverage
totalStatements -= 1;
}
if(output.description && output.description !== '' && output.modifierKind !== 111) {
totalStatementDocumented += 1;
}
});

if (component.constructorObj) {
totalStatements += 1;
if (component.constructorObj && component.constructorObj.description && component.constructorObj.description !== '') {
totalStatementDocumented += 1;
}
}
if (component.description && component.description !== '') {
totalStatementDocumented += 1;
}
cl.coveragePercent = Math.floor((totalStatementDocumented / totalStatements) * 100);
if(totalStatements === 0) {
cl.coveragePercent = 0;
}
cl.coverageCount = totalStatementDocumented + '/' + totalStatements;
cl.status = getStatus(cl.coveragePercent);
totalProjectStatementDocumented += cl.coveragePercent;
files.push(cl);
})
};

_.forEach(component.propertiesClass, (property) => {
if (property.modifierKind === 111) { // Doesn't handle private for coverage
totalStatements -= 1;
}
if(property.description && property.description !== '' && property.modifierKind !== 111) {
totalStatementDocumented += 1;
}
});
_.forEach(component.methodsClass, (method) => {
if (method.modifierKind === 111) { // Doesn't handle private for coverage
totalStatements -= 1;
}
if(method.description && method.description !== '' && method.modifierKind !== 111) {
totalStatementDocumented += 1;
}
});
_.forEach(component.inputsClass, (input) => {
if (input.modifierKind === 111) { // Doesn't handle private for coverage
totalStatements -= 1;
}
if(input.description && input.description !== '' && input.modifierKind !== 111) {
totalStatementDocumented += 1;
}
});
_.forEach(component.outputsClass, (output) => {
if (output.modifierKind === 111) { // Doesn't handle private for coverage
totalStatements -= 1;
}
if(output.description && output.description !== '' && output.modifierKind !== 111) {
totalStatementDocumented += 1;
}
});
processComponentsAndDirectives(this.configuration.mainData.components);
processComponentsAndDirectives(this.configuration.mainData.directives);

cl.coveragePercent = Math.floor((totalStatementDocumented / totalStatements) * 100);
if(totalStatements === 0) {
cl.coveragePercent = 0;
}
cl.coverageCount = totalStatementDocumented + '/' + totalStatements;
cl.status = getStatus(cl.coveragePercent);
totalProjectStatementDocumented += cl.coveragePercent;
files.push(cl);
})
_.forEach(this.configuration.mainData.classes, (classe) => {
if (!classe.properties ||
!classe.methods) {
Expand Down
22 changes: 12 additions & 10 deletions src/app/compiler/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ export class Dependencies {
} else {
_return = kindToType(node.kind);
}
if (node.typeArguments) {
if (node.typeArguments && node.typeArguments.length > 0) {
_return += '<';
for (const argument of node.typeArguments) {
_return += kindToType(argument.kind);
Expand Down Expand Up @@ -1142,8 +1142,6 @@ export class Dependencies {
},
jsdoctags = JSDocTagsParser.getJSDocs(method),



if (method.symbol) {
result.description = marked(ts.displayPartsToString(method.symbol.getDocumentationComment()));
}
Expand All @@ -1161,15 +1159,15 @@ export class Dependencies {
return result;
}

private visitConstructorProperties(method) {
private visitConstructorProperties(constr, sourceFile) {
var that = this;
if (method.parameters) {
if (constr.parameters) {
var _parameters = [],
i = 0,
len = method.parameters.length;
len = constr.parameters.length;
for(i; i < len; i++) {
if (that.isPublic(method.parameters[i])) {
_parameters.push(that.visitArgument(method.parameters[i]));
if (that.isPublic(constr.parameters[i])) {
_parameters.push(that.visitProperty(constr.parameters[i], sourceFile));
}
}
return _parameters;
Expand Down Expand Up @@ -1327,7 +1325,11 @@ export class Dependencies {
description: '',
line: this.getPosition(property, sourceFile).line + 1
},
jsdoctags = JSDocTagsParser.getJSDocs(property);
jsdoctags;

if(property.jsDoc) {
jsdoctags = JSDocTagsParser.getJSDocs(property);
}

if (property.symbol) {
result.description = marked(ts.displayPartsToString(property.symbol.getDocumentationComment()));
Expand Down Expand Up @@ -1389,7 +1391,7 @@ export class Dependencies {
} else if (members[i].kind === ts.SyntaxKind.IndexSignature) {
indexSignatures.push(this.visitIndexDeclaration(members[i], sourceFile));
} else if (members[i].kind === ts.SyntaxKind.Constructor) {
let _constructorProperties = this.visitConstructorProperties(members[i]),
let _constructorProperties = this.visitConstructorProperties(members[i], sourceFile),
j = 0,
len = _constructorProperties.length;
for(j; j<len; j++) {
Expand Down
4 changes: 4 additions & 0 deletions src/app/engines/html.engine.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { prefixOfficialDoc } from '../../utils/angular-version';
import { jsdocTagInterface } from '../interfaces/jsdoc-tag.interface';

import { finderInBasicTypes, finderInTypeScriptBasicTypes } from '../../utils/basic-types';
import { kindToType } from '../../utils/kind-to-type';

export let HtmlEngineHelpers = (function() {
let init = function() {
Expand Down Expand Up @@ -433,6 +434,9 @@ export let HtmlEngineHelpers = (function() {
if (jsdocTags[i].typeExpression && jsdocTags[i].typeExpression.type.name) {
tag.type = jsdocTags[i].typeExpression.type.name.text
}
if (jsdocTags[i].typeExpression && jsdocTags[i].typeExpression.type.kind) {
tag.type = kindToType(jsdocTags[i].typeExpression.type.kind);
}
if (jsdocTags[i].comment) {
tag.comment = jsdocTags[i].comment
}
Expand Down
29 changes: 29 additions & 0 deletions test/src/cli/cli-coverage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,33 @@ describe('CLI coverage report', () => {

});

describe('coverage page', () => {

let stdoutString = null,
coverageFile;
before(function (done) {
tmp.create();
let ls = shell('node', [
'../bin/index-cli.js',
'-p', '../test/src/sample-files/tsconfig.simple.json',
'-d', '../' + tmp.name + '/'], { cwd: tmp.name, env });

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
stdoutString = ls.stdout.toString();
coverageFile = read(`${tmp.name}/coverage.html`);
done();
});
after(() => tmp.clean());

it('it should have coverage page', () => {
expect(coverageFile).to.contain('Documentation coverage');
expect(coverageFile).to.contain('img src="./images/coverage-badge.svg"');
expect(coverageFile).to.contain('5/5');
});

});

});
8 changes: 8 additions & 0 deletions test/src/sample-files/foo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ export class FooComponent {
*/
@Output() exampleOutput: EventEmitter<{foo: string}> = new EventEmitter();

/**
* constructor description
* @param {boolean} myprop description
*/
constructor(public myprop: boolean) {

}

}

0 comments on commit 0653fb2

Please sign in to comment.