2024-05-30 07:13:24 +00:00
|
|
|
/**
|
|
|
|
* Helper function for throttling clicks on the recompile button to avoid hitting server side rate limits.
|
|
|
|
* The naive approach is waiting a fixed a mount of time (3s) just before clicking the button.
|
|
|
|
* This helper takes into account that other UI interactions take time. We can deduce that latency from the fixed delay (3s minus other latency). This can bring down the effective waiting time to 0s.
|
|
|
|
*/
|
|
|
|
export function throttledRecompile() {
|
|
|
|
let lastCompile = 0
|
|
|
|
function queueReset() {
|
|
|
|
cy.then(() => {
|
|
|
|
lastCompile = Date.now()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
queueReset()
|
|
|
|
return () =>
|
|
|
|
cy.then(() => {
|
2024-06-19 15:46:53 +00:00
|
|
|
cy.log('Recompile without hitting rate-limit')
|
2024-05-30 07:13:24 +00:00
|
|
|
const msSinceLastCompile = Date.now() - lastCompile
|
2024-06-11 11:01:21 +00:00
|
|
|
cy.wait(Math.max(0, 1_000 - msSinceLastCompile))
|
2024-05-30 07:13:24 +00:00
|
|
|
cy.findByText('Recompile').click()
|
|
|
|
queueReset()
|
2024-06-27 08:49:21 +00:00
|
|
|
cy.log('Wait for recompile to finish')
|
|
|
|
cy.findByText('Recompile')
|
2024-05-30 07:13:24 +00:00
|
|
|
})
|
|
|
|
}
|