From b2bc64c38c19de3d690110d251117fbd8118cc38 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Fri, 1 Apr 2022 11:31:23 +0400 Subject: [PATCH] feat: use `waitForSelector` to prevent flakes --- packages/web-functionality/src/index.ts | 2 +- packages/web-functionality/src/smoke.test.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/web-functionality/src/index.ts b/packages/web-functionality/src/index.ts index a91c9fb50..da14609b7 100755 --- a/packages/web-functionality/src/index.ts +++ b/packages/web-functionality/src/index.ts @@ -26,7 +26,7 @@ const handler = async (): Promise => { await runTests() break } catch (error) { - console.error(`Failed attempt ${index}:`, error) + console.error(`Failed attempt ${index + 1}:`, error) if (index === 2) { process.exit(error?.exitCode || 1) } diff --git a/packages/web-functionality/src/smoke.test.ts b/packages/web-functionality/src/smoke.test.ts index 32b15337c..66b5d2a2a 100644 --- a/packages/web-functionality/src/smoke.test.ts +++ b/packages/web-functionality/src/smoke.test.ts @@ -9,6 +9,7 @@ describe('Smoke tests', () => { it('successful runs a search', async () => { // Update search input + await page.waitForSelector('.test-query-input textarea') await expect(page).toFill( '.test-query-input textarea', 'repo:^github.com/sourcegraph/smoke-tests-test-repository$' @@ -18,6 +19,9 @@ describe('Smoke tests', () => { await expect(page).toClick('.test-search-button') // Expect results count is shown correctly - await expect(page).toMatchElement('[data-testid="streaming-progress-count"]', { text: '1 result' }) - }, 5000) // Bigger timeout is required to avoid flakes. Default is 500ms. + await page.waitForSelector('[data-testid="streaming-progress-count"]') + await expect(page).toMatchElement('[data-testid="streaming-progress-count"]', { + text: '1 result', + }) + }) })