Skip to content

Commit

Permalink
use a single key for error message using serialized json
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Aug 21, 2024
1 parent a5ec727 commit 8d675a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ export class ChromeService {
console.error(errorObject);

// 2. store error in sessionStorage so it can be detected in testing
sessionStorage.setItem('dev.euiProviderWarning.message', providerError.toString());
sessionStorage.setItem('dev.euiProviderWarning.stack', errorObject.stack ?? 'undefined');
sessionStorage.setItem('dev.euiProviderWarning.pageHref', window.location.href);
sessionStorage.setItem('dev.euiProviderWarning.pageTitle', document.title);
const storedError = {
message: providerError.toString(),
stack: errorObject.stack ?? 'undefined',
pageHref: window.location.href,
pageTitle: document.title,
};
sessionStorage.setItem('dev.euiProviderWarning', JSON.stringify(storedError));

// 3. error toast / popup
notifications.toasts.addDanger({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,23 @@ export async function RemoteProvider({ getService }: FtrProviderContext) {
lifecycle.afterTestSuite.add(async () => {
await tryWebDriverCall(async () => {
// collect error message stashed in SessionStorage that indicate EuiProvider implementation error
const [errorMessage, errorStack, pageHref, pageTitle] = await Promise.all([
getSessionStorageItem('dev.euiProviderWarning.message'),
getSessionStorageItem('dev.euiProviderWarning.stack'),
getSessionStorageItem('dev.euiProviderWarning.pageHref'),
getSessionStorageItem('dev.euiProviderWarning.pageTitle'),
]);
if (errorMessage != null) {
const euiProviderWarning = await getSessionStorageItem('dev.euiProviderWarning');
if (euiProviderWarning != null) {
let errorMessage: string;
let errorStack: string;
let pageHref: string;
let pageTitle: string;
try {
({
message: errorMessage,
stack: errorStack,
pageHref,
pageTitle,
} = JSON.parse(euiProviderWarning));
} catch (error) {
throw new Error(`Found EuiProvider dev error, but the details could not be parsed`);
}

log.error(`pageTitle: ${pageTitle}`);
log.error(`pageHref: ${pageHref}`);
log.error(`Error: ${errorMessage}`);
Expand Down
26 changes: 16 additions & 10 deletions test/plugin_functional/test_suites/shared_ux/eui_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@ export default function ({ getPageObjects, getService }: PluginFunctionalProvide

describe('EUI Provider Dev Warning', () => {
it('shows error toast to developer', async () => {
const pageTitle = 'EuiProvider test - Elastic';

await PageObjects.common.navigateToApp('euiProviderDevWarning');
await PageObjects.header.waitUntilLoadingHasFinished();
expect(await browser.getTitle()).eql('EuiProvider test - Elastic');
expect(await browser.getTitle()).eql(pageTitle);
await testSubjects.existOrFail('core-chrome-euiDevProviderWarning-toast');

expect(
await browser.getSessionStorageItem('dev.euiProviderWarning.message')
).to.not.be.empty();
// check that the error has been detected and stored in session storage
const euiProviderWarning = await browser.getSessionStorageItem('dev.euiProviderWarning');
const {
message: errorMessage,
stack: errorStack,
pageHref: errorPageHref,
pageTitle: errorPageTitle,
} = JSON.parse(euiProviderWarning!);
expect(errorMessage).to.not.be.empty();
expect(errorStack).to.not.be.empty();
expect(errorPageHref).to.not.be.empty();
expect(errorPageTitle).to.be(pageTitle);

// clean up to ensure test suite will pass
await Promise.all([
browser.removeSessionStorageItem('dev.euiProviderWarning.message'),
browser.removeSessionStorageItem('dev.euiProviderWarning.stack'),
browser.removeSessionStorageItem('dev.euiProviderWarning.pageHref'),
browser.removeSessionStorageItem('dev.euiProviderWarning.pageTitle'),
]);
await browser.removeSessionStorageItem('dev.euiProviderWarning');
});
});
}

0 comments on commit 8d675a6

Please sign in to comment.