mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-25 19:23:55 +00:00
@uppy/core: fix events when retrying with upload() (#5696)
Co-authored-by: Murderlon <merlijn@soverin.net>
This commit is contained in:
parent
518f2d5d88
commit
0db99ca74b
2 changed files with 30 additions and 18 deletions
|
|
@ -1376,8 +1376,7 @@ describe('src/Core', () => {
|
|||
onUpload.mockReset()
|
||||
onUploadError.mockReset()
|
||||
|
||||
// One failed file in memory but we add a new one before uploading
|
||||
core.addFile({
|
||||
const secondFileID = core.addFile({
|
||||
source: 'vi',
|
||||
name: 'bar.jpg',
|
||||
type: 'image/jpeg',
|
||||
|
|
@ -1388,15 +1387,24 @@ describe('src/Core', () => {
|
|||
// Second time two uploads should happen back-to-back.
|
||||
// First to retry the failed files, which will emit events, and the second upload
|
||||
// for the new files, which also emits events.
|
||||
await core.upload()
|
||||
const result = await core.upload()
|
||||
expect(result?.successful?.[0].id).toBe(firstFileID)
|
||||
expect(result?.successful?.[1].id).toBe(secondFileID)
|
||||
|
||||
expect(onRetryAll).toBeCalledTimes(1)
|
||||
expect(onUpload).toBeCalledTimes(2)
|
||||
expect(onUploadError).toBeCalledTimes(0)
|
||||
expect(onComplete).toBeCalledTimes(2)
|
||||
const result = onComplete.mock.calls[0][0]
|
||||
expect(result.successful?.length).toBe(1)
|
||||
expect(result.failed?.length).toBe(0)
|
||||
expect(result.successful?.[0].id).toBe(firstFileID)
|
||||
expect(onComplete).toBeCalledTimes(1)
|
||||
|
||||
const retryResult = onRetryAll.mock.calls[0][0]
|
||||
expect(retryResult.length).toBe(1)
|
||||
expect(retryResult[0].id).toBe(firstFileID)
|
||||
|
||||
const completeResult = onComplete.mock.calls[0][0]
|
||||
expect(completeResult.successful?.length).toBe(2)
|
||||
expect(completeResult.failed?.length).toBe(0)
|
||||
expect(completeResult.successful?.[0].id).toBe(firstFileID)
|
||||
expect(completeResult.successful?.[1].id).toBe(secondFileID)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1371,7 +1371,7 @@ export class Uppy<
|
|||
this.emit('resume-all')
|
||||
}
|
||||
|
||||
retryAll(): Promise<UploadResult<M, B> | undefined> {
|
||||
async retryAll(): Promise<UploadResult<M, B> | undefined> {
|
||||
const updatedFiles = { ...this.getState().files }
|
||||
const filesToRetry = Object.keys(updatedFiles).filter((file) => {
|
||||
return updatedFiles[file].error
|
||||
|
|
@ -1402,7 +1402,9 @@ export class Uppy<
|
|||
const uploadID = this.#createUpload(filesToRetry, {
|
||||
forceAllowNewUpload: true, // create new upload even if allowNewUpload: false
|
||||
})
|
||||
return this.#runUpload(uploadID)
|
||||
const result = await this.#runUpload(uploadID)
|
||||
this.emit('complete', result!)
|
||||
return result
|
||||
}
|
||||
|
||||
cancelAll(): void {
|
||||
|
|
@ -2226,8 +2228,6 @@ export class Uppy<
|
|||
let result
|
||||
if (currentUpload) {
|
||||
result = currentUpload.result
|
||||
this.emit('complete', result)
|
||||
|
||||
this.#removeUpload(uploadID)
|
||||
}
|
||||
if (result == null) {
|
||||
|
|
@ -2270,17 +2270,19 @@ export class Uppy<
|
|||
error: null,
|
||||
})
|
||||
|
||||
this.emit('retry-all', Object.values(updatedFiles))
|
||||
this.emit('retry-all', this.getFilesByIds(filesToRetry))
|
||||
|
||||
const uploadID = this.#createUpload(filesToRetry, {
|
||||
forceAllowNewUpload: true, // create new upload even if allowNewUpload: false
|
||||
})
|
||||
const result = await this.#runUpload(uploadID)
|
||||
const hasNewFiles = this.getFiles().filter(
|
||||
(file) => file.progress.uploadStarted == null,
|
||||
)
|
||||
const hasNewFiles =
|
||||
this.getFiles().filter((file) => file.progress.uploadStarted == null)
|
||||
.length > 0
|
||||
|
||||
if (!hasNewFiles) {
|
||||
this.emit('complete', result!)
|
||||
|
||||
return result
|
||||
}
|
||||
files = this.getState().files
|
||||
|
|
@ -2323,7 +2325,7 @@ export class Uppy<
|
|||
// missing fields error here.
|
||||
throw err
|
||||
})
|
||||
.then(() => {
|
||||
.then(async () => {
|
||||
const { currentUploads } = this.getState()
|
||||
// get a list of files that are currently assigned to uploads
|
||||
const currentlyUploadingFiles = Object.values(currentUploads).flatMap(
|
||||
|
|
@ -2343,7 +2345,9 @@ export class Uppy<
|
|||
})
|
||||
|
||||
const uploadID = this.#createUpload(waitingFileIDs)
|
||||
return this.#runUpload(uploadID)
|
||||
const result = await this.#runUpload(uploadID)
|
||||
this.emit('complete', result!)
|
||||
return result
|
||||
})
|
||||
.catch((err) => {
|
||||
this.emit('error', err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue