From 6649c27f219329b5095e6acf2253d15b5204c751 Mon Sep 17 00:00:00 2001 From: DIBSTER <76603072+DEV-DIBSTER@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:44:46 -0500 Subject: [PATCH] Update domains.test.js --- tests/domains.test.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/domains.test.js b/tests/domains.test.js index 4d817683..0fa7a47f 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -5,6 +5,14 @@ const path = require("path"); const domainsPath = path.resolve("domains"); const files = fs.readdirSync(domainsPath); +/** + * Helper function to determine if a subdomain is a root domain. + * A root domain is assumed to be exactly two parts (e.g., "is-cool.dev"). + */ +function isRootDomain(domain) { + return domain.split(".").length === 2; +} + t("Nested subdomains should not exist without a parent subdomain", (t) => { files.forEach((file) => { // Skip directories and process only .json files @@ -19,6 +27,11 @@ t("Nested subdomains should not exist without a parent subdomain", (t) => { // Get parent domain by removing the leftmost part const parentSubdomain = subdomain.split(".").slice(1).join("."); + // Skip check if the parent subdomain is a root domain + if (isRootDomain(parentSubdomain)) { + return; + } + // Ensure the parent subdomain exists t.true( files.includes(`${parentSubdomain}.json`), @@ -45,6 +58,11 @@ t("Nested subdomains should not exist if the parent subdomain has NS records", ( const parentSubdomain = subdomain.split(".").slice(1).join("."); const parentFilePath = path.join(domainsPath, `${parentSubdomain}.json`); + // Skip check if the parent subdomain is a root domain + if (isRootDomain(parentSubdomain)) { + return; + } + // Check if the parent file exists before attempting to read it if (fs.existsSync(parentFilePath)) { const parentDomain = fs.readJsonSync(parentFilePath); @@ -63,4 +81,3 @@ t("Nested subdomains should not exist if the parent subdomain has NS records", ( t.pass(); }); -