Skip to content

Commit

Permalink
test: better coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach committed May 10, 2024
1 parent ac1b280 commit 1337cf3
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
run: pnpm typecheck

- name: Test
run: pnpm test -- --coverage
run: pnpm test
166 changes: 107 additions & 59 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
)

0 comments on commit 1337cf3

Please sign in to comment.