diff --git a/screenshot/errorHandler.js b/screenshot/errorHandler.js new file mode 100644 index 00000000..3db9a79b --- /dev/null +++ b/screenshot/errorHandler.js @@ -0,0 +1,6 @@ +// A little utility to catch errors executing the test generation routines + +window.addEventListener('error', errorMsg => { + window.__TEST_DATA = 'Error occurred: ' + errorMsg.message; + return false; +}, {capture: true}); diff --git a/screenshot/index.js b/screenshot/index.js index 1f615aa5..e8e5d33e 100644 --- a/screenshot/index.js +++ b/screenshot/index.js @@ -1,5 +1,6 @@ import {render} from 'react-dom'; import App, {testMetadata} from 'UI_TEST_APP_ENTRY'; +import './errorHandler'; import TestChooser from './TestChooser'; const url = new URL(window.location.href); diff --git a/utils/runTest.js b/utils/runTest.js index 970bdabe..a5ade2e4 100644 --- a/utils/runTest.js +++ b/utils/runTest.js @@ -20,6 +20,10 @@ const runTest = ({concurrency, filter, Page, testName, ...rest}) => { return window.__TEST_DATA; // eslint-disable-line no-undef }); + if (typeof testCases === 'string') { + throw new Error(`Test data failed to load: ${testCases}.\n\nLoad page in a browser to view the error.`) + } + expect(testCases).to.be.an('object', 'Test data failed to load'); describe(testName, function () {