From fe12b72293e4bd3fb8af03e6d61045b33486ae05 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Thu, 24 May 2018 20:01:34 -0700 Subject: [PATCH] attempt to fix flaky tests (#318) * attempt to fix flaky tests * another attempt to fix flakiness * more attempts to fix flakiness --- tests/roles.js | 13 ++++++++----- tests/spec/002-login-spec.js | 5 ++++- tests/spec/010-focus.js | 2 ++ tests/spec/107-streaming-gap.js | 1 + tests/spec/113-block-unblock.js | 5 ++--- tests/utils.js | 18 +++++++++++------- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/tests/roles.js b/tests/roles.js index e43d1715..35e8d3b3 100644 --- a/tests/roles.js +++ b/tests/roles.js @@ -1,14 +1,17 @@ import { Role } from 'testcafe' import { - addInstanceButton, authorizeInput, emailInput, getUrl, instanceInput, mastodonLogInButton, - passwordInput + passwordInput, + sleep } from './utils' import { users } from './users' -function login (t, username, password) { - return t.typeText(instanceInput, 'localhost:3000', {paste: true}) - .click(addInstanceButton) +async function login (t, username, password) { + await sleep(500) + await t.typeText(instanceInput, 'localhost:3000', {paste: true}) + await sleep(500) + return t + .pressKey('enter') .expect(getUrl()).eql('http://localhost:3000/auth/sign_in', {timeout: 30000}) .typeText(emailInput, username, {paste: true}) .typeText(passwordInput, password, {paste: true}) diff --git a/tests/spec/002-login-spec.js b/tests/spec/002-login-spec.js index ab421aa8..e84753b2 100644 --- a/tests/spec/002-login-spec.js +++ b/tests/spec/002-login-spec.js @@ -4,7 +4,8 @@ import { authorizeInput, emailInput, formError, getFirstVisibleStatus, getUrl, instanceInput, logInToInstanceLink, mastodonLogInButton, passwordInput, - settingsButton + settingsButton, + sleep } from '../utils' fixture`002-login-spec.js` @@ -25,6 +26,7 @@ function manualLogin (t, username, password) { } test('Cannot log in to a fake instance', async t => { + await sleep(500) await t.click(logInToInstanceLink) .expect(getUrl()).contains('/settings/instances/add') .typeText(instanceInput, 'fake.nolanlawson.com', {paste: true}) @@ -39,6 +41,7 @@ test('Cannot log in to a fake instance', async t => { }) test('Logs in and logs out of localhost:3000', async t => { + await sleep(500) await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar') .expect(getUrl()).eql('http://localhost:4002/') .hover(getFirstVisibleStatus()) diff --git a/tests/spec/010-focus.js b/tests/spec/010-focus.js index 4b4e1856..e8e09afd 100644 --- a/tests/spec/010-focus.js +++ b/tests/spec/010-focus.js @@ -37,6 +37,7 @@ test('timeline preserves focus', async t => { test('timeline link preserves focus', async t => { await t.useRole(foobarRole) + .expect(getNthStatus(0).exists).ok({timeout: 20000}) .click(getNthStatus(0).find('.status-header a')) .expect(getUrl()).contains('/accounts/') .click(goBackButton) @@ -87,6 +88,7 @@ test('thread preserves focus', async t => { test('reply preserves focus and moves focus to the text input', async t => { await t.useRole(foobarRole) + .expect(getNthStatus(1).exists).ok({timeout: 20000}) .click(getNthReplyButton(1)) .expect(getActiveElementClass()).contains('compose-box-input') }) diff --git a/tests/spec/107-streaming-gap.js b/tests/spec/107-streaming-gap.js index a718cd7f..720b7fcc 100644 --- a/tests/spec/107-streaming-gap.js +++ b/tests/spec/107-streaming-gap.js @@ -14,6 +14,7 @@ test('fills in a status posted while away from timeline', async t => { await t.useRole(foobarRole) .click(localTimelineNavButton) + .expect(getNthStatus(0).exists).ok({timeout}) .hover(getNthStatus(0)) await postAs('admin', 'heyo') await t.expect(getNthStatus(0).innerText).contains('heyo', {timeout}) diff --git a/tests/spec/113-block-unblock.js b/tests/spec/113-block-unblock.js index 1ef690ff..71cc3181 100644 --- a/tests/spec/113-block-unblock.js +++ b/tests/spec/113-block-unblock.js @@ -11,11 +11,10 @@ fixture`113-block-unblock.js` .page`http://localhost:4002` test('Can block and unblock an account from a status', async t => { - await t.useRole(foobarRole) let post = 'a very silly statement that should probably get me blocked' await postAs('admin', post) - - await t.expect(getNthStatus(0).innerText).contains(post, {timeout: 20000}) + await t.useRole(foobarRole) + .expect(getNthStatus(0).innerText).contains(post, {timeout: 30000}) .click(getNthStatusOptionsButton(0)) .expect(getNthDialogOptionsOption(1).innerText).contains('Unfollow @admin') .expect(getNthDialogOptionsOption(2).innerText).contains('Block @admin') diff --git a/tests/utils.js b/tests/utils.js index 27219590..ebc464da 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -2,7 +2,7 @@ import { ClientFunction as exec, Selector as $ } from 'testcafe' import * as images from './images' import * as blobUtils from './blobUtils' -const SCROLL_INTERVAL = 3 +const SCROLL_INTERVAL = 1 export const settingsButton = $('nav a[aria-label=Settings]') export const instanceInput = $('#instanceInput') @@ -234,27 +234,29 @@ export function getNthPinnedStatusFavoriteButton (n) { } export async function validateTimeline (t, timeline) { + const timeout = 20000 for (let i = 0; i < timeline.length; i++) { let status = timeline[i] + await t.expect(getNthStatus(i).exists).ok({ timeout }) if (status.content) { await t.expect(getNthStatus(i).find('.status-content p').innerText) - .contains(status.content) + .contains(status.content, { timeout }) } if (status.spoiler) { await t.expect(getNthStatus(i).find('.status-spoiler p').innerText) - .contains(status.spoiler) + .contains(status.spoiler, { timeout }) } if (status.followedBy) { await t.expect(getNthStatus(i).find('.status-header span').innerText) - .contains(status.followedBy + ' followed you') + .contains(status.followedBy + ' followed you', { timeout }) } if (status.rebloggedBy) { await t.expect(getNthStatus(i).find('.status-header span').innerText) - .contains(status.rebloggedBy + ' boosted your status') + .contains(status.rebloggedBy + ' boosted your status', { timeout }) } if (status.favoritedBy) { await t.expect(getNthStatus(i).find('.status-header span').innerText) - .contains(status.favoritedBy + ' favorited your status') + .contains(status.favoritedBy + ' favorited your status', { timeout }) } // hovering forces TestCafé to scroll to that element: https://git.io/vABV2 @@ -291,8 +293,10 @@ export async function scrollToBottomOfTimeline (t) { } export async function scrollToStatus (t, n) { + let timeout = 20000 for (let i = 0; i <= n; i += SCROLL_INTERVAL) { - await t.hover(getNthStatus(i)) + await t.expect(getNthStatus(i).exists).ok({timeout}) + .hover(getNthStatus(i)) .expect($('.loading-footer').exist).notOk() if (i < n) { await t.hover(getNthStatus(i).find('.status-toolbar'))