From eade7e15b36daa5cf4629bddae93f62cf900bc6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Matte?= Date: Tue, 3 Jan 2023 23:58:50 -0500 Subject: [PATCH] Ignore specific file when walking --- lib/suite.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/suite.js b/lib/suite.js index 986fcf4..796d55c 100644 --- a/lib/suite.js +++ b/lib/suite.js @@ -1,9 +1,11 @@ import { readdir } from 'node:fs/promises' import { join } from 'node:path' -const walkDir = async function* (dir) { +const walkDir = async function* (dir = '.', ignores = []) { const files = await readdir(dir, { withFileTypes: true }) for (const file of files) { + if (ignores.includes(file.name)) continue + if (file.isDirectory()) { yield* walkDir(join(dir, file.name)) } else { @@ -34,9 +36,7 @@ const suite = async (folder = '.') => { const total = totalreporter() - for await (const file of walkDir(folder)) { - if (file.includes('node_modules')) continue - if (file.startsWith('.git')) continue + for await (const file of walkDir(folder, ['node_modules', '.git'])) { if (!file.endsWith('.test.js')) continue const module = join(absolutePath, file)