forked from undefined-academy/semana-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolders.test.js
62 lines (54 loc) · 2.13 KB
/
folders.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const regularUsernameRegex = /(\w+|\(dot\))*/;
const discordUsernameRegex = /(\w+|\(dot\))*-\d{4}/;
// Define the array of folders and filenames to check
const foldersToCheck = [
{
name: "github-profiles",
filenames: ["index.html", "README.md", "**/*.css"],
},
];
// Define the array of folders to ignore
const foldersToIgnore = [".github", "node_modules", ".git"];
describe("Folder structure", () => {
foldersToCheck.forEach((folderToCheck) => {
// Get all folders in the current directory
const folders = fs.readdirSync(path.join(__dirname, folderToCheck.name));
folders.forEach((folder) => {
describe(`Check folder ${folderToCheck.name}/${folder}`, () => {
test(`name ${folder} is valid`, () => {
const usernameRegex = new RegExp(
`(${regularUsernameRegex.source})|(${discordUsernameRegex.source})`
);
expect(folder).toMatch(usernameRegex);
});
describe(`Check files in ${folderToCheck.name}/${folder}`, () => {
// Check if each file in the filenames array exists in the folder
folderToCheck.filenames.forEach((pattern) => {
const files = glob.sync(
path.join(__dirname, folderToCheck.name, folder, pattern),
{ nocase: false }
);
test(`file ${pattern} exists in ${folder}`, () => {
expect(files.length).toBeGreaterThan(0);
});
});
});
});
});
});
test("Check for unexpected folders", () => {
// Get all folders in the parent directory
const folders = fs.readdirSync(__dirname);
folders.forEach((folder) => {
// Check if the folder is either in foldersToCheck, foldersToIgnore, or is not a directory
const isExpectedFolder =
foldersToCheck.some((f) => f.name === folder) ||
foldersToIgnore.includes(folder) ||
!fs.lstatSync(path.join(__dirname, folder)).isDirectory();
expect(isExpectedFolder).toBe(true);
});
});
});