Add code quality test, remove all constructor.name entries as they are unreadable after minification

This commit is contained in:
Pieter Vander Vennet 2022-02-14 02:26:03 +01:00
parent 312dbe7aff
commit 1c418e5a49
15 changed files with 95 additions and 52 deletions

36
test/CodeQuality.spec.ts Normal file
View file

@ -0,0 +1,36 @@
import T from "./TestHelper";
import {exec} from "child_process";
export default class CodeQualitySpec extends T {
constructor() {
super([
[
"no constructor.name in compiled code", () => {
const excludedDirs = [".git", "node_modules", "dist", ".cache", ".parcel-cache", "assets"]
exec("grep \"constructor.name\" -r . " + excludedDirs.map(d => "--exclude-dir=" + d).join(" "), ((error, stdout, stderr) => {
console.log("Grep gave: ", stdout)
if (error?.message?.startsWith("Command failed: grep")) {
return;
}
if (error !== null) {
throw error
}
if (stderr !== "") {
throw stderr
}
const found = stdout.split("\n").filter(s => s !== "").filter(s => s.startsWith("test/"));
if (found.length > 0) {
throw "Found a 'constructor.name' at " + found.join(", ") + ". This is not allowed, as minification does erase names."
}
}))
}
]
]);
}
}

View file

@ -18,6 +18,7 @@ import LegacyThemeLoaderSpec from "./LegacyThemeLoader.spec";
import T from "./TestHelper";
import CreateNoteImportLayerSpec from "./CreateNoteImportLayer.spec";
import CreateCacheSpec from "./CreateCache.spec";
import CodeQualitySpec from "./CodeQuality.spec";
async function main() {
@ -39,7 +40,8 @@ async function main() {
new ReplaceGeometrySpec(),
new LegacyThemeLoaderSpec(),
new CreateNoteImportLayerSpec(),
new CreateCacheSpec()
new CreateCacheSpec(),
new CodeQualitySpec()
]
ScriptUtils.fixUtils();
const realDownloadFunc = Utils.externalDownloadFunction;