Ignore specific file when walking

master
Frédéric Matte 2023-01-03 23:58:50 -05:00
parent 07f0e2a084
commit eade7e15b3
1 changed files with 4 additions and 4 deletions

View File

@ -1,9 +1,11 @@
import { readdir } from 'node:fs/promises' import { readdir } from 'node:fs/promises'
import { join } from 'node:path' import { join } from 'node:path'
const walkDir = async function* (dir) { const walkDir = async function* (dir = '.', ignores = []) {
const files = await readdir(dir, { withFileTypes: true }) const files = await readdir(dir, { withFileTypes: true })
for (const file of files) { for (const file of files) {
if (ignores.includes(file.name)) continue
if (file.isDirectory()) { if (file.isDirectory()) {
yield* walkDir(join(dir, file.name)) yield* walkDir(join(dir, file.name))
} else { } else {
@ -34,9 +36,7 @@ const suite = async (folder = '.') => {
const total = totalreporter() const total = totalreporter()
for await (const file of walkDir(folder)) { for await (const file of walkDir(folder, ['node_modules', '.git'])) {
if (file.includes('node_modules')) continue
if (file.startsWith('.git')) continue
if (!file.endsWith('.test.js')) continue if (!file.endsWith('.test.js')) continue
const module = join(absolutePath, file) const module = join(absolutePath, file)