mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
When reconfiguring fails, the config snapshot in the frontend is not updated. When the next test uses the previous config, it will not attempt to restore that config again, and instead use the other config. Reset the config before making changes to ensure all tests get their desired config, even when reconfiguring fails. GitOrigin-RevId: 0939e709cf93da820a86fef2599940669138d728
114 lines
2.5 KiB
TypeScript
114 lines
2.5 KiB
TypeScript
import { reconfigure } from './hostAdminClient'
|
|
import { resetActivateUserRateLimit, resetCreatedUsersCache } from './login'
|
|
|
|
export const STARTUP_TIMEOUT =
|
|
parseInt(Cypress.env('STARTUP_TIMEOUT'), 10) || 120_000
|
|
|
|
export function isExcludedBySharding(
|
|
shard:
|
|
| 'LOCAL_ONLY'
|
|
| 'CE_DEFAULT'
|
|
| 'CE_CUSTOM_1'
|
|
| 'PRO_DEFAULT_1'
|
|
| 'PRO_DEFAULT_2'
|
|
| 'PRO_CUSTOM_1'
|
|
| 'PRO_CUSTOM_2'
|
|
| 'PRO_CUSTOM_3'
|
|
| 'PRO_CUSTOM_4'
|
|
) {
|
|
const SHARD = Cypress.env('SHARD')
|
|
return SHARD && shard !== SHARD
|
|
}
|
|
|
|
let previousConfigFrontend: string
|
|
|
|
export function startWith({
|
|
pro = false,
|
|
version = 'latest',
|
|
vars = {},
|
|
varsFn = () => ({}),
|
|
withDataDir = false,
|
|
resetData = false,
|
|
mongoVersion = '',
|
|
}) {
|
|
before(async function () {
|
|
Object.assign(vars, varsFn())
|
|
const cfg = JSON.stringify({
|
|
pro,
|
|
version,
|
|
vars,
|
|
withDataDir,
|
|
resetData,
|
|
mongoVersion,
|
|
})
|
|
if (resetData) {
|
|
cy.log('resetting data and sessions')
|
|
resetCreatedUsersCache()
|
|
resetActivateUserRateLimit()
|
|
// no return here, always reconfigure when resetting data
|
|
} else if (previousConfigFrontend === cfg) {
|
|
cy.log(`already running with ${cfg}`)
|
|
return
|
|
}
|
|
cy.log(`starting with ${cfg}`)
|
|
|
|
this.timeout(STARTUP_TIMEOUT)
|
|
previousConfigFrontend = ''
|
|
const { previousConfigServer } = await reconfigure({
|
|
pro,
|
|
version,
|
|
vars,
|
|
withDataDir,
|
|
resetData,
|
|
mongoVersion,
|
|
})
|
|
if (previousConfigServer !== cfg) {
|
|
await Cypress.session.clearAllSavedSessions()
|
|
}
|
|
previousConfigFrontend = cfg
|
|
})
|
|
}
|
|
|
|
// Allow reloading the server in other places, e.g. beforeEach hooks.
|
|
export async function reloadWith({
|
|
pro = false,
|
|
version = 'latest',
|
|
vars = {},
|
|
varsFn = () => ({}),
|
|
withDataDir = false,
|
|
resetData = false,
|
|
mongoVersion = '',
|
|
}) {
|
|
Object.assign(vars, varsFn())
|
|
const cfg = JSON.stringify({
|
|
pro,
|
|
version,
|
|
vars,
|
|
withDataDir,
|
|
resetData,
|
|
mongoVersion,
|
|
})
|
|
if (resetData) {
|
|
resetCreatedUsersCache()
|
|
resetActivateUserRateLimit()
|
|
// no return here, always reconfigure when resetting data
|
|
} else if (previousConfigFrontend === cfg) {
|
|
return
|
|
}
|
|
previousConfigFrontend = ''
|
|
const { previousConfigServer } = await reconfigure({
|
|
pro,
|
|
version,
|
|
vars,
|
|
withDataDir,
|
|
resetData,
|
|
mongoVersion,
|
|
})
|
|
if (previousConfigServer !== cfg) {
|
|
await Cypress.session.clearAllSavedSessions()
|
|
}
|
|
previousConfigFrontend = cfg
|
|
}
|
|
|
|
export { reconfigure }
|