diff --git a/src/cli/commands/test/iac-local-execution/file-loader.ts b/src/cli/commands/test/iac-local-execution/file-loader.ts index c6a593462d..9b95419aaa 100644 --- a/src/cli/commands/test/iac-local-execution/file-loader.ts +++ b/src/cli/commands/test/iac-local-execution/file-loader.ts @@ -41,7 +41,7 @@ export async function loadFiles( if (filesToScan.length === 0) { throw new NoFilesToScanError(); } - return filesToScan; + return filesToScan.filter((file) => file.fileContent !== ''); } function getFilePathsFromDirectory( @@ -71,10 +71,6 @@ export async function tryLoadFileData( await fs.readFile(pathToScan, DEFAULT_ENCODING) ).toString(); - if (fileContent === '') { - return null; - } - return { filePath: pathToScan, fileType: fileType as IacFileTypes, diff --git a/test/jest/unit/iac-unit-tests/file-loader.spec.ts b/test/jest/unit/iac-unit-tests/file-loader.spec.ts index b3d0752bd9..8019dbe6b2 100644 --- a/test/jest/unit/iac-unit-tests/file-loader.spec.ts +++ b/test/jest/unit/iac-unit-tests/file-loader.spec.ts @@ -162,14 +162,13 @@ describe('loadFiles', () => { }); describe('empty files', () => { - it('single empty file does not get scanned and throws an error', async () => { + it('single empty file gets scanned and returns no output', async () => { mockFs({ [emptyFileStub.filePath]: emptyFileStub.fileContent, }); - await expect(loadFiles(emptyFileStub.filePath)).rejects.toThrow( - NoFilesToScanError, - ); + const loadedFiles = await loadFiles(emptyFileStub.filePath); + expect(loadedFiles).toEqual([]); }); it('empty file in directory is skipped', async () => {