From d7f73083727766ff411ec9bf404f6d787a6e7a23 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Mon, 18 May 2020 17:39:43 +0200 Subject: [PATCH] chore: increase step timeout to prevent flakiness Also added a custom error logic, so actual output is printed if condition times out. Example https://travis-ci.org/github/karma-runner/karma/jobs/688421469#L643 --- test/e2e/step_definitions/core_steps.js | 9 ++++++++- test/e2e/step_definitions/utils.js | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/e2e/step_definitions/core_steps.js b/test/e2e/step_definitions/core_steps.js index d2f69b476..af6cfbbed 100644 --- a/test/e2e/step_definitions/core_steps.js +++ b/test/e2e/step_definitions/core_steps.js @@ -31,7 +31,14 @@ When('I start a server in background', async function () { }) When('I wait until server output contains:', async function (expectedOutput) { - await waitForCondition(() => this.backgroundProcess.stdout.includes(expectedOutput)) + await waitForCondition( + () => this.backgroundProcess.stdout.includes(expectedOutput), + 5000, + () => new Error( + 'Expected server output to contain the above text within 5000ms, but got:\n\n' + + this.backgroundProcess.stdout + ) + ) }) defineParameterType({ diff --git a/test/e2e/step_definitions/utils.js b/test/e2e/step_definitions/utils.js index 5dacbb470..32ea24c88 100644 --- a/test/e2e/step_definitions/utils.js +++ b/test/e2e/step_definitions/utils.js @@ -2,14 +2,18 @@ const { promisify } = require('util') const sleep = promisify(setTimeout) -module.exports.waitForCondition = async (evaluateCondition, timeout = 1000) => { +module.exports.waitForCondition = async (evaluateCondition, timeout = 1000, customError = null) => { let remainingTime = timeout while (!evaluateCondition()) { if (remainingTime > 0) { await sleep(50) remainingTime -= 50 } else { - throw new Error(`Condition not fulfilled, waited ${timeout}ms`) + if (customError != null) { + throw customError() + } else { + throw new Error(`Condition not fulfilled, waited ${timeout}ms`) + } } } }