Skip to content

Commit 411d49a

Browse files
committed
Added an option to provide additional css to fix any gltiches that appears when shown in VSTS code coverage frame
1 parent 6475a13 commit 411d49a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

run.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const vstsCoverageStyles = require('./index').VstsCoverageStyles;
22

33
vstsCoverageStyles({
4-
coverageDir: './test'
4+
coverageDir: './test',
5+
extraCss: '.test{color:red;}'
56
});

src/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ const cleanCSS = require('clean-css');
77
var appRoot = require('app-root-path');
88

99
module.exports = function (options) {
10-
if(!(options && options.coverageDir))
10+
if (!(options && options.coverageDir))
1111
throw new Error('coverageDir param is required');
1212

1313
const defaultOpts = {
1414
coverageDir: './',
1515
pattern: '/**/*.html',
1616
fileEncoding: 'utf8',
17+
extraCss: '',
1718
minifyOptions: {
1819

1920
}
@@ -33,6 +34,10 @@ module.exports = function (options) {
3334

3435
let fileCache = {};
3536

37+
if (opts.extraCss) {
38+
opts.extraCss = new cleanCSS(opts.minifyOptions).minify(opts.extraCss).styles;
39+
}
40+
3641
files.forEach((file) => {
3742
fs.readFile(file, opts.fileEncoding, (fileErr, data) => {
3843
const $ = cheerio.load(data);
@@ -47,9 +52,15 @@ module.exports = function (options) {
4752

4853
$('<style/>').html(fileCache[resolvedHref]).insertAfter(jElem);
4954
jElem.remove();
50-
fs.writeFile(file, $.html(), () => {
51-
// console.log(file + ' written');
52-
});
55+
});
56+
57+
if (opts.extraCss) {
58+
var customCssObj = $('<style/>').html(opts.extraCss);
59+
$('head').append(customCssObj);
60+
}
61+
62+
fs.writeFile(file, $.html(), () => {
63+
// console.log(file + ' written');
5364
});
5465
});
5566
});

0 commit comments

Comments
 (0)