Socket
Socket
Sign inDemoInstall

gemini-coverage

Package Overview
Dependencies
14
Maintainers
6
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 2.0.0

10

lib/cli/common.js
'use strict';
var q = require('q');
const Promise = require('bluebird');

@@ -21,9 +21,7 @@ exports.common = function() {

exports.exitCoa = function exitCoa(code) {
return q.resolve({
exports.exitCoa = (code) => {
return Promise.resolve({
exitCode: code,
toString: function() {
return '';
}
toString: () => ''
});
};

16

lib/cli/gen.js
'use strict';
var fs = require('fs'),
path = require('path'),
common = require('./common'),
Generator = require('../generator');
const fs = require('fs');
const path = require('path');
const {common, exitCoa} = require('./common');
const Generator = require('../generator');

@@ -11,3 +11,3 @@ module.exports = function() {

.helpful()
.apply(common.common)
.apply(common)
.opt()

@@ -19,3 +19,3 @@ .name('template')

.def('default')
.val(function(val) {
.val((val) => {
if (!fs.existsSync(path.resolve(__dirname, '../templates/', val))) {

@@ -34,6 +34,6 @@ console.warn('Template %s is not found. Using default.', val);

.def(path.join(process.cwd(), 'gemini-coverage'))
.act(function(opts, args) {
.act((opts, args) => {
return (new Generator(opts, args)).generate()
.then(common.exitCoa);
.then(exitCoa);
});
};
'use strict';
var pkg = require('../../package.json'),
common = require('./common');
const pkg = require('../../package.json');
const common = require('./common');

@@ -6,0 +6,0 @@ module.exports = require('coa').Cmd()

'use strict';
var inherit = require('inherit'),
path = require('path'),
url = require('url'),
q = require('q'),
qfs = require('q-io/fs'),
hb = require('handlebars');
const path = require('path');
const url = require('url');
const Promise = require('bluebird');
const hb = require('handlebars');
const fs = require('fs-extra');
module.exports = inherit({
__constructor: function(opts, args) {
const readFile = (path) => fs.readFile(path, 'utf8');
module.exports = class Generator {
constructor(opts, args) {
this.opts = opts;
this.args = args;
this.templateDir = path.join(__dirname, 'templates', opts.template);
},
}
generate: function() {
var _this = this;
return qfs.makeTree(this.opts.destDir)
.then(function() {
return _this.makeReports();
generate() {
return fs.ensureDir(this.opts.destDir)
.then(() => this.makeReports())
.catch((err) => {
throw new Error(`Error while making reports\n${err.stack || err.message || err}`);
});
},
}
makeReports: function() {
var _this = this,
reports = [],
cov = this.args.coverage;
makeReports() {
const reports = [];
let cov = this.args.coverage;
if (typeof cov === 'string') {
cov = qfs.read(cov).then(JSON.parse);
cov = readFile(cov).then(JSON.parse);
}
return q.all([qfs.read(path.join(this.templateDir, 'coverage.hbs')), cov])
.spread(function(tmpl, coverage) {
return batch(coverage.files.slice());
const covHbs = path.join(this.templateDir, 'coverage.hbs');
return Promise.all([readFile(covHbs), cov])
.spread((tmpl, coverage) => {
// split files processing into batches to avoid too many files being opened
function batch(files) {
const batch = (files) => {
if (!files.length) {

@@ -45,8 +43,8 @@ return;

return q.all(files.splice(0, 10).map(function(fileInfo) {
var reportFile = fileInfo.file.replace(/\//g, '_') + '.html',
reportPath = path.join(_this.opts.destDir, reportFile);
return Promise.all(files.splice(0, 10).map((fileInfo) => {
const reportFile = fileInfo.file.replace(/\//g, '_') + '.html',
reportPath = path.join(this.opts.destDir, reportFile);
return _this.makeReport(
path.resolve(_this.opts.sourceRoot, fileInfo.file),
return this.makeReport(
path.resolve(this.opts.sourceRoot, fileInfo.file),
reportPath,

@@ -57,3 +55,3 @@ {

})
.then(function(rulesStat) {
.then((rulesStat) => {
reports.push({

@@ -66,38 +64,25 @@ source: fileInfo.file,

}))
.then(function() {
return batch(files);
});
}
.then(() => batch(files));
};
return batch(coverage.files.slice());
})
.then(function() {
return prepareOutputStats(reports);
})
.then(function(stats) {
return _this.writeIndex(stats);
})
.then(function() {
return _this.copyResources();
});
},
.then(() => prepareOutputStats(reports))
.then((stats) => this.writeIndex(stats))
.then(() => this.copyResources());
}
makeReport: function(source, dest, opts) {
var _this = this,
fi = opts.data,
blocks = fi.blocks,
stat = {
total: fi.stat.total,
covered: fi.stat.covered,
percent: fi.stat.percent,
level: fi.stat.neverUsed && 'worst' ||
fi.stat.percent === 100 && 'perfect' || fi.stat.percent >= 50 && 'good' || 'bad',
detailReport: true,
neverUsed: fi.stat.neverUsed
};
makeReport(source, dest, opts) {
const {blocks} = opts.data;
const {total, covered, percent, neverUsed} = opts.data.stat;
const level = neverUsed && 'worst' || percent === 100 && 'perfect' || percent >= 50 && 'good' || 'bad';
return qfs.read(source)
.catch(function() {
const stat = {total, covered, percent, level, detailReport: true, neverUsed};
return readFile(source)
.catch(() => {
stat.detailReport = false;
return null;
})
.then(function(content) {
.then((content) => {
if (!content) {

@@ -109,10 +94,10 @@ return;

var lines = content.split(/\r?\n/g);
let lines = content.split(/\r?\n/g);
// cover into <pre> blocks css lines having some coverage state
for (var b = blocks.length - 1; b >= 0; b--) {
var block = blocks[b];
for (let b = blocks.length - 1; b >= 0; b--) {
const block = blocks[b];
for (var l = block.start.line - 1; l < block.end.line; l++) {
for (let l = block.start.line - 1; l < block.end.line; l++) {
if (!handled.has(l)) {
lines[l] = '<pre class="' + block.type + '">' + htmlEscape(lines[l]) + ' </pre>';
lines[l] = `<pre class="${block.type}">${htmlEscape(lines[l])}</pre>`;
handled.add(l);

@@ -124,10 +109,8 @@ }

// cover into <pre> blocks everything not covered in the state above
lines = lines.map(function(line, lineNo) {
return handled.has(lineNo) ? line : '<pre>' + htmlEscape(line) + ' </pre>';
});
lines = lines.map((line, lineNo) => handled.has(lineNo) ? line : `<pre>${htmlEscape(line)}</pre>`);
return qfs.write(dest, hb.compile(opts.tmpl)({
return fs.writeFile(dest, hb.compile(opts.tmpl)({
content: lines.join('\n'),
source: path.relative(path.dirname(dest), source),
projectSource: path.relative(_this.opts.sourceRoot, source),
projectSource: path.relative(this.opts.sourceRoot, source),
url: url,

@@ -137,27 +120,24 @@ stat: stat

})
.thenResolve(stat);
},
.then(() => stat);
}
copyResources: function() {
return qfs.copyTree(path.join(__dirname, 'templates', this.opts.template, 'res'), this.opts.destDir);
},
copyResources() {
return fs.copy(path.join(__dirname, 'templates', this.opts.template, 'res'), this.opts.destDir);
}
writeIndex: function(stats) {
var _this = this;
return qfs.read(path.join(this.templateDir, 'coverage-index.hbs'))
.then(function(tmpl) {
return qfs.write(
path.join(_this.opts.destDir, 'index.html'),
writeIndex(stats) {
return readFile(path.join(this.templateDir, 'coverage-index.hbs'))
.then((tmpl) => {
return fs.writeFile(
path.join(this.opts.destDir, 'index.html'),
hb.compile(tmpl)(stats));
});
}
});
};
function prepareOutputStats(reports) {
reports.sort(function(a, b) {
return a.source.localeCompare(b.source);
});
reports.sort((a, b) => a.source.localeCompare(b.source));
var stat = reports.reduce(
function(prev, current) {
const stat = reports.reduce(
(prev, current) => {
prev.covered += current.stat.covered;

@@ -171,3 +151,3 @@ prev.total += current.stat.total;

return q.resolve({
return Promise.resolve({
reports: reports,

@@ -185,3 +165,3 @@ covered: stat.covered,

var escape = {
const escape = {
'&': '&amp;',

@@ -196,7 +176,5 @@ '<': '&lt;',

return s.replace(
new RegExp('[' + Object.keys(escape).join('') + ']', 'g'),
function(c) {
return escape[c] || c;
}
new RegExp(`[${Object.keys(escape).join('')}]`, 'g'),
(c) => escape[c] || c
);
}
{
"name": "gemini-coverage",
"version": "1.0.3",
"version": "2.0.0",
"description": "Coverage report generator for gemini",

@@ -10,7 +10,6 @@ "bin": {

"dependencies": {
"bluebird": "^3.5.1",
"coa": "^1.0.1",
"handlebars": "~1.3.0",
"inherit": "~2.2.1",
"q": "^1.4.1",
"q-io": "^2.0.6"
"fs-extra": "^5.0.0",
"handlebars": "~1.3.0"
},

@@ -17,0 +16,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc