mirror of
https://github.com/donovanglover/nix-config.git
synced 2024-11-21 15:53:32 +01:00
tests: Add option to exclude files from imports
Note that these tests were originally made to prevent dead code from being in the repository, although a proper coverage solution would likely be more useful long-term.
This commit is contained in:
parent
f1a5aa8520
commit
771a97ef39
16
tests/lib.ts
16
tests/lib.ts
@ -31,11 +31,25 @@ async function getImportsInFile(file: string): Promise<string[]> {
|
||||
return imports;
|
||||
}
|
||||
|
||||
export async function assertAllModulesInDirectory(directory: string) {
|
||||
/** Assets that all files in a given directory are imported in default.nix.
|
||||
*
|
||||
* @param directory The directory to assert.
|
||||
* @param excludes Files to exclude from assertion. Useful for files imported elsewhere.
|
||||
*/
|
||||
export async function assertAllModulesInDirectory(
|
||||
directory: string,
|
||||
excludes?: string[],
|
||||
) {
|
||||
const files = await getFilesInDirectory(`./${directory}`);
|
||||
const imports = await getImportsInFile(`./${directory}/default.nix`);
|
||||
|
||||
for (const file of files) {
|
||||
const basename = file.split(`${directory}/`)[1];
|
||||
|
||||
if (excludes && excludes.includes(basename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(imports.includes(file));
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,20 @@ const dirs = [
|
||||
"specializations",
|
||||
];
|
||||
|
||||
/** A helper function to return excluded files.
|
||||
*
|
||||
* @param directory The directory to get excludes for.
|
||||
* @returns An array of excluded files for the given directory or undefined.
|
||||
*/
|
||||
function getExcludes(directory: string): string[] | undefined {
|
||||
switch (directory) {
|
||||
case "packages":
|
||||
return ["hycov.nix"];
|
||||
}
|
||||
}
|
||||
|
||||
for (const dir of dirs) {
|
||||
Deno.test(`imports all modules in ./${dir}`, async () => {
|
||||
await assertAllModulesInDirectory(dir);
|
||||
await assertAllModulesInDirectory(dir, getExcludes(dir));
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user