Skip to content

Commit

Permalink
feat(e2e): Introduce JS exception catcher to whole test suite (#16788)
Browse files Browse the repository at this point in the history
* feat(e2e): Introduce JS exception catcher to whole test suite

* fix(e2e): Disable JS catcher for bridge and safari tests
  • Loading branch information
Vere-Grey authored Feb 4, 2025
1 parent eb781d8 commit 0ce9d7b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/suite-desktop-core/e2e/support/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,10 @@ export const isEqualWithOmit = (param: { object1: any; object2: any; mask: strin
isEqual(omit(param.object1, param.mask), omit(param.object2, param.mask));

export const formatAddress = (address: string) => splitStringEveryNCharacters(address, 4).join(' ');

// This function is used to override automatic fixtures that we want to skip in specific tests.
/* eslint-disable no-empty-pattern, react-hooks/rules-of-hooks */
export async function skipFixture({}, use: (r: void) => Promise<void>) {
await use();
}
/* eslint-enable no-empty-pattern, react-hooks/rules-of-hooks */
19 changes: 19 additions & 0 deletions packages/suite-desktop-core/e2e/support/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Fixtures = {
indexedDb: IndexedDbFixture;
metadataProviderMock: MetadataProviderMock;
blockbookMock: BlockbookMock;
exceptionLogger: void;
};

const test = base.extend<Fixtures>({
Expand Down Expand Up @@ -217,6 +218,24 @@ const test = base.extend<Fixtures>({
const blockbookMock = new BlockbookMock();
await use(blockbookMock);
},
exceptionLogger: [
async ({ page }, use) => {
const errors: Error[] = [];
page.on('pageerror', error => {
errors.push(error);
});

await use();

if (errors.length > 0) {
throw new Error(
`There was a JS exception during test run.
\n${errors.map(error => `${error.message}\n${error.stack}`).join('\n-----\n')}`,
);
}
},
{ auto: true },
],
});

export { test };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
expectBridgeToBeStopped,
waitForAppToBeInitialized,
} from '../../support/bridge';
import { launchSuite, launchSuiteElectronApp } from '../../support/common';
import { launchSuite, launchSuiteElectronApp, skipFixture } from '../../support/common';
import { expect, test } from '../../support/fixtures';

test.use({ exceptionLogger: skipFixture });
test.describe.serial('Bridge', { tag: ['@group=suite', '@desktopOnly'] }, () => {
test.beforeAll(async ({ trezorUserEnvLink }) => {
// Ensure bridge is stopped so we properly test the electron app starting node-bridge module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
expectBridgeToBeStopped,
waitForAppToBeInitialized,
} from '../../support/bridge';
import { LEGACY_BRIDGE_VERSION, launchSuite } from '../../support/common';
import { LEGACY_BRIDGE_VERSION, launchSuite, skipFixture } from '../../support/common';
import { expect, test } from '../../support/fixtures';
import { AnalyticsActions } from '../../support/pageActions/analyticsActions';
import { DevicePromptActions } from '../../support/pageActions/devicePromptActions';
import { OnboardingActions } from '../../support/pageActions/onboarding/onboardingActions';

test.use({ exceptionLogger: skipFixture });
test.describe.serial('Bridge', { tag: ['@group=suite', '@desktopOnly'] }, () => {
test.beforeEach(async ({ trezorUserEnvLink }) => {
//Ensure bridge is stopped so we properly test the electron app starting node-bridge module.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Page } from '@playwright/test';

import { launchSuite } from '../../support/common';
import { launchSuite, skipFixture } from '../../support/common';
import { expect, test } from '../../support/fixtures';
import { NetworkAnalyzer } from '../../support/networkAnalyzer';

test.use({ exceptionLogger: skipFixture });

const timeout = 1000 * 60 * 5; // 5 minutes because it takes a while to start tor.

const turnOnTorInSettings = async (window: Page, shouldEnableTor = true) => {
Expand Down
8 changes: 7 additions & 1 deletion packages/suite-desktop-core/e2e/tests/browser/safari.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { devices } from '@playwright/test';

import { skipFixture } from '../../support/common';
import { expect, test } from '../../support/fixtures';

const safariAria = `
Expand All @@ -15,7 +16,12 @@ const safariAria = `
- paragraph: Continue at my own risk
`;

test.use({ startEmulator: false, ...devices['Desktop Safari'], channel: 'webkit' });
test.use({
startEmulator: false,
...devices['Desktop Safari'],
channel: 'webkit',
exceptionLogger: skipFixture,
});
test.describe('Safari', { tag: ['@group=other', '@webOnly', '@snapshot'] }, () => {
test('Suite does not support Safari', async ({ page, onboardingPage }) => {
await expect(page.locator('body')).toMatchAriaSnapshot(safariAria);
Expand Down

0 comments on commit 0ce9d7b

Please sign in to comment.