-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor(ImageUploader): get complete upload data #6779
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6779 +/- ##
==========================================
- Coverage 92.70% 92.70% -0.01%
==========================================
Files 335 335
Lines 7199 7198 -1
Branches 1792 1804 +12
==========================================
- Hits 6674 6673 -1
Misses 490 490
Partials 35 35 ☔ View full report in Codecov by Sentry. |
@@ -196,7 +196,7 @@ export const ImageUploader = forwardRef<ImageUploaderRef, ImageUploaderProps>( | |||
|
|||
setTasks(prev => [...getFinalTasks(prev), ...newTasks]) | |||
const newVal: ImageUploadItem[] = [] | |||
await Promise.all( | |||
await Promise.allSettled( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个兼容性比起 all 差很多。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个兼容性比起 all 差很多。
改为 for 循环, 成功的时候 push 值, 失败的话 push null 并在 catch log error 如何
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个解法看起来和之前 Promise.all
里去掉 throw 是差不多意思?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实~
@@ -225,10 +225,10 @@ export const ImageUploader = forwardRef<ImageUploaderRef, ImageUploaderProps>( | |||
return task | |||
}) | |||
}) | |||
throw e | |||
console.error(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试用例~~
@@ -35,6 +35,19 @@ export async function mockUploadFail() { | |||
throw new Error('Fail to upload') | |||
} | |||
|
|||
export function mockUploadWithFailure(failOnCount: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个最好放 get all upload url
测试里定义,内聚一下~
|
||
expect(fn.mock.lastCall[0].length).toBe(4) | ||
|
||
function mockUploadWithFailure(failOnCount: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
定义放最前面
jest.runAllTimers() | ||
}) | ||
|
||
expect(fn.mock.lastCall[0].length).toBe(4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
失败的 2 个要去掉,否则实际上传和 UI 会对不上
jest.runAllTimers() | ||
}) | ||
|
||
expect(fn.mock.lastCall[0].length).toBe(3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对比一下现在的 list file name 是否和 mock input 里的 file list 是对上的~
PR 标题不对。 |
#6775