From abee93b4212c92f1041dbe6e6823d01f9ba9d56e Mon Sep 17 00:00:00 2001 From: Jackson Howe Date: Mon, 24 Jul 2023 11:07:03 -0600 Subject: [PATCH] Fail canvas-media jest tests with console errors/warnings An exception list is created for the existing errors and warnings so that we can block new errors moving forward. refs LF-534 flag = none Test plan: - Without this commit, run `yarn jest` in packages/canvas-media - Expect to see a bunch of console errors/warnings - With this commit loaded, run `yarn jest` again - Expect to see no errors/ warnings - Add a new error to a test - Run `yarn jest` once more - Expect the test to fail Change-Id: I39ec2a6705284c5e376cb2f5412c9a8ad784a883 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/323442 Reviewed-by: Jake Oeding QA-Review: Jake Oeding Product-Review: Jackson Howe Tested-by: Service Cloud Jenkins --- packages/canvas-media/jest/jest-setup.js | 55 +++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/canvas-media/jest/jest-setup.js b/packages/canvas-media/jest/jest-setup.js index 58d93590446..96aab7354c2 100644 --- a/packages/canvas-media/jest/jest-setup.js +++ b/packages/canvas-media/jest/jest-setup.js @@ -24,8 +24,61 @@ require('@instructure/ui-themes') // set up mocks for native APIs if (!('MutationObserver' in window)) { Object.defineProperty(window, 'MutationObserver', { - value: require('@sheerun/mutationobserver-shim') + value: require('@sheerun/mutationobserver-shim'), }) } window.scroll = () => {} + +/** + * 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 = global.console.error +const ignoredErrors = [ + /An update to %s inside a test was not wrapped in act/, + /A theme registry has already been initialized/, + /The prop `label` is marked as required in `Checkbox`/, + /The prop `children` is marked as required in `CheckboxFacade`/, + /The prop `selectedLanguage.label` is marked as required in `ClosedCaptionCreatorRow`/, + /Invalid prop `value.state.selectedSrc` of type `object` supplied to `Provider`/, + /Invalid prop `sources` supplied to `Player`/, + /Invalid prop `sources` supplied to `MediaPlayer`/, + /Invalid prop `value.state.selectedSrc` of type `object` supplied to `Provider`/, + /Invalid context `state.selectedSrc` of type `object` supplied to `Consumer`/, + /Invalid child context `state.selectedSrc` of type `object` supplied to `Provider`/, + /Invalid prop `selectedSrc` of type `object` supplied to `HTML5Video`/, + /The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'/, +] +const globalWarn = global.console.warn +const ignoredWarnings = [ + /Translation for .* in "en" is missing/, + /Exactly one focusable child is required/, +] +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. ${error}` + ) + }, + 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. ${warning}` + ) + }, + info: console.info, + debug: console.debug, +} +/* eslint-enable no-console */