From 046f22584618b8f2fb89581aecc01681f64091f2 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpovich Date: Tue, 7 Dec 2021 17:40:57 +0100 Subject: [PATCH] web: workaround flaky CI test runner (#1550) * web: workaround flaky CI test runner * Move config path to test-utils/conf/karma.config.common.d * Reusing same karma config everywhere aprt benchmarks it looks like we can have only one karma config directory Co-authored-by: Oleksandr Karpovich Co-authored-by: Shagen Ogandzhanian --- .../build.gradle.kts | 1 + web/core/build.gradle.kts | 1 + web/integration-core/build.gradle.kts | 1 + web/integration-widgets/build.gradle.kts | 1 + .../build.gradle.kts | 1 + web/svg/build.gradle.kts | 1 + web/test-utils/build.gradle.kts | 1 + .../karma-kotlin-reporter-decorated.js | 32 +++++++++++++++++++ .../conf/karma.config.common.d/patch.js | 4 +++ web/widgets/build.gradle.kts | 1 + 10 files changed, 44 insertions(+) create mode 100644 web/test-utils/conf/karma-kotlin-runner-decorator/karma-kotlin-reporter-decorated.js create mode 100644 web/test-utils/conf/karma.config.common.d/patch.js diff --git a/web/compose-compiler-integration/build.gradle.kts b/web/compose-compiler-integration/build.gradle.kts index 014fe3c615..5e75b5d1bc 100644 --- a/web/compose-compiler-integration/build.gradle.kts +++ b/web/compose-compiler-integration/build.gradle.kts @@ -9,6 +9,7 @@ kotlin { browser() { testTask { useKarma { + useConfigDirectory("${rootProject.projectDir}/test-utils/conf/karma.config.common.d") useChromeHeadless() useFirefox() } diff --git a/web/core/build.gradle.kts b/web/core/build.gradle.kts index 489abac9d7..337bd960c8 100644 --- a/web/core/build.gradle.kts +++ b/web/core/build.gradle.kts @@ -10,6 +10,7 @@ kotlin { browser() { testTask { useKarma { + useConfigDirectory("${rootProject.projectDir}/test-utils/conf/karma.config.common.d") useChromeHeadless() //useFirefox() } diff --git a/web/integration-core/build.gradle.kts b/web/integration-core/build.gradle.kts index e30dd8ec6c..92c23fbb61 100644 --- a/web/integration-core/build.gradle.kts +++ b/web/integration-core/build.gradle.kts @@ -19,6 +19,7 @@ kotlin { browser() { testTask { useKarma { + useConfigDirectory("${rootProject.projectDir}/test-utils/conf/karma.config.common.d") useChromeHeadless() useFirefox() } diff --git a/web/integration-widgets/build.gradle.kts b/web/integration-widgets/build.gradle.kts index c41575ed80..2724214f56 100644 --- a/web/integration-widgets/build.gradle.kts +++ b/web/integration-widgets/build.gradle.kts @@ -9,6 +9,7 @@ kotlin { browser() { testTask { useKarma { + useConfigDirectory("${rootProject.projectDir}/test-utils/conf/karma.config.common.d") useChromeHeadless() useFirefox() } diff --git a/web/internal-web-core-runtime/build.gradle.kts b/web/internal-web-core-runtime/build.gradle.kts index 78cfb25d16..a3bb1684bb 100644 --- a/web/internal-web-core-runtime/build.gradle.kts +++ b/web/internal-web-core-runtime/build.gradle.kts @@ -9,6 +9,7 @@ kotlin { browser() { testTask { useKarma { + useConfigDirectory("${rootProject.projectDir}/test-utils/conf/karma.config.common.d") useChromeHeadless() useFirefox() } diff --git a/web/svg/build.gradle.kts b/web/svg/build.gradle.kts index f4ffe8bd75..80cd74d387 100644 --- a/web/svg/build.gradle.kts +++ b/web/svg/build.gradle.kts @@ -9,6 +9,7 @@ kotlin { browser() { testTask { useKarma { + useConfigDirectory("${rootProject.projectDir}/test-utils/conf/karma.config.common.d") useChromeHeadless() } } diff --git a/web/test-utils/build.gradle.kts b/web/test-utils/build.gradle.kts index 5ed41c1a16..154c682aa0 100644 --- a/web/test-utils/build.gradle.kts +++ b/web/test-utils/build.gradle.kts @@ -13,6 +13,7 @@ kotlin { browser() { testTask { useKarma { + useConfigDirectory("${rootProject.projectDir}/test-utils/conf/karma.config.common.d") useChromeHeadless() useFirefox() } diff --git a/web/test-utils/conf/karma-kotlin-runner-decorator/karma-kotlin-reporter-decorated.js b/web/test-utils/conf/karma-kotlin-runner-decorator/karma-kotlin-reporter-decorated.js new file mode 100644 index 0000000000..139fc782e4 --- /dev/null +++ b/web/test-utils/conf/karma-kotlin-runner-decorator/karma-kotlin-reporter-decorated.js @@ -0,0 +1,32 @@ +// This is a workaround for https://github.com/karma-runner/karma-teamcity-reporter/issues/86 + +const kotlinReporterModule = require("../../../build/js/packages_imported/kotlin-test-js-runner/1.5.31/karma-kotlin-reporter"); + +const KotlinReporter = kotlinReporterModule['reporter:karma-kotlin-reporter'][1]; + +const NewReporter = function(baseReporterDecorator, config, emitter) { + KotlinReporter.call(this, baseReporterDecorator, config, emitter); + + const onBrowserLogOriginal = this.onBrowserLog; + const onSpecCompleteOriginal = this.onSpecComplete; + + this.onBrowserLog = (browser, log, type) => { + if (!this.browserResults[browser.id]) { + this.initializeBrowser(browser); + } + onBrowserLogOriginal(browser, log, type); + } + + this.onSpecComplete = function (browser, result) { + if (!this.browserResults[browser.id]) { + this.initializeBrowser(browser); + } + onSpecCompleteOriginal(browser, result); + } +} + +NewReporter.$inject = KotlinReporter.$inject; + +module.exports = { + 'reporter:karma-kotlin-reporter': ['type', NewReporter] +}; diff --git a/web/test-utils/conf/karma.config.common.d/patch.js b/web/test-utils/conf/karma.config.common.d/patch.js new file mode 100644 index 0000000000..d63f2cb46e --- /dev/null +++ b/web/test-utils/conf/karma.config.common.d/patch.js @@ -0,0 +1,4 @@ +config.plugins = config.plugins || []; +config.plugins = config.plugins.filter(it => it !== "kotlin-test-js-runner/karma-kotlin-reporter.js"); +config.plugins.push("../../../../../test-utils/conf/karma-kotlin-runner-decorator/karma-kotlin-reporter-decorated.js"); + diff --git a/web/widgets/build.gradle.kts b/web/widgets/build.gradle.kts index f417f37de5..b9740831f3 100644 --- a/web/widgets/build.gradle.kts +++ b/web/widgets/build.gradle.kts @@ -10,6 +10,7 @@ kotlin { browser() { testTask { useKarma { + useConfigDirectory("${rootProject.projectDir}/test-utils/conf/karma.config.common.d") useChromeHeadless() useFirefox() }