From 6fd20b1c7d688f5ef29fc3b2a71a5e65c77b45d9 Mon Sep 17 00:00:00 2001 From: Jon <66625200+Kyro3400@users.noreply.github.com> Date: Sun, 17 Nov 2024 16:40:03 -0500 Subject: [PATCH] Update domains.test.js --- tests/domains.test.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/domains.test.js b/tests/domains.test.js index eddb7833..593046c4 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -7,12 +7,20 @@ const files = fs.readdirSync(domainsPath); t("Nested subdomains should not exist without a parent subdomain", (t) => { files.forEach((file) => { + // Skip directories and process only .json files + const filePath = path.join(domainsPath, file); + if (fs.lstatSync(filePath).isDirectory()) { + return; // Skip directories + } + const subdomain = file.replace(".json", ""); if (subdomain.split(".").length > 1) { const parentSubdomain = subdomain.split(".").pop(); - - t.true(files.includes(`${parentSubdomain}.json`), `${file}: Parent subdomain does not exist`); + t.true( + files.includes(`${parentSubdomain}.json`), + `${file}: Parent subdomain does not exist` + ); } }); @@ -21,13 +29,25 @@ t("Nested subdomains should not exist without a parent subdomain", (t) => { t("Nested subdomains should not exist if the parent subdomain has NS records", (t) => { files.forEach((file) => { + // Skip directories and process only .json files + const filePath = path.join(domainsPath, file); + if (fs.lstatSync(filePath).isDirectory()) { + return; // Skip directories + } + const subdomain = file.replace(".json", ""); if (subdomain.split(".").length > 1) { const parentSubdomain = subdomain.split(".").pop(); - const parentDomain = fs.readJsonSync(path.join(domainsPath, `${parentSubdomain}.json`)); + const parentFilePath = path.join(domainsPath, `${parentSubdomain}.json`); - t.is(parentDomain.record.NS, undefined, `${file}: Parent subdomain has NS records`); + // Check if the parent file exists before attempting to read it + if (fs.existsSync(parentFilePath)) { + const parentDomain = fs.readJsonSync(parentFilePath); + t.is(parentDomain.record.NS, undefined, `${file}: Parent subdomain has NS records`); + } else { + t.fail(`${parentSubdomain}.json file does not exist`); + } } });