Skip to content

Commit

Permalink
🐛 fix(core): Return correctly when skipping file download (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception authored Oct 4, 2023
1 parent 7a9d47a commit 5adb832
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/downloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export async function downloadFile(options: DownloaderOptions) {
filePath,
downloadSkipped: true
})

return
}

axios
Expand Down
14 changes: 11 additions & 3 deletions packages/core/test/downloadFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ 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,
outputDir: ROOT_DIR,
fileName: FILE_NAME
})

expect(axiosSpy).toHaveBeenCalledOnce()
expect(axiosSpy).toHaveBeenCalledWith(MOCK_URL, {
expect(axiosGetSpy).toHaveBeenCalledOnce()
expect(axiosGetSpy).toHaveBeenCalledWith(MOCK_URL, {
responseType: 'stream'
})
})
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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()
})
})
})

0 comments on commit 5adb832

Please sign in to comment.