-
-
Notifications
You must be signed in to change notification settings - Fork 626
/
Copy pathutils.js
41 lines (30 loc) · 859 Bytes
/
utils.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
const fs = require("fs");
const path = require("path");
const BASE_DIR = "test/";
function collectTestFolders(strategy) {
const testFolder = path.resolve(path.join(process.cwd(), BASE_DIR));
return extractFolder(testFolder, [], strategy);
}
function extractFolder(folderToRead, folders = [], folderStrategy) {
let files;
try {
files = fs.readdirSync(folderToRead);
} catch (error) {
return [];
}
if (!files) {
return [];
}
files.forEach((file) => {
const filePath = path.resolve(path.join(folderToRead, file));
const stats = fs.statSync(filePath);
if (folderStrategy(stats, file)) {
folders.push(folderToRead);
}
if (stats.isDirectory() && file !== "node_modules") {
extractFolder(filePath, folders, folderStrategy);
}
});
return folders;
}
module.exports = collectTestFolders;