From 658658c6c222d38813a87fe2c53e909cc9e46b95 Mon Sep 17 00:00:00 2001 From: Xon <635541+Xon@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:26:24 +0800 Subject: [PATCH] Make remote loading tests less flaky --- test-e2e/select-test-suit.ts | 21 --------------------- test-e2e/tests/select-one.spec.ts | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/test-e2e/select-test-suit.ts b/test-e2e/select-test-suit.ts index 537359ca..acaad83d 100644 --- a/test-e2e/select-test-suit.ts +++ b/test-e2e/select-test-suit.ts @@ -19,27 +19,6 @@ export class SelectTestSuit extends TestSuit { this.itemsWithPlaceholder = this.itemList.locator('.choices__item'); } - async start(textInput?: string): Promise { - await this.page.route('**/data.json', async (route) => { - await new Promise((f) => { - setTimeout(f, 250); - }); - - const fakeData = [...new Array(10)].map((_, index) => ({ - label: `Label ${index + 1}`, - value: `Value ${index + 1}`, - })); - - await route.fulfill({ - status: 200, - contentType: 'application/json', - body: JSON.stringify(fakeData), - }); - }); - - await super.start(textInput); - } - async startWithClick(): Promise { await this.start(); await this.selectByClick(); diff --git a/test-e2e/tests/select-one.spec.ts b/test-e2e/tests/select-one.spec.ts index 86009dc5..f6691a51 100644 --- a/test-e2e/tests/select-one.spec.ts +++ b/test-e2e/tests/select-one.spec.ts @@ -402,11 +402,32 @@ describe(`Choices - select one`, () => { test('checking placeholder values', async ({ page, bundle }) => { const jsonLoad = page.waitForResponse('**/data.json'); + let stopJsonWaiting = () => {}; + const jsonWaiting = new Promise((f) => { + stopJsonWaiting = f; + }); + + await page.route('**/data.json', async (route) => { + await jsonWaiting; + + const fakeData = [...new Array(10)].map((_, index) => ({ + label: `Label ${index + 1}`, + value: `Value ${index + 1}`, + })); + + await route.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify(fakeData), + }); + }); + const suite = new SelectTestSuit(page, bundle, testUrl, testId); await suite.start(); await expect(suite.itemList.first()).toHaveText('Loading...'); + stopJsonWaiting(); await jsonLoad; await suite.selectByClick();