overleaf/server-ce/test/helpers/compile.ts
Jakob Ackermann 2754c90ea6 Merge pull request #18465 from overleaf/jpa-more-server-pro-e2e-tests
[server-pro] add more e2e tests for Server Pro

GitOrigin-RevId: 003a92ae6c12b58d1d31679f9d9e54d83cfc4a1e
2024-05-30 08:05:26 +00:00

22 lines
792 B
TypeScript

/**
* 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(() => {
const msSinceLastCompile = Date.now() - lastCompile
cy.wait(Math.max(0, 3_000 - msSinceLastCompile))
cy.findByText('Recompile').click()
queueReset()
})
}