forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestScriptChecks.ts
More file actions
36 lines (30 loc) · 1.48 KB
/
testScriptChecks.ts
File metadata and controls
36 lines (30 loc) · 1.48 KB
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
import { readdirSync, readFileSync, statSync } from "fs";
import * as path from "path";
import { printFilePath, scripts, scriptsPath } from "./utils";
const testFilenames = ['tests', 'tests.js', 'tests.ts'];
export function execute (): 0 {
const noTestScripts: string[] = [];
for (const scriptName of scripts) {
const scriptPath = path.resolve(scriptsPath, scriptName);
const files = readdirSync(scriptPath);
const testFiles = files.filter(x => testFilenames.includes(x) && !statSync(path.resolve(scriptPath, x)).isDirectory());
if (testFiles.length <= 0) noTestScripts.push(scriptPath);
else {
for (const file of testFiles) {
const filepath = path.resolve(scriptPath, file)
if (!path.extname(file) && !statSync(filepath).isDirectory()) {
console.warn(`${printFilePath(filepath)} is not a directory. Do you mean 'tests.js' or 'tests.ts'?`);
}
else if (!!path.extname(file) && statSync(filepath).isDirectory()) {
console.warn(`${printFilePath(filepath)} is not a file.`);
}
else {
const content = readFileSync(filepath).toString();
if (!/^[A-Za-z0-9]*/.test(content) || content.length <= 0) console.warn(`${printFilePath(filepath)} has no content.`);
};
}
}
};
if (noTestScripts.length > 0) console.warn(`There are ${noTestScripts.length} package(s) do not have any unit test scripts:\n${noTestScripts.map(script => printFilePath(script)).join(', ')} `);
return 0;
}