mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-13 08:15:41 +00:00
improve tests
This commit is contained in:
1 parent
61ed491666
commit
a79a219dd6
4 files changed
+151
-264
No files matched your search
+15
-8
@@ -59,8 +59,9 @@ t("All files should have valid file names", (t) => {
|
||||
|
||||
// Ignore root domain
|
||||
if (file !== "@.json") {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
t.regex(
|
||||
file.replace(/\.json$/, "") + ".is-a.dev",
|
||||
subdomain + ".is-a.dev",
|
||||
hostnameRegex,
|
||||
`${file}: FQDN must be 1-253 characters, use letters, numbers, dots, or hyphens, and not start or end with a hyphen.`
|
||||
);
|
||||
@@ -72,9 +73,13 @@ t("All files should have the required fields", (t) => {
|
||||
files.forEach((file) => {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
|
||||
// Validate top-level required fields
|
||||
validateRequiredFields(t, data, requiredFields, file);
|
||||
|
||||
// Validate owner object fields
|
||||
validateRequiredFields(t, data.owner, requiredOwnerFields, file);
|
||||
|
||||
// Ensure 'record' field is not empty unless reserved
|
||||
if (!data.reserved) {
|
||||
t.true(Object.keys(data.record).length > 0, `${file}: No record types found`);
|
||||
}
|
||||
@@ -85,22 +90,24 @@ t("All files should have valid optional fields", (t) => {
|
||||
files.forEach((file) => {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
|
||||
// Validate optional fields at top level
|
||||
validateOptionalFields(t, data, optionalFields, file);
|
||||
|
||||
// Validate optional fields for owner object
|
||||
validateOptionalFields(t, data.owner, optionalOwnerFields, file);
|
||||
|
||||
// Email validation (if provided)
|
||||
if (data.owner.email) {
|
||||
t.regex(data.owner.email, emailRegex, `${file}: Owner email should be a valid email address`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const ignoredJSONFiles = [
|
||||
"package-lock.json",
|
||||
"package.json"
|
||||
]
|
||||
const ignoredJSONFiles = ["package-lock.json", "package.json"];
|
||||
|
||||
t("JSON files should not be in the root directory", (t) => {
|
||||
const files = fs.readdirSync(path.resolve()).filter((file) => file.endsWith(".json") && !ignoredJSONFiles.includes(file));;
|
||||
|
||||
t.is(files.length, 0, "JSON files should not be in the root directory");
|
||||
const rootFiles = fs
|
||||
.readdirSync(path.resolve())
|
||||
.filter((file) => file.endsWith(".json") && !ignoredJSONFiles.includes(file));
|
||||
t.is(rootFiles.length, 0, "JSON files should not be in the root directory");
|
||||
});
|
||||
Reference in new issue
Block a user