From 2613175cc890a513d9d359e1d7693489b3eaae4d Mon Sep 17 00:00:00 2001 From: Raghu Simha Date: Tue, 31 Jul 2018 15:17:59 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=F0=9F=90=9B=20Print=20uncaught=20e?= =?UTF-8?q?rrors=20seen=20during=20tests=20(instead=20of=20rethrowing=20th?= =?UTF-8?q?em)=20(#17213)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-system/tasks/karma.conf.js | 3 --- build-system/tasks/runtime-test.js | 8 -------- test/_init_tests.js | 20 ++++---------------- 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/build-system/tasks/karma.conf.js b/build-system/tasks/karma.conf.js index c622932065ef..0662e5cbea40 100644 --- a/build-system/tasks/karma.conf.js +++ b/build-system/tasks/karma.conf.js @@ -227,9 +227,6 @@ 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, verboseLogging: false, }, diff --git a/build-system/tasks/runtime-test.js b/build-system/tasks/runtime-test.js index 01bc82362af4..188c207bfd4f 100644 --- a/build-system/tasks/runtime-test.js +++ b/build-system/tasks/runtime-test.js @@ -40,7 +40,6 @@ const {green, yellow, cyan, red, bold} = colors; const preTestTasks = argv.nobuild ? [] : ( (argv.unit || argv.a4a || argv['local-changes']) ? ['css'] : ['build']); const ampConfig = (argv.config === 'canary') ? 'canary' : 'prod'; -const tooManyTestsToFix = 15; const extensionsCssMapPath = 'EXTENSIONS_CSS_MAP'; /** @@ -458,9 +457,6 @@ function runTests() { }); } c.files = c.files.concat(config.commonUnitTestPaths, testsToRun); - if (testsToRun.length < tooManyTestsToFix) { - c.client.failOnConsoleError = true; - } } else if (argv.integration) { c.files = c.files.concat( config.commonIntegrationTestPaths, config.integrationTestPaths); @@ -478,10 +474,6 @@ function runTests() { c.files = c.files.concat(config.testPaths); } - if (argv.travis_like) { - c.client.failOnConsoleError = false; - } - // c.client is available in test browser via window.parent.karma.config c.client.amp = { useCompiledJs: !!argv.compiled, diff --git a/test/_init_tests.js b/test/_init_tests.js index 532140eae14a..6d6c4f21fadf 100644 --- a/test/_init_tests.js +++ b/test/_init_tests.js @@ -315,14 +315,7 @@ function warnForConsoleError() { } } - // We're throwing an error. Clean up other expected errors since they will - // never appear. - expectedAsyncErrors = []; - const errorMessage = message.split('\n', 1)[0]; // First line. - const {failOnConsoleError} = window.__karma__.config; - const terminator = failOnConsoleError ? '\'' : ''; - const separator = failOnConsoleError ? '\n' : '\'\n'; const helpMessage = ' The test "' + testName + '"' + ' resulted in a call to console.error. (See above line.)\n' + ' ⤷ If the error is not expected, fix the code that generated ' + @@ -333,14 +326,9 @@ function warnForConsoleError() { 'error> });\'\n' + ' ⤷ If the error is expected (and asynchronous), use the ' + 'following pattern at the top of the test:\n' + - ' \'expectAsyncConsoleError([, number of' + - ' times the error message repeats]);' + terminator; - // TODO(rsimha, #14406): Simply throw here after all tests are fixed. - if (failOnConsoleError) { - throw new Error(errorMessage + separator + helpMessage); - } else { - originalConsoleError(errorMessage + separator + helpMessage); - } + ' \'expectAsyncConsoleError([, ]);'; + originalConsoleError(errorMessage + '\'\n' + helpMessage); }); this.expectAsyncConsoleError = function(message, repeat = 1) { expectedAsyncErrors.push.apply( @@ -355,7 +343,7 @@ function warnForConsoleError() { const helpMessage = 'The test "' + testName + '" contains an "allowConsoleError" block ' + 'that didn\'t result in a call to console.error.'; - throw new Error(helpMessage); + originalConsoleError(helpMessage); } warnForConsoleError(); return result;