mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-14 10:18:38 +00:00
optimise + improve tests
This commit is contained in:
1 parent
c84fd1377c
commit
bcf071b6f2
4 files changed
+244
-248
No files matched your search
+19
-4
@@ -3,10 +3,25 @@ const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const requiredRecordsToProxy = new Set(["A", "AAAA", "CNAME"]);
|
||||
// URL records are not listed here because they are proxied by default, so they don't need the proxied flag
|
||||
|
||||
const domainCache = {};
|
||||
|
||||
function getDomainData(file) {
|
||||
if (domainCache[file]) {
|
||||
return domainCache[file];
|
||||
}
|
||||
|
||||
try {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
domainCache[file] = data;
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to read JSON for ${file}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function validateProxiedRecords(t, data, file) {
|
||||
// Convert the Set to an array for message display
|
||||
// Convert the Set to an array for message display (moved outside the loop to optimize performance)
|
||||
const recordTypes = Array.from(requiredRecordsToProxy).join(", ");
|
||||
|
||||
if (data.proxied) {
|
||||
@@ -22,9 +37,9 @@ function validateProxiedRecords(t, data, file) {
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json"));
|
||||
|
||||
t("Domains with proxy enabled should have at least one record that can be proxied", (t) => {
|
||||
t("Domains with proxy enabled must have at least one proxy-able record", (t) => {
|
||||
files.forEach((file) => {
|
||||
const domain = fs.readJsonSync(path.join(domainsPath, file));
|
||||
const domain = getDomainData(file);
|
||||
|
||||
validateProxiedRecords(t, domain, file);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user