diff --git a/tests/lib.ts b/tests/lib.ts index 9e43415d..ce33da6b 100644 --- a/tests/lib.ts +++ b/tests/lib.ts @@ -31,11 +31,25 @@ async function getImportsInFile(file: string): Promise { 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)); } } diff --git a/tests/main.ts b/tests/main.ts index 817a3db4..0bd71f13 100644 --- a/tests/main.ts +++ b/tests/main.ts @@ -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)); }); }