From a6fb5ef1cf8466b4e7a519dc61f04a754bbb3697 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sat, 18 Jul 2026 18:15:41 +0300 Subject: [PATCH] fix: preserve specific error message on unexpected test exceptions The outer catch's overwrite guard checked `!outcome.error`, but outcome.error is always truthy (even the default placeholder string), so an exception occurring outside the two explicitly-guarded blocks (e.g. a .fill()/.click() timeout) would leave the generic "Test did not complete" message instead of the real error. Replaced with an explicit outcomeFinalized sentinel that is set exactly where outcome is deliberately finalized (missing env var, login timeout, post-submission timeout, success), so any other exception correctly falls through to the catch-all branch with its real message. --- sidecars/reddit-post/tests/reddit-post.spec.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sidecars/reddit-post/tests/reddit-post.spec.js b/sidecars/reddit-post/tests/reddit-post.spec.js index bdd6677..f540bc6 100644 --- a/sidecars/reddit-post/tests/reddit-post.spec.js +++ b/sidecars/reddit-post/tests/reddit-post.spec.js @@ -12,6 +12,7 @@ function writeResult(result) { test.describe('reddit post', () => { let outcome = { success: false, error: 'Test did not complete' }; + let outcomeFinalized = false; test.afterEach(async () => { writeResult(outcome); @@ -33,6 +34,7 @@ test.describe('reddit post', () => { })) { if (!value) { outcome = { success: false, error: `Missing required environment variable: ${name}` }; + outcomeFinalized = true; throw new Error(outcome.error); } } @@ -51,6 +53,7 @@ test.describe('reddit post', () => { success: false, error: 'Login did not complete — possible CAPTCHA, 2FA prompt, or invalid credentials', }; + outcomeFinalized = true; throw new Error(outcome.error); } @@ -75,13 +78,15 @@ test.describe('reddit post', () => { await page.waitForURL(/\/comments\//, { timeout: 20_000 }); } catch { outcome = { success: false, error: 'Post submission did not complete — no redirect to the new post' }; + outcomeFinalized = true; throw new Error(outcome.error); } outcome = { success: true, url: page.url() }; + outcomeFinalized = true; expect(outcome.success).toBe(true); } catch (err) { - if (outcome.success !== false || !outcome.error) { + if (!outcomeFinalized) { outcome = { success: false, error: err instanceof Error ? err.message : String(err) }; } throw err;