From 750deb936719d5adda8dafa582d0aa4614504b7e Mon Sep 17 00:00:00 2001 From: Solomon Victorino Date: Wed, 14 Aug 2024 15:34:36 -0600 Subject: [PATCH] test: fail on unhandled JS exceptions --- tests/e2e/actions.test.e2e.js | 4 ++-- .../commit-graph-branch-selector.test.e2e.js | 4 ++-- tests/e2e/dashboard-ci-status.test.e2e.js | 4 ++-- tests/e2e/edit-comment.test.e2e.js | 4 ++-- tests/e2e/example.test.e2e.js | 4 ++-- tests/e2e/explore.test.e2e.js | 3 ++- tests/e2e/issue-sidebar.test.e2e.js | 4 ++-- tests/e2e/markdown-editor.test.e2e.js | 4 ++-- tests/e2e/markup.test.e2e.js | 3 ++- tests/e2e/profile_actions.test.e2e.js | 4 ++-- tests/e2e/reaction-selectors.test.e2e.js | 4 ++-- tests/e2e/release.test.e2e.js | 4 ++-- tests/e2e/repo-code.test.e2e.js | 4 ++-- tests/e2e/right-settings-button.test.e2e.js | 4 ++-- tests/e2e/utils_e2e.js | 22 ++++++++++++++++--- 15 files changed, 47 insertions(+), 29 deletions(-) diff --git a/tests/e2e/actions.test.e2e.js b/tests/e2e/actions.test.e2e.js index 0a4695e4a2..b049a93ed9 100644 --- a/tests/e2e/actions.test.e2e.js +++ b/tests/e2e/actions.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/commit-graph-branch-selector.test.e2e.js b/tests/e2e/commit-graph-branch-selector.test.e2e.js index 4994c948b4..db849320b9 100644 --- a/tests/e2e/commit-graph-branch-selector.test.e2e.js +++ b/tests/e2e/commit-graph-branch-selector.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/dashboard-ci-status.test.e2e.js b/tests/e2e/dashboard-ci-status.test.e2e.js index fdf868f083..f8b81dc175 100644 --- a/tests/e2e/dashboard-ci-status.test.e2e.js +++ b/tests/e2e/dashboard-ci-status.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/edit-comment.test.e2e.js b/tests/e2e/edit-comment.test.e2e.js index c2a5a8fec9..ad6e028821 100644 --- a/tests/e2e/edit-comment.test.e2e.js +++ b/tests/e2e/edit-comment.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/example.test.e2e.js b/tests/e2e/example.test.e2e.js index effb9f31b9..874faab67b 100644 --- a/tests/e2e/example.test.e2e.js +++ b/tests/e2e/example.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, save_visual, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, save_visual, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/explore.test.e2e.js b/tests/e2e/explore.test.e2e.js index 1b7986242f..9603443b35 100644 --- a/tests/e2e/explore.test.e2e.js +++ b/tests/e2e/explore.test.e2e.js @@ -1,7 +1,8 @@ // @ts-check // document is a global in evaluate, so it's safe to ignore here // eslint playwright/no-conditional-in-test: 0 -import {test, expect} from '@playwright/test'; +import {expect} from '@playwright/test'; +import {test} from './utils_e2e.js'; test('Explore view taborder', async ({page}) => { await page.goto('/explore/repos'); diff --git a/tests/e2e/issue-sidebar.test.e2e.js b/tests/e2e/issue-sidebar.test.e2e.js index 7f343bd3b3..c64cc538c5 100644 --- a/tests/e2e/issue-sidebar.test.e2e.js +++ b/tests/e2e/issue-sidebar.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/markdown-editor.test.e2e.js b/tests/e2e/markdown-editor.test.e2e.js index e773c70845..4a3b414b10 100644 --- a/tests/e2e/markdown-editor.test.e2e.js +++ b/tests/e2e/markdown-editor.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {expect, test} from '@playwright/test'; -import {load_logged_in_context, login_user} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, load_logged_in_context, login_user} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/markup.test.e2e.js b/tests/e2e/markup.test.e2e.js index ff4e948d8f..920537d08f 100644 --- a/tests/e2e/markup.test.e2e.js +++ b/tests/e2e/markup.test.e2e.js @@ -1,5 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; +import {expect} from '@playwright/test'; +import {test} from './utils_e2e.js'; test('markup with #xyz-mode-only', async ({page}) => { const response = await page.goto('/user2/repo1/issues/1'); diff --git a/tests/e2e/profile_actions.test.e2e.js b/tests/e2e/profile_actions.test.e2e.js index 55c44e7042..dcec0cd83c 100644 --- a/tests/e2e/profile_actions.test.e2e.js +++ b/tests/e2e/profile_actions.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test('Follow actions', async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/reaction-selectors.test.e2e.js b/tests/e2e/reaction-selectors.test.e2e.js index 91754b0931..2a9c62bb4d 100644 --- a/tests/e2e/reaction-selectors.test.e2e.js +++ b/tests/e2e/reaction-selectors.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/release.test.e2e.js b/tests/e2e/release.test.e2e.js index 7e08a30fbe..9d5d12848b 100644 --- a/tests/e2e/release.test.e2e.js +++ b/tests/e2e/release.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, save_visual, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, save_visual, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/repo-code.test.e2e.js b/tests/e2e/repo-code.test.e2e.js index adbcc7b38e..626af76305 100644 --- a/tests/e2e/repo-code.test.e2e.js +++ b/tests/e2e/repo-code.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/right-settings-button.test.e2e.js b/tests/e2e/right-settings-button.test.e2e.js index 698aa03192..4f2b09b4c1 100644 --- a/tests/e2e/right-settings-button.test.e2e.js +++ b/tests/e2e/right-settings-button.test.e2e.js @@ -1,6 +1,6 @@ // @ts-check -import {test, expect} from '@playwright/test'; -import {login_user, load_logged_in_context} from './utils_e2e.js'; +import {expect} from '@playwright/test'; +import {test, login_user, load_logged_in_context} from './utils_e2e.js'; test.beforeAll(async ({browser}, workerInfo) => { await login_user(browser, workerInfo, 'user2'); diff --git a/tests/e2e/utils_e2e.js b/tests/e2e/utils_e2e.js index d60c78b16e..4cc2b17d40 100644 --- a/tests/e2e/utils_e2e.js +++ b/tests/e2e/utils_e2e.js @@ -1,4 +1,20 @@ -import {expect} from '@playwright/test'; +import {expect, test as baseTest} from '@playwright/test'; + +export const test = baseTest.extend({ + context: async ({browser}, use) => { + return use(await test_context(browser)); + }, +}); + +async function test_context(browser, options) { + const context = await browser.newContext(options); + + context.on('page', (page) => { + page.on('pageerror', (err) => expect(err).toBeUndefined()); + }); + + return context; +} const ARTIFACTS_PATH = `tests/e2e/test-artifacts`; const LOGIN_PASSWORD = 'password'; @@ -7,7 +23,7 @@ const LOGIN_PASSWORD = 'password'; // run in test.beforeAll(), then the session can be loaded in tests. export async function login_user(browser, workerInfo, user) { // Set up a new context - const context = await browser.newContext(); + const context = await test_context(browser); const page = await context.newPage(); // Route to login page @@ -33,7 +49,7 @@ export async function login_user(browser, workerInfo, user) { export async function load_logged_in_context(browser, workerInfo, user) { let context; try { - context = await browser.newContext({storageState: `${ARTIFACTS_PATH}/state-${user}-${workerInfo.workerIndex}.json`}); + context = await test_context(browser, {storageState: `${ARTIFACTS_PATH}/state-${user}-${workerInfo.workerIndex}.json`}); } catch (err) { if (err.code === 'ENOENT') { throw new Error(`Could not find state for '${user}'. Did you call login_user(browser, workerInfo, '${user}') in test.beforeAll()?`);