mirror of
https://github.com/logto-io/logto.git
synced 2025-03-10 22:22:45 -05:00
fix(test): fix experience ui test randomly fail issue (#4945)
This commit is contained in:
parent
df6d0894ba
commit
a376b71ae7
3 changed files with 17 additions and 5 deletions
|
@ -3,7 +3,7 @@ import { appendPath } from '@silverhand/essentials';
|
|||
|
||||
import { logtoUrl, mockSocialAuthPageUrl } from '#src/constants.js';
|
||||
import { readVerificationCode } from '#src/helpers/index.js';
|
||||
import { dcls, waitFor } from '#src/utils.js';
|
||||
import { dcls } from '#src/utils.js';
|
||||
|
||||
import ExpectPage from './expect-page.js';
|
||||
|
||||
|
@ -97,8 +97,11 @@ export default class ExpectExperience extends ExpectPage {
|
|||
* It will clear the ongoing experience if the experience is ended successfully.
|
||||
*/
|
||||
async verifyThenEnd(closePage = true) {
|
||||
// Wait for 500ms since sometimes the sign-in success callback haven't been handled yet
|
||||
await waitFor(500);
|
||||
/**
|
||||
* Wait for the network to be idle since we need to process the sign-in consent
|
||||
* and handle sign-in success callback, this may take a long time.
|
||||
*/
|
||||
await this.page.waitForNetworkIdle();
|
||||
if (this.#ongoing === undefined) {
|
||||
return this.throwNoOngoingExperienceError();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,11 @@ export default class ExpectPage {
|
|||
*/
|
||||
async toStart(initialUrl: URL) {
|
||||
await expectNavigation(this.page.goto(initialUrl.href), this.page);
|
||||
/**
|
||||
* Wait for the network to be idle before assert the page element
|
||||
* since the page needs to fetch data from the backend.
|
||||
*/
|
||||
await this.page.waitForNetworkIdle();
|
||||
await expect(this.page).toMatchElement('#app');
|
||||
}
|
||||
|
||||
|
|
|
@ -77,9 +77,13 @@ export const expectNavigation = async <T>(
|
|||
action: Promise<T>,
|
||||
page: Page = global.page
|
||||
): Promise<T> => {
|
||||
const [result] = await Promise.all([
|
||||
action,
|
||||
const [_, result] = await Promise.all([
|
||||
/**
|
||||
* We should call `waitForNavigation` before the action or the `waitForNavigation` will encounter a timeout error randomly,
|
||||
* since sometimes the action is too fast and the `waitForNavigation` is not called before the navigation is completed.
|
||||
*/
|
||||
page.waitForNavigation({ waitUntil: 'networkidle0' }),
|
||||
action,
|
||||
]);
|
||||
return result;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue