mirror of
https://github.com/cypress-io/cypress.git
synced 2026-03-15 13:50:28 -05:00
fix(deps): update dependency request-progress to version .x 🌟 (#4584)
* fix(deps): update request-progress to 3.0.0 🌟 * Added method to utils to convert percent value to percentage - Wrote unit tests for both calculateETA and the percent to percentage conversion Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
This commit is contained in:
committed by
Jennifer Shehane
parent
19e1297240
commit
a3daee100b
@@ -139,10 +139,13 @@ const downloadFromUrl = ({ url, downloadDestination, progress }) => {
|
||||
// starting on our first progress notification
|
||||
const elapsed = new Date() - started
|
||||
|
||||
const eta = util.calculateEta(state.percent, elapsed)
|
||||
// request-progress sends a value between 0 and 1
|
||||
const percentage = util.convertPercentToPercentage(state.percent)
|
||||
|
||||
const eta = util.calculateEta(percentage, elapsed)
|
||||
|
||||
// send up our percent and seconds remaining
|
||||
progress.onProgress(state.percent, util.secsRemaining(eta))
|
||||
progress.onProgress(percentage, util.secsRemaining(eta))
|
||||
})
|
||||
// save this download here
|
||||
.pipe(fs.createWriteStream(downloadDestination))
|
||||
|
||||
@@ -189,7 +189,7 @@ const util = {
|
||||
calculateEta (percent, elapsed) {
|
||||
// returns the number of seconds remaining
|
||||
|
||||
// if we're at 100 already just return 0
|
||||
// if we're at 100% already just return 0
|
||||
if (percent === 100) {
|
||||
return 0
|
||||
}
|
||||
@@ -200,6 +200,13 @@ const util = {
|
||||
return elapsed * (1 / (percent / 100)) - elapsed
|
||||
},
|
||||
|
||||
convertPercentToPercentage (num) {
|
||||
// convert a percent with values between 0 and 1
|
||||
// with decimals, so that it is between 0 and 100
|
||||
// and has no decimal places
|
||||
return Math.round(_.isFinite(num) ? (num * 100) : 0)
|
||||
},
|
||||
|
||||
secsRemaining (eta) {
|
||||
// calculate the seconds reminaing with no decimal places
|
||||
return (_.isFinite(eta) ? (eta / 1000) : 0).toFixed(0)
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
"moment": "2.24.0",
|
||||
"ramda": "0.24.1",
|
||||
"request": "2.88.0",
|
||||
"request-progress": "0.4.0",
|
||||
"request-progress": "3.0.0",
|
||||
"supports-color": "5.5.0",
|
||||
"tmp": "0.1.0",
|
||||
"url": "0.11.0",
|
||||
|
||||
@@ -287,6 +287,30 @@ describe('util', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('.calculateEta', () => {
|
||||
it('Remaining eta is same as elapsed when 50%', () => {
|
||||
expect(util.calculateEta('50', 1000)).to.equal(1000)
|
||||
})
|
||||
|
||||
it('Remaining eta is 0 when 100%', () => {
|
||||
expect(util.calculateEta('100', 500)).to.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('.convertPercentToPercentage', () => {
|
||||
it('converts to 100 when 1', () => {
|
||||
expect(util.convertPercentToPercentage(1)).to.equal(100)
|
||||
})
|
||||
|
||||
it('strips out extra decimals', () => {
|
||||
expect(util.convertPercentToPercentage(0.37892)).to.equal(38)
|
||||
})
|
||||
|
||||
it('returns 0 if null num', () => {
|
||||
expect(util.convertPercentToPercentage(null)).to.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
context('.printNodeOptions', () => {
|
||||
describe('NODE_OPTIONS is not set', () => {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user