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 0a4695e4a..b049a93ed 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 4994c948b..db849320b 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 fdf868f08..f8b81dc17 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 c2a5a8fec..ad6e02882 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 effb9f31b..874faab67 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 1b7986242..9603443b3 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 7f343bd3b..c64cc538c 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 e773c7084..4a3b414b1 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 ff4e948d8..920537d08 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 55c44e704..dcec0cd83 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 91754b093..2a9c62bb4 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 7e08a30fb..9d5d12848 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 adbcc7b38..626af7630 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 698aa0319..4f2b09b4c 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 d60c78b16..4cc2b17d4 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()?`);