From 1337cf3b33dfd928cbac0699e0cae9c75f77e948 Mon Sep 17 00:00:00 2001 From: Tomer Aberbach Date: Fri, 10 May 2024 17:06:44 -0400 Subject: [PATCH] test: better coverage --- .github/workflows/ci.yml | 2 +- test/index.ts | 166 +++++++++++++++++++++++++-------------- 2 files changed, 108 insertions(+), 60 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5efbd4a..1ec8ec9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,4 +39,4 @@ jobs: run: pnpm typecheck - name: Test - run: pnpm test -- --coverage + run: pnpm test diff --git a/test/index.ts b/test/index.ts index 2326e99..223c271 100644 --- a/test/index.ts +++ b/test/index.ts @@ -4,62 +4,110 @@ import { getAllFiles, getAllFilesSync } from '../src/index.ts' const fixtures = `./test/fixtures` -test(`sync finds 6 files`, () => { - let count = 0 - - for (const filename of getAllFilesSync(fixtures)) { - expect(existsSync(filename)).toBeTrue() - count++ - } - - expect(count).toBe(6) -}) - -test(`sync with filter finds 5 files`, () => { - let count = 0 - - for (const filename of getAllFilesSync(fixtures, { - isExcludedDir: path => path.endsWith(`sort of real/`), - })) { - expect(existsSync(filename)).toBeTrue() - count++ - } - - expect(count).toBe(5) -}) - -test(`sync array finds 6 files`, () => { - const files = getAllFilesSync(fixtures) - - expect(files.toArray()).toHaveLength(6) -}) - -test(`async with filter finds 5 files`, async () => { - let count = 0 - - for await (const filename of getAllFiles(fixtures, { - isExcludedDir: path => path.endsWith(`sort of real/`), - })) { - expect(existsSync(filename)).toBeTrue() - count++ - } - - expect(count).toBe(5) -}) - -test(`async finds 6 files`, async () => { - let count = 0 - - for await (const filename of getAllFiles(fixtures)) { - expect(existsSync(filename)).toBeTrue() - count++ - } - - expect(count).toBe(6) -}) - -test(`async array finds 6 files`, async () => { - const files = getAllFiles(fixtures) - - expect(await files.toArray()).toHaveLength(6) -}) +test.each([undefined, { resolve: true }, { resolve: false }])( + `sync finds file - %p`, + options => { + let count = 0 + + for (const filename of getAllFilesSync(`${fixtures}/wow`, options)) { + expect(existsSync(filename)).toBeTrue() + count++ + } + + expect(count).toBe(1) + }, +) + +test.each([undefined, { resolve: true }, { resolve: false }])( + `sync finds 6 files - %p`, + options => { + let count = 0 + + for (const filename of getAllFilesSync(fixtures, options)) { + expect(existsSync(filename)).toBeTrue() + count++ + } + + expect(count).toBe(6) + }, +) + +test.each([undefined, { resolve: true }, { resolve: false }])( + `sync with filter finds 5 files - %p`, + options => { + let count = 0 + + for (const filename of getAllFilesSync(fixtures, { + isExcludedDir: path => path.endsWith(`sort of real/`), + ...options, + })) { + expect(existsSync(filename)).toBeTrue() + count++ + } + + expect(count).toBe(5) + }, +) + +test.each([undefined, { resolve: true }, { resolve: false }])( + `sync array finds 6 files - resolve %p`, + options => { + const files = getAllFilesSync(fixtures, options) + + expect(files.toArray()).toHaveLength(6) + }, +) + +test.each([undefined, { resolve: true }, { resolve: false }])( + `async finds file - %p`, + async options => { + let count = 0 + + for await (const filename of getAllFiles(`${fixtures}/wow`, options)) { + expect(existsSync(filename)).toBeTrue() + count++ + } + + expect(count).toBe(1) + }, +) + +test.each([undefined, { resolve: true }, { resolve: false }])( + `async with filter finds 5 files - %p`, + async options => { + let count = 0 + + for await (const filename of getAllFiles(fixtures, { + isExcludedDir: path => path.endsWith(`sort of real/`), + ...options, + })) { + expect(existsSync(filename)).toBeTrue() + count++ + } + + expect(count).toBe(5) + }, +) + +test.each([undefined, { resolve: true }, { resolve: false }])( + `async finds 6 files - resolve %p`, + async options => { + let count = 0 + + for await (const filename of getAllFiles(fixtures, options)) { + expect(existsSync(filename)).toBeTrue() + count++ + } + + expect(count).toBe(6) + }, +) + +test.each([undefined, { resolve: true }, { resolve: false }])( + `async array finds 6 files - resolve %p`, + async options => { + const files = getAllFiles(fixtures, options) + + expect(await files.toArray()).toHaveLength(6) + }, +)