Last active
March 22, 2019 10:46
-
-
Save thiagosanches/6115bc2047a39a195f79cd1d0f21bb17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.