diff --git a/tests/domains.test.js b/tests/domains.test.js index abb88004..03e2ccba 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -1,3 +1,18 @@ +const t = require("ava"); +const fs = require("fs-extra"); +const path = require("path"); + +const domainsPath = path.resolve("domains"); +const files = fs.readdirSync(domainsPath); + +// Extract valid root domains dynamically from the files, ignoring specific TLDs +const validRootDomains = Array.from( + new Set( + files + .map((file) => file.split(".").slice(-2).join(".")) + ) +); + t("Nested subdomains should not exist without a valid parent domain", (t) => { files.forEach((file) => { // Skip directories and process only .json files @@ -13,7 +28,7 @@ t("Nested subdomains should not exist without a valid parent domain", (t) => { // Get the parent domain (remove the first part of the subdomain) const parentSubdomain = subdomain.split(".").slice(1).join("."); - // Ensure the parent subdomain exists + // Ensure the parent subdomain exists in the list of files t.true( files.includes(`${parentSubdomain}.json`), `${file}: Parent domain ${parentSubdomain}.json does not exist` @@ -34,7 +49,7 @@ t("Nested subdomains should not exist if the parent domain has NS records", (t) const subdomain = file.replace(/\.json$/, ""); - // Skip first-level subdomains (i.e., subdomains with only one part like "599.is-cool.dev") + // Skip first-level subdomains (i.e., subdomains with only one part like "dibster.is-cool.dev") if (subdomain.split(".").length > 2) { // Get the parent domain (remove the first part of the subdomain) const parentSubdomain = subdomain.split(".").slice(1).join(".");