force clean test logs

refs VICE-930
flag=none

test plan:
  - add a console warn/error to an existing components
    with tests
  - run tests
    - the tests should now fail with a message pointing
      you to the jest setup
  - add a regex to filter your message and rerun tests
    - tests should pass and your message should be filtered

qa risk: low

Change-Id: Ib234e6aba3fa2df14f90b8d1b0b9d2e773ea9449
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/250625
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jeffrey Johnson <jeffrey.johnson@instructure.com>
QA-Review: Jeffrey Johnson <jeffrey.johnson@instructure.com>
Product-Review: Jeffrey Johnson <jeffrey.johnson@instructure.com>
This commit is contained in:
Davis Hyer 2020-10-20 16:46:03 -06:00
parent 0d6101960b
commit d6e4c5ef69
1 changed files with 36 additions and 0 deletions

View File

@ -24,3 +24,39 @@ if (!('MutationObserver' in window)) {
value: require('@sheerun/mutationobserver-shim')
})
}
/**
* We want to ensure errors and warnings get appropriate eyes. If
* you are seeing an exception from here, it probably means you
* have an unintended consequence from your changes. If you expect
* the warning/error, add it to the ignore list below.
*/
/* eslint-disable no-console */
const globalError = console.error
const ignoredErrors = []
const globalWarn = console.warn
const ignoredWarnings = [/Warning: \[SimpleSelect\] is experimental.*/]
global.console = {
log: console.log,
error: error => {
if (ignoredErrors.some(regex => regex.test(error))) {
return
}
globalError(error)
throw new Error(
'Looks like you have an unhandled error. Keep our test logs clean by handling or filtering it'
)
},
warn: warning => {
if (ignoredWarnings.some(regex => regex.test(warning))) {
return
}
globalWarn(warning)
throw new Error(
'Looks like you have an unhandled warning. Keep our test logs clean by handling or filtering it'
)
},
info: console.info,
debug: console.debug
}
/* eslint-enable no-console */