Skip to content

Commit

Permalink
feat: success colors for lighthouse in xlsx
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Aug 15, 2020
1 parent e9c02ec commit c31e554
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/save-as-xlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module.exports = (csvPath, xlsxPath) => {

// styles presets for validation
const styles = {
success: {
fill: {
fgColor: { rgb: "FFA4F79A" }
}
},
warning: {
fill: {
fgColor: { rgb: "FFFFDAA2" }
Expand Down Expand Up @@ -103,6 +108,7 @@ module.exports = (csvPath, xlsxPath) => {
if(colsValidate[colName]){
if(colsValidate[colName].warning && colsValidate[colName].warning(colVal)) ws[addr].s = styles.warning;
if(colsValidate[colName].error && colsValidate[colName].error(colVal)) ws[addr].s = styles.error;
if(colsValidate[colName].success && colsValidate[colName].success(colVal)) ws[addr].s = styles.success;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ module.exports = async (baseUrl, options = {}) => {
});
}

if(options.fields) {
//console.log('options.fields: ', options.fields);
fields = [...Object.keys(options.fields).map(f => 'result.' + f), ...fields];
if(options.fields.length > 0) {
// console.log('options.fields: ', options.fields);
const newFields = Object.keys(options.fields).map(f => 'result.' + f);
fields = [...fields, ...newFields];
}

if (options.skipStatic !== undefined) {
Expand Down
52 changes: 23 additions & 29 deletions src/validate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
const {at} = require('lodash');

const lighthouseValidateScore = {
success: (v) => v >= 90,
warning: (v) => v < 90,
error: (v) => v < 50,
};

const warnErrorThresholds = (warn, error, isSuccess=true) => {
const rules = {
warning: (v) => v > warn,
error: (v) => v > error,
}
if(isSuccess) {
rules.success = (v) => v <= warn;
}
return rules;
};

const colsValidate = {
mixed_content_url: {
error: (v) => !!v,
Expand Down Expand Up @@ -45,37 +57,19 @@ const colsValidate = {
warning: (v) => v > 1000000,
},

'lighthouse.scores.performance': lighthouseValidateScore,
'lighthouse.scores.pwa': lighthouseValidateScore,
'lighthouse.scores.accessibility': lighthouseValidateScore,
'lighthouse.scores.best-practices': lighthouseValidateScore,
'lighthouse.scores.seo': lighthouseValidateScore,
'lighthouse.scores.performance': lighthouseValidateScore,
'lighthouse.scores.pwa': lighthouseValidateScore,
'lighthouse.scores.accessibility': lighthouseValidateScore,
'lighthouse.scores.best-practices': lighthouseValidateScore,
'lighthouse.scores.seo': lighthouseValidateScore,

// https://web.dev/lighthouse-performance/
'lighthouse.first-contentful-paint': {
warning: (v) => v > 2000,
error: (v) => v > 4000
},
'lighthouse.speed-index': {
warning: (v) => v > 4300,
error: (v) => v > 5800
},
'lighthouse.largest-contentful-paint': {
warning: (v) => v > 2000,
error: (v) => v > 4000
},
'lighthouse.interactive': {
warning: (v) => v > 3800,
error: (v) => v > 7300
},
'lighthouse.total-blocking-time': {
warning: (v) => v > 300,
error: (v) => v > 600
},
'lighthouse.cumulative-layout-shift': {
warning: (v) => v > 100,
error: (v) => v > 250
},
'lighthouse.first-contentful-paint': warnErrorThresholds(2000, 4000),
'lighthouse.speed-index': warnErrorThresholds(4300, 5800),
'lighthouse.largest-contentful-paint': warnErrorThresholds(2000, 4000),
'lighthouse.interactive': warnErrorThresholds(3800, 7300),
'lighthouse.total-blocking-time': warnErrorThresholds(300, 600),
'lighthouse.cumulative-layout-shift': warnErrorThresholds(100, 250),
};

const validationSum = {};
Expand Down

0 comments on commit c31e554

Please sign in to comment.