Skip to content

Commit

Permalink
fix: Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu-codecov committed Aug 3, 2021
1 parent fb89052 commit c7968b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/helpers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,7 @@ export function readCoverageFile(
* @returns boolean
*/
export function fileExists(projectRoot: string, filePath: string): boolean {
try {
return fs.existsSync(getFilePath(projectRoot, filePath))
} catch (error) {
info(`File ${filePath} does not exist`)
}
return false
return fs.existsSync(getFilePath(projectRoot, filePath))
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/helpers/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ describe('File Helpers', () => {
expect(fileHelpers.coverageFilePatterns()).toContain('jacoco*.xml')
})
})
describe('file exists', () => {
it('returns true if file exists', () => {
expect(fileHelpers.fileExists('', 'test/fixtures/coverage.txt'))
})
it('returns false if file doesnt exist', () => {
expect(fileHelpers.fileExists('', 'test/fake/path/to/file.txt'))
})
it('returns true if file exists in a directory', () => {
expect(fileHelpers.fileExists('test/fixtures', 'coverage.txt'))
})
})
describe('getFilePath()', () => {
it('should return path when file path has no starting slash', () => {
expect(fileHelpers.getFilePath('/usr/', 'coverage.xml')).toEqual(
Expand Down

0 comments on commit c7968b8

Please sign in to comment.