From 5adb832bac5fd67ea106ff2afdd0eec2e5a6dce1 Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Wed, 4 Oct 2023 12:18:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(core):=20Return=20correctly?= =?UTF-8?q?=20when=20skipping=20file=20download=20(#908)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/downloadFile.ts | 2 ++ packages/core/test/downloadFile.test.ts | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/core/src/downloadFile.ts b/packages/core/src/downloadFile.ts index 921ad9fdc..0b358d793 100644 --- a/packages/core/src/downloadFile.ts +++ b/packages/core/src/downloadFile.ts @@ -26,6 +26,8 @@ export async function downloadFile(options: DownloaderOptions) { filePath, downloadSkipped: true }) + + return } axios diff --git a/packages/core/test/downloadFile.test.ts b/packages/core/test/downloadFile.test.ts index 0fe59188a..f67396fb5 100644 --- a/packages/core/test/downloadFile.test.ts +++ b/packages/core/test/downloadFile.test.ts @@ -54,7 +54,7 @@ describe('downloadFile', () => { }) it('calls axios.get with the correct arguments', async () => { - const axiosSpy = vi.spyOn(axios, 'get') + const axiosGetSpy = vi.spyOn(axios, 'get') await downloadFile({ url: MOCK_URL, @@ -62,8 +62,8 @@ describe('downloadFile', () => { fileName: FILE_NAME }) - expect(axiosSpy).toHaveBeenCalledOnce() - expect(axiosSpy).toHaveBeenCalledWith(MOCK_URL, { + expect(axiosGetSpy).toHaveBeenCalledOnce() + expect(axiosGetSpy).toHaveBeenCalledWith(MOCK_URL, { responseType: 'stream' }) }) @@ -115,6 +115,8 @@ describe('downloadFile', () => { }) it('skips download', async () => { + const axiosGetSpy = vi.spyOn(axios, 'get') + const result = await downloadFile({ url: MOCK_URL, outputDir: ROOT_DIR, @@ -129,9 +131,13 @@ describe('downloadFile', () => { expect(fs.readFileSync(result.filePath, 'utf8')).toBe( existingMockFileContent ) + + expect(axiosGetSpy).not.toHaveBeenCalled() }) it('overwrites the existing file if the `overrideFile` flag is present', async () => { + const axiosGetSpy = vi.spyOn(axios, 'get') + const result = await downloadFile({ url: MOCK_URL, outputDir: ROOT_DIR, @@ -145,6 +151,8 @@ describe('downloadFile', () => { }) expect(fs.existsSync(result.filePath)).toBe(true) expect(fs.readFileSync(result.filePath, 'utf8')).toBe(FILE_CONTENT) + + expect(axiosGetSpy).toHaveBeenCalledOnce() }) }) })