Repository: Moya/Moya
File: Tests/MoyaProviderSpec.swift (Swift)

Code before:
                        if case .failure(let err) = result {
                            error = err
                        }
                        done()
                    }

                    provider.request(target, callbackQueue: nil, progress: progressClosure, completion: progressCompletionClosure)
                }

                expect(error).to(beNil())
                expect(progressValues) == [0.25, 0.5, 0.75, 1.0, 1.0]
                expect(completedValues) == [false, false, false, false, true]
                expect(progressObjects.filter{$0 != nil}.count) == 5
            }

        }

        describe("a provider with upload progress tracking") {
            var provider: MoyaProvider<HTTPBin>!
            beforeEach {
                provider = MoyaProvider<HTTPBin>()
            }

            it("tracks progress of request") {

                let url = Bundle(for: MoyaProviderSpec.self).urlForImageResource("testImage.png")!
                let target: HTTPBin = .upload(file: url)
                
                var progressObjects: [Progress?] = []
                var progressValues: [Double] = []
                var completedValues: [Bool] = []
                var error: MoyaError?

                waitUntil(timeout: 5.0) { done in
                    let progressClosure: ProgressBlock = { progress in
                        progressObjects.append(progress.progressObject)
                        progressValues.append(progress.progress)
                        completedValues.append(progress.completed)
                    }

                    let progressCompletionClosure: Completion = { (result) in
                        if case .failure(let err) = result {
                            error = err
                        }
                        done()
                    }

                    provider.request(target, callbackQueue: nil, progress: progressClosure, completion: progressCompletionClosure)
                }

                expect(error).to(beNil())

Review comment (bug):
Hmm, CI is failing on this one `Bundle.urlForImageResource("testImage.png")!`, could you check if it compiles for you locally?

Code after:
                        if case .failure(let err) = result {
                            error = err
                        }
                        done()
                    }

                    provider.request(target, callbackQueue: nil, progress: progressClosure, completion: progressCompletionClosure)
                }

                expect(error).to(beNil())
                expect(progressValues) == [0.25, 0.5, 0.75, 1.0, 1.0]
                expect(completedValues) == [false, false, false, false, true]
                expect(progressObjects.filter { $0 != nil }.count) == 5
            }

        }

        describe("a provider with upload progress tracking") {
            var provider: MoyaProvider<HTTPBin>!
            beforeEach {
                provider = MoyaProvider<HTTPBin>()
            }

            it("tracks progress of request") {

                let url = Bundle(for: MoyaProviderSpec.self).url(forResource: "testImage", withExtension: "png")!
                let target: HTTPBin = .upload(file: url)

                var progressObjects: [Progress?] = []
                var progressValues: [Double] = []
                var completedValues: [Bool] = []
                var error: MoyaError?

                waitUntil(timeout: 5.0) { done in
                    let progressClosure: ProgressBlock = { progress in
                        progressObjects.append(progress.progressObject)
                        progressValues.append(progress.progress)
                        completedValues.append(progress.completed)
                    }

                    let progressCompletionClosure: Completion = { (result) in
                        if case .failure(let err) = result {
                            error = err
                        }
                        done()
                    }

                    provider.request(target, callbackQueue: nil, progress: progressClosure, completion: progressCompletionClosure)
                }

                expect(error).to(beNil())