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

Issue 1321 fix 2 #2772

Closed
wants to merge 4 commits into from
Closed
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
56 changes: 30 additions & 26 deletions packages/driver/src/cy/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,43 +67,47 @@ const create = () => {
return originals[fnName].apply(contentWindow, args)
}

const wrapCancel = (fnName) => (timerId) => {
if (flushing) {
cancelledTimerIds[timerId] = true
}
const wrapCancel = (fnName) => {
return (timerId) => {
if (flushing) {
cancelledTimerIds[timerId] = true
}

return callThrough(fnName, [timerId])
return callThrough(fnName, [timerId])
}
}

const wrapTimer = (fnName) => (...args) => {
const [fnOrCode, delay, ...params] = args
const wrapTimer = (fnName) => {
return (...args) => {
const [fnOrCode, delay, ...params] = args

let timerId
let timerId

const timerOverride = () => {
const timerOverride = () => {
// if we're currently paused then we need
// to enqueue this timer callback and invoke
// it immediately once we're unpaused
if (paused) {
timerQueue.push({
timerId,
fnOrCode,
params,
contentWindow,
type: fnName,
})

return
if (paused) {
timerQueue.push({
timerId,
fnOrCode,
params,
contentWindow,
type: fnName,
})

return
}

// else go ahead and invoke the real function
// the same way the browser otherwise would
return invoke(contentWindow, fnOrCode, params)
}

// else go ahead and invoke the real function
// the same way the browser otherwise would
return invoke(contentWindow, fnOrCode, params)
}

timerId = callThrough(fnName, [timerOverride, delay, ...params])
timerId = callThrough(fnName, [timerOverride, delay, ...params])

return timerId
return timerId
}
}

contentWindow.setTimeout = wrapTimer('setTimeout')
Expand Down
1 change: 0 additions & 1 deletion packages/driver/test/cypress/integration/cy/timers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ describe('driver/src/cy/timers', () => {
})
})


//
// setInterval(cb, 100)
// cb() 100
Expand Down
73 changes: 73 additions & 0 deletions packages/server/lib/util/progress_bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const chalk = require('chalk')
const ProgressBar = require('progress')

module.exports = {
create (message, options = {}) {
_.defaults(options, {
total: 100,
width: 30,
})

const ascii = [
chalk.white(' -'),
chalk.blue(message),
chalk.yellow('[:bar]'),
chalk.white(':percent'),
chalk.gray(':etas'),
]

const bar = new ProgressBar(ascii.join(' '), {
total: options.total,
width: options.width,
})

let ticked = 0
const { total } = options

const clear = function () {
bar.clear = true

return bar.terminate()
}

const tick = function (num) {
ticked += num

return bar.tick(num)
}

const tickTotal = function (float) {
//# calculate the overall progress
//# of how full the bar should now be
//# taking into account the total and
//# the current ticks

//# return us the absolute total
//# we need to tick up to to fill
//# our progress bar
const abs = total * float

//# now subtract what we've already
//# ticked to get the difference
//# of what we need to tick up to
const diff = abs - ticked

return tick(diff)
}

return {
bar,
tick,
clear,
tickTotal,
}
},
}