From c2bed78b593b79c01bc544d39af73c27aa44ca15 Mon Sep 17 00:00:00 2001 From: Raghu Simha Date: Thu, 3 May 2018 14:34:53 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Fail=20tests=20that=20call=20`conso?= =?UTF-8?q?le=20error`=20when=20they=20are=20run=20during=20local=20dev=20?= =?UTF-8?q?(#15043)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-system/pr-check.js | 1 + build-system/tasks/karma.conf.js | 2 ++ test/_init_tests.js | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/build-system/pr-check.js b/build-system/pr-check.js index 68b7eb9dfa48..d1bc7f367425 100644 --- a/build-system/pr-check.js +++ b/build-system/pr-check.js @@ -533,6 +533,7 @@ function main() { // Run the local version of all tests. if (!process.env.TRAVIS) { + process.env['LOCAL_PR_CHECK'] = true; console.log(fileLogPrefix, 'Running all pr-check commands locally.'); runAllCommandsLocally(); stopTimer('pr-check.js', startTime); diff --git a/build-system/tasks/karma.conf.js b/build-system/tasks/karma.conf.js index a63142db6fbc..5103276cb823 100644 --- a/build-system/tasks/karma.conf.js +++ b/build-system/tasks/karma.conf.js @@ -202,6 +202,8 @@ module.exports = { // Longer timeout on Travis; fail quickly at local. timeout: process.env.TRAVIS ? 10000 : 2000, }, + // TODO(rsimha, #14406): Remove this after all tests are fixed. + failOnConsoleError: !process.env.TRAVIS && !process.env.LOCAL_PR_CHECK, // TODO(rsimha, #14432): Set to false after all tests are fixed. captureConsole: true, }, diff --git a/test/_init_tests.js b/test/_init_tests.js index d1736f4bf935..286e3e7a8573 100644 --- a/test/_init_tests.js +++ b/test/_init_tests.js @@ -289,8 +289,12 @@ function warnForConsoleError() { 'test code that generated the error:\n' + ' \'allowConsoleError(() => { });'; - // TODO(rsimha, #14432): Throw an error here after all tests are fixed. - originalConsoleError(errorMessage + '\'\n' + helpMessage); + // TODO(rsimha, #14406): Simply throw here after all tests are fixed. + if (window.__karma__.config.failOnConsoleError) { + throw new Error(errorMessage + '\'\n' + helpMessage); + } else { + originalConsoleError(errorMessage + '\'\n' + helpMessage); + } }); this.allowConsoleError = function(func) { dontWarnForConsoleError(); @@ -301,8 +305,12 @@ function warnForConsoleError() { const helpMessage = 'The test "' + testName + '" contains an "allowConsoleError" block ' + 'that didn\'t result in a call to console.error.'; - // TODO(rsimha, #14432): Throw an error here after all tests are fixed. - originalConsoleError(helpMessage); + // TODO(rsimha, #14406): Simply throw here after all tests are fixed. + if (window.__karma__.config.failOnConsoleError) { + throw new Error(helpMessage); + } else { + originalConsoleError(helpMessage); + } } warnForConsoleError(); };