From 71963de70c0784f2eaa901811dc85878b8739f2e Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Fri, 27 Sep 2019 18:39:49 +0300 Subject: [PATCH] Move revertible methods to finally --- .../src/KotlinTestTeamCityReporter.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/tools/kotlin-test-js-runner/src/KotlinTestTeamCityReporter.ts b/libraries/tools/kotlin-test-js-runner/src/KotlinTestTeamCityReporter.ts index a84282a8fd3..fcbfb36f7d5 100644 --- a/libraries/tools/kotlin-test-js-runner/src/KotlinTestTeamCityReporter.ts +++ b/libraries/tools/kotlin-test-js-runner/src/KotlinTestTeamCityReporter.ts @@ -77,6 +77,9 @@ export function runWithTeamCityReporter( } else { const startTime = timer ? timer.start() : null; teamCity.sendMessage('testStarted', withName(name)); + + const revertLogMethods: CallableFunction[] = []; + try { runner.test(name, isIgnored, () => { const log = (type: string) => function (message?: any, ...optionalParams: any[]) { @@ -97,13 +100,14 @@ export function runWithTeamCityReporter( [method: string]: (message?: any, ...optionalParams: any[]) => void }; - const revertLogMethods = logMethods.map(method => { - const realMethod = globalConsole[method]; - globalConsole[method] = log(method); - return () => globalConsole[method] = realMethod - }); + logMethods + .map(method => { + const realMethod = globalConsole[method]; + globalConsole[method] = log(method); + return () => globalConsole[method] = realMethod + }) + .forEach(method => revertLogMethods.push(method)); fn(); - revertLogMethods.forEach(revert => revert()); }); } catch (e) { const data: TeamCityMessageData = withName(name, { @@ -118,6 +122,7 @@ export function runWithTeamCityReporter( } teamCity.sendMessage('testFailed', data); } finally { + revertLogMethods.forEach(revert => revert()); currentAssertionResult = null; const data: TeamCityMessageData = withName(name); if (startTime) {