Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thiagosanches/6115bc2047a39a195f79cd1d0f21bb17 to your computer and use it in GitHub Desktop.
Save thiagosanches/6115bc2047a39a195f79cd1d0f21bb17 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var sites = [];
var threshold = {
"performance": 0.90,
"accessibility": 0.95,
"seo": 0.90,
"pwa": 0
};
fs.readdir(".", (err, files) => {
files.forEach(file => {
if (file.endsWith(".report.json")) {
var obj = JSON.parse(fs.readFileSync(file, 'utf8'));
var isAcceptable = (obj.categories.performance.score >= threshold.performance &&
obj.categories.accessibility.score >= threshold.accessibility &&
obj.categories.seo.score >= threshold.seo &&
obj.categories.pwa.score >= threshold.pwa );
sites.push({
"site": obj.requestedUrl,
"performanceScore": obj.categories.performance.score,
"accessibilityScore": obj.categories.accessibility.score,
"seoScore": obj.categories.seo.score,
"pwaScore": obj.categories.pwa.score,
"acceptable" : isAcceptable
});
}
});
console.log(sites);
sites.forEach(element => {
if(element.acceptable === false){
process.exit(-1);
}
});
});
@thiagosanches
Copy link
Author

thiagosanches commented Mar 19, 2019

The idea is to use it on Jenkins so we can break the build.
It will read all the .report.json files on the current folder and if there isn't a acceptable value it will return -1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment