Update test.js to check for sizes and correct sizes (#652)

* Update/Modernize Chai, NPM, Fetch

* Test readme size

* Remove dev check

* Fix file sizes

Mostly fixing readme to match files, but sometimes removing newlines to match readme

* Test improvements

* Fix Samsung Swoop size
This commit is contained in:
Ethan Chapman
2022-04-30 12:46:57 -04:00
committed by GitHub
parent 12da895902
commit ad84b11924
19 changed files with 1385 additions and 415 deletions

View File

@@ -1,17 +1,22 @@
const expect = require("chai").expect
const fs = require("fs")
const fetch = require("node-fetch")
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const svgDir = __dirname + "/../images/svg/"
const readme = __dirname + "/../README.md"
const readmeLines = fs.readFileSync(readme).toString().split("\n")
const files = fs.readdirSync(svgDir)
const readmeRegex = new RegExp("<br>(\\d{1,4}) Bytes<\/td>")
files.forEach((filename, i) => {
if (! filename.endsWith(".svg")) {return}
const filepath = svgDir + filename
describe(filename, async () => {
it("should exists", () => {
expect(fs.existsSync(filepath)).to.be.true
console.log(" ", i + 1, "/", files.length)
expect(fs.existsSync(filepath)).to.be.true
})
it("should be under 1KB", () => {
@@ -22,13 +27,23 @@ files.forEach((filename, i) => {
await fetch("https://validator.w3.org/nu/?out=gnu", {
method: "POST",
body: fs.readFileSync(filepath, "utf8").replace(/aria-label="[^"]+"/g, ""),
headers: new fetch.Headers([["Content-Type", "application/xml"]])
headers: {"Content-Type": "application/xml"}
})
.then(res => (console.log(i + 1, "/", files.length), res))
.then(res => res.text())
.then(res => {
expect(res).to.be.empty
})
})
it("should match readme size", () => {
for(line of readmeLines) {
if(line.includes("/svg/"+filename+"\" width=\"125\"")) {
const size = parseInt(line.match(readmeRegex)[1])
expect(fs.statSync(filepath).size).to.equal(size)
break
}
}
})
})
})