Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix(core): Return correctly when skipping file download #908

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
})
})