Skip to content

Commit

Permalink
fix html report
Browse files Browse the repository at this point in the history
  • Loading branch information
serut committed Nov 27, 2018
1 parent d116d8d commit fb25f86
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
local-packages.json
.idea
test
someapp
19 changes: 15 additions & 4 deletions assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ body {
font-size: 14px;
color:#333;
}
.small { font-size: 12px;; }
.small { font-size: 12px; }
*, *:after, *:before {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
Expand Down Expand Up @@ -152,9 +152,15 @@ table.coverage td span.cline-any {
background-position: 0 -10px;
}
.status-line { height: 10px; }
/* yellow */
.cbranch-no { background: yellow !important; color: #111; }
/* dark red */
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
.low .chart { border:1px solid #C21F39 }
.highlighted,
.highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{
background: #C21F39 !important;
}
/* medium red */
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
/* light red */
Expand All @@ -167,19 +173,24 @@ table.coverage td span.cline-any {
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
.high .chart { border:1px solid rgb(77,146,33) }


.medium .chart { border:1px solid #666; }
.medium .cover-fill { background: #666; }

.cbranch-no { background: yellow !important; color: #111; }

.cstat-skip { background: #ddd; color: #111; }
.fstat-skip { background: #ddd; color: #111 !important; }
.cbranch-skip { background: #ddd !important; color: #111; }

span.cline-neutral { background: #eaeaea; }
.medium { background: #eaeaea; }

.coverage-summary td.empty {
opacity: .5;
padding-top: 4px;
padding-bottom: 4px;
line-height: 1;
color: #888;
}

.cover-fill, .cover-empty {
display:inline-block;
height: 12px;
Expand Down
63 changes: 63 additions & 0 deletions assets/block-navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var jumpToCode = (function init () {
// Classes of code we would like to highlight
var missingCoverageClasses = [ '.cbranch-no', '.cstat-no', '.fstat-no' ];

// We don't want to select elements that are direct descendants of another match
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `

// Selecter that finds elements on the page to which we can jump
var selector = notSelector + missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`

// The NodeList of matching elements
var missingCoverageElements = document.querySelectorAll(selector);

var currentIndex;

function toggleClass(index) {
missingCoverageElements.item(currentIndex).classList.remove('highlighted');
missingCoverageElements.item(index).classList.add('highlighted');
}

function makeCurrent(index) {
toggleClass(index);
currentIndex = index;
missingCoverageElements.item(index)
.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
}

function goToPrevious() {
var nextIndex = 0;
if (typeof currentIndex !== 'number' || currentIndex === 0) {
nextIndex = missingCoverageElements.length - 1;
} else if (missingCoverageElements.length > 1) {
nextIndex = currentIndex - 1;
}

makeCurrent(nextIndex);
}

function goToNext() {
var nextIndex = 0;

if (typeof currentIndex === 'number' && currentIndex < (missingCoverageElements.length - 1)) {
nextIndex = currentIndex + 1;
}

makeCurrent(nextIndex);
}

return function jump(event) {
switch (event.which) {
case 78: // n
case 74: // j
goToNext();
break;
case 66: // b
case 75: // k
case 80: // p
goToPrevious();
break;
}
};
}());
window.addEventListener('keydown', jumpToCode);
5 changes: 3 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'lmieulet:meteor-coverage',
version: '3.0.0',
version: '3.0.1',
summary: 'Server and client coverage for Meteor',
git: 'https://github.com/serut/meteor-coverage',
documentation: 'README.md',
Expand Down Expand Up @@ -31,7 +31,8 @@ Package.onUse(function (api) {
'assets/vendor/prettify.js',
'assets/base.css',
'assets/sort-arrow-sprite.png',
'assets/sorter.js'
'assets/sorter.js',
'assets/block-navigation.js'
], 'server');

api.mainModule('server/index.js', 'server');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meteor-coverage",
"version": "3.0.0",
"version": "3.0.1",
"description": "A meteor package that allows you to get the statement, line, function and branch coverage of Meteor project. This package uses the [istanbuljs](https://github.com/istanbuljs/istanbuljs) packages for coverage report. It's a debug only package, so it does not affect your production build.",
"main": "server/index.js",
"dependencies": {
Expand Down
18 changes: 8 additions & 10 deletions server/report/report-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class {

generate() {
const folderPath = this.options.path;
console.log("hey", folderPath)
this.copyStatic();
var coverage = Core.getCoverageObject();

Expand All @@ -67,7 +68,8 @@ export default class {
// Todo : use future
childrens.forEach(function (child) {
var filepath = path.join(folderPath, child.getRelativeName() + '.html');
Log.info('Creating a new html report', filepath);
Log.info('Creating a new html report', filepath, child.getQualifiedName());
console.error("OK DUDE", child.getRelativeName())
let fileReport = CoverageData.getFileReport(coverage, child.getRelativeName());
report.onDetail(fileReport, ReportCommon.getContext(filepath));
});
Expand All @@ -85,15 +87,11 @@ export default class {
Object.defineProperty(context, 'writer', {
value: {
copyFile: function (sourcePath, destPath) {
fs.readFile(sourcePath, (err, data) => {
/* istanbul ignore else */
if (err) return console.error(err);
let p = path.join(folderpath, destPath);
fs.writeFile(p, data, (err, data) => {
/* istanbul ignore else */
if (err) return console.error(err);
});
});
// fix no asset while using test runner
// do not use async - nothing is awaiting us
const data = fs.readFileSync(sourcePath);
let p = path.join(folderpath, destPath);
fs.writeFileSync(p, data);
}
}
});
Expand Down
7 changes: 7 additions & 0 deletions server/services/coverage-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export default CoverageData = {
/* istanbul ignore else */
if (childs[i].getRelativeName() === filePath) {
child = childs[i];
// fix the path if possible
if (child && child.fileCoverage &&
child.fileCoverage.data && child.fileCoverage.data.path &&
child.fileCoverage.data.path.indexOf(Conf.COVERAGE_APP_FOLDER)) {
// add the folder in the path if not present
child.fileCoverage.data.path = path.join(Conf.COVERAGE_APP_FOLDER, child.fileCoverage.data.path)
}
}
}
return child;
Expand Down
2 changes: 1 addition & 1 deletion someapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"start": "meteor run"
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"@babel/runtime": "^7.1.5",
"meteor-node-stubs": "^0.4.1",
"puppeteer": "^1.10.0"
}
Expand Down

0 comments on commit fb25f86

Please sign in to comment.