Skip to content

Commit 6481428

Browse files
authored
fix(desktop): resolve flaky integration tests via project-level assertion timeout (#812)
1 parent 93183cb commit 6481428

11 files changed

Lines changed: 38 additions & 57 deletions

File tree

‎desktop/playwright.config.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export default defineConfig({
4848
use: {
4949
...devices["Desktop Chrome"],
5050
},
51+
expect: {
52+
timeout: process.env.CI ? 15_000 : 10_000,
53+
},
5154
},
5255
],
5356
webServer: {

‎desktop/src/features/channels/useActiveChannelHeader.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function useActiveChannelHeader(
1111
currentPubkey?: string,
1212
) {
1313
const activeDmParticipantPubkeys = React.useMemo(() => {
14-
if (!activeChannel || activeChannel.channelType !== "dm") {
14+
if (activeChannel?.channelType !== "dm") {
1515
return [];
1616
}
1717

‎desktop/src/features/messages/ui/TypingIndicatorRow.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type TypingIndicatorRowProps = {
1818
};
1919

2020
function resolveFallbackName(channel: Channel | null, pubkey: string) {
21-
if (!channel || channel.channelType !== "dm") {
21+
if (channel?.channelType !== "dm") {
2222
return null;
2323
}
2424

‎desktop/src/features/sidebar/lib/channelSectionsHelpers.test.mjs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ test("move up succeeds: middle section swaps order with the one above", () => {
2020
const result = swapSectionOrder(store, "b", "up");
2121
assert.notEqual(result, null);
2222
const byId = Object.fromEntries(result.sections.map((s) => [s.id, s.order]));
23-
assert.equal(byId["b"], 0);
24-
assert.equal(byId["a"], 1);
25-
assert.equal(byId["c"], 2);
23+
assert.equal(byId.b, 0);
24+
assert.equal(byId.a, 1);
25+
assert.equal(byId.c, 2);
2626
});
2727

2828
test("move down succeeds: middle section swaps order with the one below", () => {
@@ -34,9 +34,9 @@ test("move down succeeds: middle section swaps order with the one below", () =>
3434
const result = swapSectionOrder(store, "b", "down");
3535
assert.notEqual(result, null);
3636
const byId = Object.fromEntries(result.sections.map((s) => [s.id, s.order]));
37-
assert.equal(byId["b"], 2);
38-
assert.equal(byId["c"], 1);
39-
assert.equal(byId["a"], 0);
37+
assert.equal(byId.b, 2);
38+
assert.equal(byId.c, 1);
39+
assert.equal(byId.a, 0);
4040
});
4141

4242
test("move up at top boundary returns null", () => {
@@ -73,7 +73,7 @@ test("non-contiguous orders: swap uses actual order values not indices", () => {
7373
const result = swapSectionOrder(store, "b", "up");
7474
assert.notEqual(result, null);
7575
const byId = Object.fromEntries(result.sections.map((s) => [s.id, s.order]));
76-
assert.equal(byId["b"], 0);
77-
assert.equal(byId["a"], 5);
78-
assert.equal(byId["c"], 10);
76+
assert.equal(byId.b, 0);
77+
assert.equal(byId.a, 5);
78+
assert.equal(byId.c, 10);
7979
});

‎desktop/src/features/user-status/hooks.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function useUserStatusSubscription() {
9090
function handleStatusEvent(event: RelayEvent) {
9191
if (isCancelled) return;
9292
const dTag = event.tags.find((t) => t[0] === "d");
93-
if (!dTag || dTag[1] !== "general") return;
93+
if (dTag?.[1] !== "general") return;
9494
const parsed = parseUserStatusEvent(event);
9595
const status: UserStatus | null =
9696
parsed.text || parsed.emoji

‎desktop/src/shared/api/relayClientSession.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ export class RelayClient {
564564

565565
return async () => {
566566
const active = this.subscriptions.get(subId);
567-
if (!active || active.mode !== "live") {
567+
if (active?.mode !== "live") {
568568
return;
569569
}
570570

‎desktop/src/shared/ui/markdownFileCard.test.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { resolveFileCard } from "./markdownFileCard.ts";
66
// A generic-file URL (non-media extension) does not match the relay-media
77
// proxy regex, so `rewriteRelayUrl` passes it through unchanged — assertions
88
// can compare hrefs directly.
9-
const PDF_URL = "https://relay.example/media/" + "a".repeat(64) + ".pdf";
9+
const PDF_URL = `https://relay.example/media/${"a".repeat(64)}.pdf`;
1010

1111
test("resolveFileCard: returns null when there is no imeta entry", () => {
1212
assert.equal(resolveFileCard(undefined, PDF_URL, ""), null);
@@ -62,12 +62,12 @@ test("resolveFileCard: falls back to link child text when imeta has no filename"
6262

6363
test("resolveFileCard: falls back to URL tail when no filename or child text", () => {
6464
const card = resolveFileCard({ m: "application/octet-stream" }, PDF_URL, "");
65-
assert.equal(card?.filename, "a".repeat(64) + ".pdf");
65+
assert.equal(card?.filename, `${"a".repeat(64)}.pdf`);
6666
});
6767

6868
test("resolveFileCard: octet-stream (no magic bytes) is treated as a file", () => {
6969
// Text/code/data upload with no magic signature — the Slack-like case.
70-
const url = "https://relay.example/media/" + "b".repeat(64) + ".txt";
70+
const url = `https://relay.example/media/${"b".repeat(64)}.txt`;
7171
const card = resolveFileCard(
7272
{ m: "application/octet-stream", filename: "notes.txt" },
7373
url,

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4298,7 +4298,7 @@ function resolveMockUploadDescriptors(
42984298
if (configured !== undefined) return configured;
42994299
return [
43004300
{
4301-
url: "https://mock.relay/media/" + "a".repeat(64) + ".pdf",
4301+
url: `https://mock.relay/media/${"a".repeat(64)}.pdf`,
43024302
sha256: "a".repeat(64),
43034303
size: 12345,
43044304
type: "application/pdf",

‎desktop/tests/e2e/integration.spec.ts‎

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { assertRelaySeeded } from "../helpers/seed";
66

77
const isCi = Boolean(process.env.CI);
88
const relaySeedHookTimeoutMs = isCi ? 90_000 : 30_000;
9-
const relayDeliveryTimeoutMs = isCi ? 15_000 : 10_000;
109

1110
async function createStream(
1211
page: import("@playwright/test").Page,
@@ -276,11 +275,7 @@ test("live mentions refetch the home feed without waiting for polling", async ({
276275
message,
277276
);
278277

279-
await expect
280-
.poll(() => getLoggedNotificationCount(targetPage), {
281-
timeout: relayDeliveryTimeoutMs,
282-
})
283-
.toBe(1);
278+
await expect.poll(() => getLoggedNotificationCount(targetPage)).toBe(1);
284279

285280
const notifications = await getLoggedNotifications(targetPage);
286281

@@ -300,14 +295,9 @@ test("live mentions refetch the home feed without waiting for polling", async ({
300295
await expect(targetPage.getByTestId("home-inbox-list")).toBeVisible();
301296
await expect(targetPage.getByTestId("home-inbox-list")).toContainText(
302297
message,
303-
{ timeout: relayDeliveryTimeoutMs },
304298
);
305299
await expect(targetPage.getByTestId("sidebar-home-count")).toHaveCount(0);
306-
await expect
307-
.poll(() => getLoggedNotificationCount(targetPage), {
308-
timeout: relayDeliveryTimeoutMs,
309-
})
310-
.toBe(1);
300+
await expect.poll(() => getLoggedNotificationCount(targetPage)).toBe(1);
311301
} finally {
312302
await targetContext.close();
313303
await senderContext.close();
@@ -345,15 +335,9 @@ test("live forum mentions refetch the home feed without waiting for polling", as
345335
mentionPubkeys: [TEST_IDENTITIES.tyler.pubkey],
346336
});
347337

348-
await expect(targetPage.getByTestId("sidebar-home-count")).toHaveText("1", {
349-
timeout: relayDeliveryTimeoutMs,
350-
});
338+
await expect(targetPage.getByTestId("sidebar-home-count")).toHaveText("1");
351339

352-
await expect
353-
.poll(() => getLoggedNotificationCount(targetPage), {
354-
timeout: relayDeliveryTimeoutMs,
355-
})
356-
.toBe(1);
340+
await expect.poll(() => getLoggedNotificationCount(targetPage)).toBe(1);
357341

358342
const notifications = await getLoggedNotifications(targetPage);
359343

@@ -371,11 +355,7 @@ test("live forum mentions refetch the home feed without waiting for polling", as
371355
message,
372356
);
373357
await expect(targetPage.getByTestId("sidebar-home-count")).toHaveCount(0);
374-
await expect
375-
.poll(() => getLoggedNotificationCount(targetPage), {
376-
timeout: relayDeliveryTimeoutMs,
377-
})
378-
.toBe(1);
358+
await expect.poll(() => getLoggedNotificationCount(targetPage)).toBe(1);
379359
} finally {
380360
await targetContext.close();
381361
await senderContext.close();

‎desktop/tests/e2e/stream.spec.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import { installRelayBridge, TEST_IDENTITIES } from "../helpers/bridge";
44
import { assertRelaySeeded } from "../helpers/seed";
55

66
const isCi = Boolean(process.env.CI);
7-
const relayDeliveryTimeoutMs = isCi ? 15_000 : 5_000;
87
const relaySeedHookTimeoutMs = isCi ? 90_000 : 30_000;
98

109
async function expectTimelineToContain(page: Page, text: string) {
11-
await expect(page.getByTestId("message-timeline")).toContainText(text, {
12-
timeout: relayDeliveryTimeoutMs,
13-
});
10+
await expect(page.getByTestId("message-timeline")).toContainText(text);
1411
}
1512

1613
async function getTimelineMetrics(page: Page) {
@@ -178,9 +175,7 @@ test("loads the home feed from the relay", async ({ browser }) => {
178175
mentionPubkeys: [TEST_IDENTITIES.tyler.pubkey],
179176
});
180177

181-
await expect(page.getByTestId("home-inbox-list")).toContainText(message, {
182-
timeout: relayDeliveryTimeoutMs,
183-
});
178+
await expect(page.getByTestId("home-inbox-list")).toContainText(message);
184179
await expect(page.getByTestId("home-inbox-detail")).toBeVisible();
185180
} finally {
186181
await targetContext.close();
@@ -210,9 +205,7 @@ test("shows sent inbox replies immediately in the inbox detail pane", async ({
210205
mentionPubkeys: [TEST_IDENTITIES.tyler.pubkey],
211206
});
212207

213-
await page.getByTestId("home-inbox-list").getByText(message).click({
214-
timeout: relayDeliveryTimeoutMs,
215-
});
208+
await page.getByTestId("home-inbox-list").getByText(message).click();
216209
await expect(page.getByTestId("home-inbox-detail")).toBeVisible();
217210
await expect(page.getByTestId("message-input")).toBeEnabled();
218211

0 commit comments

Comments
 (0)