Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add debug pause mechanism to e2e tests (#2413)
Leendert de Borst1abeb5b5690d
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 981531b92..4135ebc36 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -13,8 +13,12 @@"compile": "tsc --noEmit && tsc --noEmit -p tests","lint": "eslint src tests playwright.config.ts","lint:fix": "eslint src tests playwright.config.ts --fix",- "test:e2e": "playwright test",- "test:e2e:headed": "playwright test --headed --workers=1"+ "test:e2e": "node tests/run-e2e.mjs",+ "test:e2e:headed": "node tests/run-e2e.mjs --headed --workers=1",+ "test:e2e:h": "node tests/run-e2e.mjs --headed --workers=1",+ "test:e2e:pause": "node tests/run-e2e.mjs --pause",+ "test:e2e:p": "node tests/run-e2e.mjs --pause"+},"dependencies": {"@aliasvault/client": "file:../../core/client",diff --git a/apps/web/tests/e2e/04-vault-errors.spec.ts b/apps/web/tests/e2e/04-vault-errors.spec.tsindex 4a6b56654..6c97616e5 100644--- a/apps/web/tests/e2e/04-vault-errors.spec.ts+++ b/apps/web/tests/e2e/04-vault-errors.spec.ts@@ -31,6 +31,9 @@ test.describe('4. Vault errors', () => {await app.page.goto('/user/login');await app.submitLogin(testUser.username, testUser.password);+ await expect(app.page.locator('#critical-error')).toBeVisible();+ await app.pause();+await expect(app.page).toHaveURL(/\/sync$/);await expectCriticalError(app.page, VAULT_DATA_UNREADABLE_MESSAGE, 'E-503');await expect(app.page.locator('#critical-error-report')).toContainText('AES-GCM decryption failed');@@ -43,6 +46,9 @@ test.describe('4. Vault errors', () => {await app.page.goto('/user/login');await app.submitLogin(testUser.username, testUser.password);+ await expect(app.page.locator('#critical-error')).toBeVisible();+ await app.pause();+await expect(app.page).toHaveURL(/\/sync$/);await expectCriticalError(app.page, VAULT_DATA_UNREADABLE_MESSAGE, 'E-508');await expect(app.page.locator('#critical-error-report')).toContainText('NOT NULL constraint failed');@@ -54,6 +60,9 @@ test.describe('4. Vault errors', () => {await app.page.goto('/user/login');await app.submitLogin(user.username, user.password);+ await expect(app.page.locator('#critical-error')).toBeVisible();+ await app.pause();+// The error replaces the login form instead of landing on the unlock page without explanation.await expect(app.page).toHaveURL(/\/user\/login$/);await expectCriticalError(app.page, KEY_CHAIN_UNREADABLE_MESSAGE, 'E-207');@@ -87,6 +96,9 @@ test.describe('4. Vault errors', () => {await app.page.locator('#password').fill(testUser.password);await app.page.locator('#unlock-button').click();+ await expect(app.page.locator('#critical-error')).toBeVisible();+ await app.pause();+await expect(app.page).toHaveURL(/\/unlock$/);await expectCriticalError(app.page, KEY_CHAIN_UNREADABLE_MESSAGE, 'E-207');});diff --git a/apps/web/tests/fixtures/WebApp.ts b/apps/web/tests/fixtures/WebApp.tsindex c4076eaaa..15f61e590 100644--- a/apps/web/tests/fixtures/WebApp.ts+++ b/apps/web/tests/fixtures/WebApp.ts@@ -1,4 +1,4 @@-import { expect, type Locator, type Page } from '@playwright/test';+import { expect, test, type Locator, type Page } from '@playwright/test';/*** Page object for the web app: the user-level flows tests are written in.@@ -55,6 +55,17 @@ export class WebApp {await expect(this.page.locator('#mobileMenuDropdown').getByText(username, { exact: true })).toBeAttached();}+ /**+ * Stop here and open the Playwright Inspector to look at the page, only in a `npm run test:e2e:pause` run; a no-op otherwise.+ */+ public async pause(): Promise<void> {+ if (!process.env.E2E_PAUSE) {+ return;+ }+ test.info().setTimeout(0);+ await this.page.pause();+ }+/*** Create a login item with only a name via the top bar widget, and wait for its view page.*/diff --git a/apps/web/tests/run-e2e.mjs b/apps/web/tests/run-e2e.mjsnew file mode 100644index 000000000..604b90d88--- /dev/null+++ b/apps/web/tests/run-e2e.mjs@@ -0,0 +1,63 @@+/**+ * Runs the Playwright e2e tests, selecting tests by their number.+ *+ * npm run test:e2e all tests+ * npm run test:e2e 4 every test in file 04 (4.x)+ * npm run test:e2e 4.3 test 4.3+ * npm run test:e2e 14.1,14.2 3 tests 14.1 and 14.2, plus every test in file 03+ * npm run test:e2e 14.1-14.3 tests 14.1 up to and including 14.3+ * npm run test:e2e:pause 4.3 headed, stopping at each app.pause() in the Playwright Inspector+ *+ * Numbers become one title filter (--grep), so selections combine as "or". Any other argument goes to Playwright as-is.+ */+import { spawnSync } from 'node:child_process';++const args = process.argv.slice(2);+const env = { ...process.env };+const playwrightArgs = [];+const patterns = [];++for (const arg of args) {+ if (arg === '--pause') {+ env.E2E_PAUSE = '1';+ playwrightArgs.push('--headed', '--workers=1');+ continue;+ }+ const selectors = arg.split(',').filter(Boolean);+ if (selectors.length > 0 && selectors.every(isSelector)) {+ patterns.push(...selectors.flatMap(toPatterns));+ } else {+ playwrightArgs.push(arg);+ }+}++if (patterns.length > 0) {+ // A test title starts with its number ("4.3 should ..."); the leading boundary keeps 4.3 from matching 14.3.+ playwrightArgs.push('--grep', `(^|\\s)(${patterns.join('|')})\\s`);+}++const result = spawnSync('npx', ['playwright', 'test', ...playwrightArgs], { stdio: 'inherit', env, shell: process.platform === 'win32' });+process.exit(result.status ?? 1);++/**+ * Whether an argument selects tests: "4", "4.3" or "4.1-4.3".+ */+function isSelector(value) {+ return /^\d+(\.\d+)?$/.test(value) || /^\d+\.\d+-\d+\.\d+$/.test(value);+}++/**+ * The title patterns a selector stands for.+ */+function toPatterns(selector) {+ const range = selector.match(/^(\d+)\.(\d+)-(\d+)\.(\d+)$/);+ if (range) {+ const [, file, from, toFile, to] = range.map(Number);+ if (file !== toFile || from > to) {+ console.error(`Invalid range "${selector}": use one file, low to high, e.g. 14.1-14.3.`);+ process.exit(1);+ }+ return Array.from({ length: to - from + 1 }, (_, i) => `${file}\\.${from + i}`);+ }+ return selector.includes('.') ? [selector.replace('.', '\\.')] : [`${Number(selector)}\\.\\d+`];+}