test: adjust test code for passing CI

This commit is contained in:
EnixCoda 2021-11-01 21:48:05 +08:00
parent a483a4f7d3
commit dd2a7d583a
3 changed files with 13 additions and 14 deletions

View file

@ -9,8 +9,9 @@ describe(`in Gitako project page`, () => {
`.js-details-container div[role="row"] div[role="rowheader"] a[title*="."]`,
)
if (commitLinks.length < 2) throw new Error(`No enough files`)
await commitLinks[i].click()
await waitForLegacyPJAXRedirect()
await waitForLegacyPJAXRedirect(async () => {
await commitLinks[i].click()
})
await expectToFind('table.js-file-line-container')
await sleep(1000)

View file

@ -5,7 +5,7 @@ import {
patientClick,
selectFileTreeItem,
sleep,
waitForPJAXAPIRedirect
waitForLegacyPJAXRedirect
} from '../../utils'
describe(`in Gitako project page`, () => {
@ -16,17 +16,17 @@ describe(`in Gitako project page`, () => {
await expandFloatModeSidebar()
await patientClick(selectFileTreeItem('.babelrc'))
await waitForPJAXAPIRedirect()
await waitForLegacyPJAXRedirect()
// The selector for file content
await expectToFind('table.js-file-line-container')
page.goBack()
await waitForPJAXAPIRedirect()
await waitForLegacyPJAXRedirect(async () => {
await sleep(1000) // This prevents failing in some cases due to some mystery scheduling issue of puppeteer or jest
page.goBack()
})
// The selector for file content
await expectToNotFind('table.js-file-line-container')
// await waitForPJAXAPIRedirect()
})
})

View file

@ -68,12 +68,10 @@ export function once(event: string, target: 'document' | 'window') {
})
}
export function waitForLegacyPJAXRedirect() {
return once('pjax:end', 'document')
}
export function waitForPJAXAPIRedirect() {
return once('pjax:ready', 'document')
export async function waitForLegacyPJAXRedirect(action?: () => void | Promise<void>) {
const promise = once('pjax:end', 'document')
await action?.()
return promise
}
export function selectFileTreeItem(path: string): string {