Skip to content

Commit

Permalink
fix(app): use normalized paths in unit test coverage
Browse files Browse the repository at this point in the history
fix #664
  • Loading branch information
vogloblinsky committed Jul 19, 2021
1 parent 5125ef3 commit 43bbc3b
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/app/application.ts
Expand Up @@ -2237,7 +2237,7 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
} else {
covDat = {};
covFileNames = _.map(coverageData.files, el => {
let fileName = el.filePath;
let fileName = path.normalize(el.filePath);
covDat[fileName] = {
type: el.type,
linktype: el.linktype,
Expand Down Expand Up @@ -2277,8 +2277,9 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
// need a name to include in output but this isn't visible
out = { name: fileName, filePath: fileName };
} else {
let findMatch = _.filter(covFileNames, el => {
return el.includes(fileName) || fileName.includes(el);
const findMatch = _.filter(covFileNames, el => {
const normalizedFilename = path.normalize(fileName);
return el.includes(fileName) || normalizedFilename.includes(el);
});
if (findMatch.length > 0) {
out = _.clone(covDat[findMatch[0]]);
Expand Down
146 changes: 146 additions & 0 deletions test/fixtures/todomvc-ng2/coverage-summary-win.json
@@ -0,0 +1,146 @@
{
"total": {
"lines": { "total": 293, "covered": 217, "skipped": 0, "pct": 74.06 },
"statements": { "total": 336, "covered": 256, "skipped": 0, "pct": 76.19 },
"functions": { "total": 104, "covered": 40, "skipped": 0, "pct": 38.46 },
"branches": { "total": 17, "covered": 8, "skipped": 0, "pct": 47.06 }
},
"src\\polyfills.ts": {
"lines": { "total": 16, "covered": 16, "skipped": 0, "pct": 100 },
"functions": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 },
"statements": { "total": 16, "covered": 16, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\test.ts": {
"lines": { "total": 6, "covered": 6, "skipped": 0, "pct": 100 },
"functions": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 },
"statements": { "total": 6, "covered": 6, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\app.component.ts": {
"lines": { "total": 7, "covered": 5, "skipped": 0, "pct": 71.43 },
"functions": { "total": 3, "covered": 1, "skipped": 0, "pct": 33.33 },
"statements": { "total": 9, "covered": 7, "skipped": 0, "pct": 77.78 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\about\\about.component.ts": {
"lines": { "total": 21, "covered": 14, "skipped": 0, "pct": 66.67 },
"functions": { "total": 10, "covered": 1, "skipped": 0, "pct": 10 },
"statements": { "total": 23, "covered": 16, "skipped": 0, "pct": 69.57 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\about\\compodoc\\compodoc.component.ts": {
"lines": { "total": 3, "covered": 3, "skipped": 0, "pct": 100 },
"functions": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 },
"statements": { "total": 5, "covered": 5, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\about\\todomvc\\todomvc.component.ts": {
"lines": { "total": 3, "covered": 3, "skipped": 0, "pct": 100 },
"functions": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 },
"statements": { "total": 5, "covered": 5, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\footer\\footer.component.ts": {
"lines": { "total": 20, "covered": 13, "skipped": 0, "pct": 65 },
"functions": { "total": 6, "covered": 2, "skipped": 0, "pct": 33.33 },
"statements": { "total": 22, "covered": 15, "skipped": 0, "pct": 68.18 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\header\\header.component.ts": {
"lines": { "total": 15, "covered": 10, "skipped": 0, "pct": 66.67 },
"functions": { "total": 5, "covered": 2, "skipped": 0, "pct": 40 },
"statements": { "total": 17, "covered": 12, "skipped": 0, "pct": 70.59 },
"branches": { "total": 2, "covered": 0, "skipped": 0, "pct": 0 }
},
"src\\app\\home\\home.component.ts": {
"lines": { "total": 9, "covered": 9, "skipped": 0, "pct": 100 },
"functions": { "total": 2, "covered": 1, "skipped": 0, "pct": 50 },
"statements": { "total": 11, "covered": 11, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\list\\list.component.ts": {
"lines": { "total": 21, "covered": 13, "skipped": 0, "pct": 61.9 },
"functions": { "total": 4, "covered": 3, "skipped": 0, "pct": 75 },
"statements": { "total": 23, "covered": 15, "skipped": 0, "pct": 65.22 },
"branches": { "total": 3, "covered": 0, "skipped": 0, "pct": 0 }
},
"src\\app\\list\\list.module.ts": {
"lines": { "total": 6, "covered": 6, "skipped": 0, "pct": 100 },
"functions": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 },
"statements": { "total": 9, "covered": 9, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\list\\todo\\index.ts": {
"lines": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 },
"functions": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 },
"statements": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\list\\todo\\todo.component.ts": {
"lines": { "total": 26, "covered": 13, "skipped": 0, "pct": 50 },
"functions": { "total": 9, "covered": 1, "skipped": 0, "pct": 11.11 },
"statements": { "total": 28, "covered": 15, "skipped": 0, "pct": 53.57 },
"branches": { "total": 2, "covered": 0, "skipped": 0, "pct": 0 }
},
"src\\app\\list\\todo\\todo.module.ts": {
"lines": { "total": 7, "covered": 7, "skipped": 0, "pct": 100 },
"functions": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 },
"statements": { "total": 10, "covered": 10, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\shared\\decorators\\log.decorator.ts": {
"lines": { "total": 11, "covered": 11, "skipped": 0, "pct": 100 },
"functions": { "total": 6, "covered": 6, "skipped": 0, "pct": 100 },
"statements": { "total": 11, "covered": 11, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\shared\\directives\\do-nothing-directive.metadata.ts": {
"lines": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 },
"functions": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 },
"statements": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\shared\\directives\\do-nothing.directive.ts": {
"lines": { "total": 14, "covered": 12, "skipped": 0, "pct": 85.71 },
"functions": { "total": 9, "covered": 2, "skipped": 0, "pct": 22.22 },
"statements": { "total": 16, "covered": 14, "skipped": 0, "pct": 87.5 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\shared\\miscellaneous\\miscellaneous.ts": {
"lines": { "total": 11, "covered": 10, "skipped": 0, "pct": 90.91 },
"functions": { "total": 3, "covered": 2, "skipped": 0, "pct": 66.67 },
"statements": { "total": 12, "covered": 11, "skipped": 0, "pct": 91.67 },
"branches": { "total": 2, "covered": 2, "skipped": 0, "pct": 100 }
},
"src\\app\\shared\\models\\tidi.model.ts": {
"lines": { "total": 5, "covered": 4, "skipped": 0, "pct": 80 },
"functions": { "total": 2, "covered": 1, "skipped": 0, "pct": 50 },
"statements": { "total": 7, "covered": 6, "skipped": 0, "pct": 85.71 },
"branches": { "total": 2, "covered": 0, "skipped": 0, "pct": 0 }
},
"src\\app\\shared\\models\\todo.model.ts": {
"lines": { "total": 22, "covered": 18, "skipped": 0, "pct": 81.82 },
"functions": { "total": 10, "covered": 6, "skipped": 0, "pct": 60 },
"statements": { "total": 26, "covered": 22, "skipped": 0, "pct": 84.62 },
"branches": { "total": 2, "covered": 2, "skipped": 0, "pct": 100 }
},
"src\\app\\shared\\pipes\\first-upper.pipe.ts": {
"lines": { "total": 8, "covered": 8, "skipped": 0, "pct": 100 },
"functions": { "total": 3, "covered": 3, "skipped": 0, "pct": 100 },
"statements": { "total": 10, "covered": 10, "skipped": 0, "pct": 100 },
"branches": { "total": 0, "covered": 0, "skipped": 0, "pct": 100 }
},
"src\\app\\shared\\services\\emitter.service.ts": {
"lines": { "total": 8, "covered": 8, "skipped": 0, "pct": 100 },
"functions": { "total": 2, "covered": 2, "skipped": 0, "pct": 100 },
"statements": { "total": 10, "covered": 10, "skipped": 0, "pct": 100 },
"branches": { "total": 2, "covered": 2, "skipped": 0, "pct": 100 }
},
"src\\app\\shared\\services\\todo.store.ts": {
"lines": { "total": 52, "covered": 26, "skipped": 0, "pct": 50 },
"functions": { "total": 26, "covered": 3, "skipped": 0, "pct": 11.54 },
"statements": { "total": 58, "covered": 28, "skipped": 0, "pct": 48.28 },
"branches": { "total": 2, "covered": 2, "skipped": 0, "pct": 100 }
}
}
51 changes: 49 additions & 2 deletions test/src/cli/cli-unit-test.spec.ts
Expand Up @@ -9,7 +9,7 @@ describe('CLI Unit Test Report', () => {
describe('full path in JSON', () => {
let stdoutString = undefined,
unitTestFile;
before(function(done) {
before(function (done) {
tmp.create(distFolder);
let ls = shell('node', [
'./bin/index-cli.js',
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('CLI Unit Test Report', () => {
describe('partial path in JSON', () => {
let stdoutString = undefined,
unitTestFile;
before(function(done) {
before(function (done) {
tmp.create(distFolder);
let ls = shell('node', [
'./bin/index-cli.js',
Expand Down Expand Up @@ -99,4 +99,51 @@ describe('CLI Unit Test Report', () => {
);
});
});

describe('Windows style path in JSON', () => {
let stdoutString = undefined,
unitTestFile;
before(function (done) {
tmp.create(distFolder);
let ls = shell('node', [
'./bin/index-cli.js',
'-p',
'./test/fixtures/todomvc-ng2/src/tsconfig.json',
'--unitTestCoverage',
'./test/fixtures/todomvc-ng2/coverage-summary-win.json',
'-d',
distFolder
]);

if (ls.stderr.toString() !== '') {
console.error(`shell error: ${ls.stderr.toString()}`);
done('error');
}
stdoutString = ls.stdout.toString();
unitTestFile = read(`${distFolder}/unit-test.html`);
done();
});
after(() => tmp.clean(distFolder));

it('should have unit test page', () => {
expect(unitTestFile).to.contain('Unit test coverage');
expect(unitTestFile).to.contain('<span class="coverage-count">(22/26)</span>');
});

it('should have badges', () => {
expect(unitTestFile).to.contain('img src="./images/coverage-badge-statements.svg"');
expect(unitTestFile).to.contain('img src="./images/coverage-badge-branches.svg"');
expect(unitTestFile).to.contain('img src="./images/coverage-badge-functions.svg"');
expect(unitTestFile).to.contain('img src="./images/coverage-badge-lines.svg"');
});

it('should have partial file path links', () => {
expect(unitTestFile).to.contain(
'<a href="./components/AppComponent.html">src\\app\\app.component.ts</a>'
);
expect(unitTestFile).to.contain(
'<a href="./components/AboutComponent.html">src\\app\\about\\about.component.ts</a>'
);
});
});
});

0 comments on commit 43bbc3b

Please sign in to comment.