tests: Abstract assertion functionality

Also uses "async function" since I personally find that easier to skim
and know that it's a function.
This commit is contained in:
Donovan Glover 2023-08-31 11:42:51 -04:00
parent fb7694a844
commit 0976968977
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65

View File

@ -1,7 +1,7 @@
import { assert } from "https://deno.land/std@0.200.0/assert/mod.ts"; import { assert } from "https://deno.land/std@0.200.0/assert/mod.ts";
import { walk } from "https://deno.land/std@0.200.0/fs/walk.ts"; import { walk } from "https://deno.land/std@0.200.0/fs/walk.ts";
const getFilesInDirectory = async (directory: string): Promise<string[]> => { async function getFilesInDirectory(directory: string): Promise<string[]> {
const files = []; const files = [];
for await (const walkEntry of walk(directory)) { for await (const walkEntry of walk(directory)) {
@ -14,7 +14,7 @@ const getFilesInDirectory = async (directory: string): Promise<string[]> => {
return files return files
} }
const getImportsInFile = async (file: string): Promise<string[]> => { async function getImportsInFile(file: string): Promise<string[]> {
const text = await Deno.readTextFile(file); const text = await Deno.readTextFile(file);
const lines = text.split("\n") const lines = text.split("\n")
const imports = []; const imports = [];
@ -28,14 +28,18 @@ const getImportsInFile = async (file: string): Promise<string[]> => {
return imports return imports
} }
Deno.test("imports all modules in ./packages", async () => { async function assertAllModulesInDirectory(directory: string) {
const packageFiles = await getFilesInDirectory("./packages") const files = await getFilesInDirectory(`./${directory}`)
const packageImports = await getImportsInFile("./packages/default.nix") const imports = await getImportsInFile(`./${directory}/default.nix`)
console.log(packageFiles) console.log(files)
console.log(packageImports) console.log(imports)
for (const file of packageFiles) { for (const file of files) {
assert(packageImports.includes(file)) assert(imports.includes(file))
} }
}
Deno.test("imports all modules in ./packages", async () => {
await assertAllModulesInDirectory("packages")
}) })