test(e2e): replace unchecked lookups, widen the assertion timeout, restore the skipped test (#241)

Tasks 2 to 4 of the plan. Nine `collection.find(...)` dereferences become findOrFail, so a missing row fails as a named assertion naming what was wanted and how many rows were searched, rather than "Cannot read properties of undefined" pointing at test plumbing. Where the old code followed the lookup with expect(x).toBeTruthy(), that assertion is dropped: findOrFail already guarantees it, and with a better message.

The expect timeout goes from Playwright's default 5s to 10s. It costs nothing on a green run — it bounds how long a failing assertion waits, not how long a passing one takes — and #239 died reporting exactly Timeout: 5000ms on a runner that also builds, migrates and runs three other suites.

The admin-save happy path comes back from the #245 skip. It is the only end-to-end check that adding an item reaches the database rather than merely firing a toast, and it passed both full parallel runs and in isolation.

filters.spec.ts:216 is deliberately untouched: its .find() searches CSS class names on a string array, not test data, and has no missing-row failure mode.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-31 20:04:43 -05:00
co-authored by Claude Opus 5
parent 93a451dbf0
commit 895c08d1a7
7 changed files with 69 additions and 33 deletions
@@ -1,4 +1,4 @@
import { test, expect, createItem, uniqueSuffix } from './fixtures';
import { test, expect, createItem, uniqueSuffix, findOrFail } from './fixtures';
test.describe('Disabling a customer account', () => {
test('an admin can disable an account and the customer is told at sign-in', async ({
@@ -34,7 +34,11 @@ test.describe('Disabling a customer account', () => {
await expect(accountModal.emailText(customer.email)).toBeVisible();
const customers = await (await request.get('/api/admin/customers')).json();
const id = customers.find((c: { email: string }) => c.email === customer.email).id;
const id = findOrFail(
customers,
(c: { email: string }) => c.email === customer.email,
`the customer ${customer.email}`
).id;
await request.post(`/api/admin/customers/${id}/disable`);
// The cookie is unchanged, so this proves the server rejects it rather
@@ -53,7 +57,11 @@ test.describe('Disabling a customer account', () => {
header
}) => {
const customers = await (await request.get('/api/admin/customers')).json();
const id = customers.find((c: { email: string }) => c.email === customer.email).id;
const id = findOrFail(
customers,
(c: { email: string }) => c.email === customer.email,
`the customer ${customer.email}`
).id;
await request.post(`/api/admin/customers/${id}/disable`);
await admin.open('Customers');
@@ -1,4 +1,4 @@
import { test, expect, uniqueSuffix, createCategory } from './fixtures';
import { test, expect, uniqueSuffix, createCategory, findOrFail } from './fixtures';
test.describe('Inline category creation from the item form', () => {
test('creates a category without leaving the item form and assigns it', async ({
@@ -32,8 +32,13 @@ test.describe('Inline category creation from the item form', () => {
await expect(page.getByText('Item added')).toBeVisible();
const items = await (await page.request.get('/api/admin/items')).json();
const saved = items.find((item: { name: string }) => item.name === itemName);
expect(saved).toBeTruthy();
// findOrFail already fails with the row count when the item is missing,
// which the toBeTruthy assertion this replaces could not report.
const saved = findOrFail(
items,
(item: { name: string }) => item.name === itemName,
`the item named ${itemName}`
);
expect(saved.category_name).toBe(categoryName);
});
+5 -17
View File
@@ -59,23 +59,11 @@ test.describe('Admin save failures', () => {
await expect(adminInventory.row(name)).toBeVisible();
});
// SKIPPED, temporarily, to get main green while #241 is outstanding. See #245
// before deleting this comment or the skip.
//
// It fails in CI and passes locally, and which test fails moves around: a
// local parallel run of the whole suite on the same commit failed four
// *different* specs and not this one. That is #241 — fullyParallel against a
// single shared database — so fixing this test on its own would be guessing at
// a symptom that will simply reappear somewhere else.
//
// Not the image work from #226: addItem fills a name and a price and saves,
// attaching nothing, so the re-encoding path is never entered here.
//
// What this stops covering is not trivial. It is the only end-to-end check
// that adding an item actually reaches the database rather than just firing a
// toast — the happy path of the core admin action. Un-skip it as soon as #241
// lands; if it still fails then, it is a real defect and worth chasing.
test.skip('saves an item successfully when the server accepts it', async ({
// Un-skipped now that #241 has landed (was skipped under #245). This is the
// only end-to-end check that adding an item actually reaches the database
// rather than just firing a toast — the happy path of the core admin action —
// so it is worth having back.
test('saves an item successfully when the server accepts it', async ({
page,
admin,
adminInventory
+6 -3
View File
@@ -1,4 +1,4 @@
import { test, expect, uniqueSuffix } from './fixtures';
import { test, expect, uniqueSuffix, findOrFail } from './fixtures';
// The e2e database is shared and never reset, so every fixture name carries a
// unique suffix and assertions are scoped to the nodes this run created. The
@@ -41,8 +41,11 @@ test.describe('Admin taxonomy', () => {
// The table paginates and the shared database holds many tags, so the new
// row is confirmed through the API rather than hunted for across pages.
const tags = await (await page.request.get('/api/admin/tags')).json();
const created = tags.find((tag: { name: string }) => tag.name === `vintage-${RUN}`);
expect(created).toBeTruthy();
const created = findOrFail(
tags,
(tag: { name: string }) => tag.name === `vintage-${RUN}`,
`the tag vintage-${RUN}`
);
expect(created.color).toBeTruthy();
});
+21 -5
View File
@@ -1,4 +1,4 @@
import { test, expect, uniqueSuffix } from './fixtures';
import { test, expect, uniqueSuffix, findOrFail } from './fixtures';
// Each test leaves the templates as it found them, because they are stored in
// admin_settings and would otherwise change the copy a later test reads.
@@ -51,7 +51,11 @@ test.describe('Editing the customer emails', () => {
// Persisted, not merely accepted by the form.
const stored = await (await page.request.get('/api/admin/email-templates')).json();
const reset = stored.find((t: { key: string }) => t.key === 'passwordReset');
const reset = findOrFail(
stored,
(t: { key: string }) => t.key === 'passwordReset',
'the passwordReset template'
);
expect(reset.subject).toBe(subject);
});
@@ -69,7 +73,11 @@ test.describe('Editing the customer emails', () => {
// And nothing was stored.
const stored = await (await page.request.get('/api/admin/email-templates')).json();
const reset = stored.find((t: { key: string }) => t.key === 'passwordReset');
const reset = findOrFail(
stored,
(t: { key: string }) => t.key === 'passwordReset',
'the passwordReset template'
);
expect(reset.body).toBeNull();
});
@@ -88,7 +96,11 @@ test.describe('Editing the customer emails', () => {
await expect(page.getByText('Password reset restored to the default')).toBeVisible();
const stored = await (await page.request.get('/api/admin/email-templates')).json();
const reset = stored.find((t: { key: string }) => t.key === 'passwordReset');
const reset = findOrFail(
stored,
(t: { key: string }) => t.key === 'passwordReset',
'the passwordReset template'
);
expect(reset.subject).toBeNull();
expect(reset.body).toBeNull();
});
@@ -113,7 +125,11 @@ test.describe('Previewing the customer emails', () => {
await expect(adminEmails.preview('Password reset').getByText(wording)).toBeVisible();
const stored = await (await page.request.get('/api/admin/email-templates')).json();
expect(stored.find((t: { key: string }) => t.key === 'passwordReset').body).toBeNull();
expect(findOrFail(
stored,
(t: { key: string }) => t.key === 'passwordReset',
'the passwordReset template'
).body).toBeNull();
});
test('substitutes sample values rather than showing raw placeholders', async ({ page, admin, adminEmails }) => {
+7 -2
View File
@@ -8,7 +8,8 @@ import {
uniqueEmail,
PASSWORD,
StorefrontPage,
FavoritePrompt
FavoritePrompt,
findOrFail
} from './fixtures';
// The storefront runs against a shared database that is never reset, so every
@@ -178,7 +179,11 @@ test.describe('Filtering the storefront by favorites', () => {
const api = await createAdminContext(playwright);
const items = await (await api.get('/api/items')).json();
const sells = items.find((item: { name: string }) => item.name === SELLS);
const sells = findOrFail(
items,
(item: { name: string }) => item.name === SELLS,
`the item named ${SELLS}`
);
await sellItem(api, sells.id);
await api.dispose();