Skip to content

Commit

Permalink
fix: account for missing __fixture__ directory when searching for fix…
Browse files Browse the repository at this point in the history
…tures

Fixes failing test in previous commit
  • Loading branch information
jwbay committed Feb 12, 2022
1 parent ba8212e commit e1ee5d5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/fixtureFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ export function findFixtureFile(ruleName: string, fixtureDirectory: string) {
}

function searchForFixture(ruleName: string, directory: string) {
const foundFile = fs.readdirSync(directory).find((entry) => {
const extension = path.extname(entry)
const name = entry.replace(new RegExp(extension + '$'), '')
return name === ruleName || name === ruleName + '.fixture'
})
let foundFile

try {
foundFile = fs.readdirSync(directory).find((entry) => {
const extension = path.extname(entry)
const name = entry.replace(new RegExp(extension + '$'), '')
return name === ruleName || name === ruleName + '.fixture'
})
} catch (e) {
const missingDirectory = (e as NodeJS.ErrnoException)?.code === 'ENOENT'
if (!missingDirectory) {
throw e
}
}

if (foundFile) {
return path.join(directory, foundFile)
Expand Down

0 comments on commit e1ee5d5

Please sign in to comment.