From 0976968977289dab708909dede1254223e0a2cc1 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Thu, 31 Aug 2023 11:42:51 -0400 Subject: [PATCH] tests: Abstract assertion functionality Also uses "async function" since I personally find that easier to skim and know that it's a function. --- tests/main.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/main.ts b/tests/main.ts index c48acc04..7639655e 100644 --- a/tests/main.ts +++ b/tests/main.ts @@ -1,7 +1,7 @@ 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"; -const getFilesInDirectory = async (directory: string): Promise => { +async function getFilesInDirectory(directory: string): Promise { const files = []; for await (const walkEntry of walk(directory)) { @@ -14,7 +14,7 @@ const getFilesInDirectory = async (directory: string): Promise => { return files } -const getImportsInFile = async (file: string): Promise => { +async function getImportsInFile(file: string): Promise { const text = await Deno.readTextFile(file); const lines = text.split("\n") const imports = []; @@ -28,14 +28,18 @@ const getImportsInFile = async (file: string): Promise => { return imports } -Deno.test("imports all modules in ./packages", async () => { - const packageFiles = await getFilesInDirectory("./packages") - const packageImports = await getImportsInFile("./packages/default.nix") +async function assertAllModulesInDirectory(directory: string) { + const files = await getFilesInDirectory(`./${directory}`) + const imports = await getImportsInFile(`./${directory}/default.nix`) - console.log(packageFiles) - console.log(packageImports) + console.log(files) + console.log(imports) - for (const file of packageFiles) { - assert(packageImports.includes(file)) + for (const file of files) { + assert(imports.includes(file)) } +} + +Deno.test("imports all modules in ./packages", async () => { + await assertAllModulesInDirectory("packages") })