Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗🐛 Print uncaught errors seen during tests (instead of rethrowing them) #17213

Merged
merged 1 commit into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions build-system/tasks/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO is about the next line, I assume. Are you removing it on purpose as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We want to continue capturing console errors.

captureConsole: true,
verboseLogging: false,
},
Expand Down
8 changes: 0 additions & 8 deletions build-system/tasks/runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
20 changes: 4 additions & 16 deletions test/_init_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand All @@ -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(<string or regex>[, 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(<string or regex>[, <number of' +
' times the error message repeats>]);';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃

originalConsoleError(errorMessage + '\'\n' + helpMessage);
});
this.expectAsyncConsoleError = function(message, repeat = 1) {
expectedAsyncErrors.push.apply(
Expand All @@ -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;
Expand Down