test: fail on unhandled JS exceptions

This commit is contained in:
Solomon Victorino 2024-08-14 15:34:36 -06:00
parent ad92ede00a
commit 750deb9367
15 changed files with 47 additions and 29 deletions

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, save_visual, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, save_visual, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,7 +1,8 @@
// @ts-check // @ts-check
// document is a global in evaluate, so it's safe to ignore here // document is a global in evaluate, so it's safe to ignore here
// eslint playwright/no-conditional-in-test: 0 // 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}) => { test('Explore view taborder', async ({page}) => {
await page.goto('/explore/repos'); await page.goto('/explore/repos');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {expect, test} from '@playwright/test'; import {expect} from '@playwright/test';
import {load_logged_in_context, login_user} from './utils_e2e.js'; import {test, load_logged_in_context, login_user} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,5 +1,6 @@
// @ts-check // @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}) => { test('markup with #xyz-mode-only', async ({page}) => {
const response = await page.goto('/user2/repo1/issues/1'); const response = await page.goto('/user2/repo1/issues/1');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test('Follow actions', async ({browser}, workerInfo) => { test('Follow actions', async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, save_visual, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, save_visual, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -1,6 +1,6 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {login_user, load_logged_in_context} from './utils_e2e.js'; import {test, login_user, load_logged_in_context} from './utils_e2e.js';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');

View file

@ -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 ARTIFACTS_PATH = `tests/e2e/test-artifacts`;
const LOGIN_PASSWORD = 'password'; const LOGIN_PASSWORD = 'password';
@ -7,7 +23,7 @@ const LOGIN_PASSWORD = 'password';
// run in test.beforeAll(), then the session can be loaded in tests. // run in test.beforeAll(), then the session can be loaded in tests.
export async function login_user(browser, workerInfo, user) { export async function login_user(browser, workerInfo, user) {
// Set up a new context // Set up a new context
const context = await browser.newContext(); const context = await test_context(browser);
const page = await context.newPage(); const page = await context.newPage();
// Route to login page // 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) { export async function load_logged_in_context(browser, workerInfo, user) {
let context; let context;
try { 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) { } catch (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
throw new Error(`Could not find state for '${user}'. Did you call login_user(browser, workerInfo, '${user}') in test.beforeAll()?`); throw new Error(`Could not find state for '${user}'. Did you call login_user(browser, workerInfo, '${user}') in test.beforeAll()?`);