Skip to content

Commit

Permalink
✅ Fail tests that call console error when they are run during local…
Browse files Browse the repository at this point in the history
… dev (#15043)
  • Loading branch information
rsimha authored May 3, 2018
1 parent 1c1dadd commit c2bed78
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions build-system/pr-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions build-system/tasks/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
16 changes: 12 additions & 4 deletions test/_init_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,12 @@ function warnForConsoleError() {
'test code that generated the error:\n' +
' \'allowConsoleError(() => { <code that generated the ' +
'error> });';
// 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();
Expand All @@ -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();
};
Expand Down

0 comments on commit c2bed78

Please sign in to comment.