Add test failure screenshot option. - #6171
michelinewu wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The generated screenshot filename can become empty for non-ASCII test titles, producing paths like .png and risking confusing/overwritten artifacts.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds an opt-in mechanism to capture the app’s UI state at the moment an AVA e2e test fails, to improve failure debugging without impacting normal test runs.
Changes:
- Introduces
saveFailureScreenshot()gated bySLOBS_FAIL_SCREENSHOT_DIR. - Hooks screenshot capture into
test.afterEach.alwaysbefore teardown stops the app.
File summaries
| File | Description |
|---|---|
test/helpers/webdriver/index.ts |
Adds an opt-in failure-screenshot helper and calls it during afterEach.always before teardown. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
BundleMonUnchanged files (4)
No change in files bundle size Final result: ✅ View report in BundleMon website ➡️ |
wesrupert
left a comment
There was a problem hiding this comment.
+1 on current suggestion, otherwise LGTM
There was a problem hiding this comment.
🟡 Changes recommended
Resolve the filename collision, startup-hook coverage, and hook-title normalization issues.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (2)
test/helpers/webdriver/index.ts:492
appIsRunningis only set afterwaitForLoader, onboarding, and the remaining startup steps complete. If one of those steps fails afterApplication.start()has already connected the WebDriver client, this condition is false and the failing test gets no screenshot even though the app UI is available. Gate on the initialized client (or mark the app running immediately afterstart) so startup-hook failures are covered too.
if (!testPassed && appIsRunning) await saveFailureScreenshot(t);
test/helpers/webdriver/index.ts:232
- AVA supplies hook callbacks with a hook-qualified
t.title; the existingbeforeEachcode stripsbeforeEach hook forat line 466, andtest/screentest/screenshoter.ts:72stripsafterEach hook for. Using the raw title here therefore produces names such asaftereach-hook-for-...instead of the test title promised by this option. Strip theafterEach/afterEach.alwayshook prefix before normalizing.
const parsedTitle = t.title
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
| const imgTitle = parsedTitle || `test-failure${Date.now()}`; | ||
|
|
||
| fs.mkdirSync(dir, { recursive: true }); | ||
| const filePath = path.join(dir, `${imgTitle}.png`); |
Capture a Screenshot of the App When an E2E Test Fails
Issues
Speed up debugging by recording what the app actually looked like at the moment of failure.
Fixes
Added
saveFailureScreenshot()totest/helpers/webdriver/index.ts, called fromafterEach.alwaysright before the existing teardown stops the app — the last point at which the failing UI still exists. Opt-in viaSLOBS_FAIL_SCREENSHOT_DIR, so a normal test run captures nothing and is unaffected. Files are named after the test title (kebab-cased, truncated to 80 chars). The capture is wrapped in try/catch and never throws, so a failed screenshot can't mask or replace the real test failure.File(s) changed:
test/helpers/webdriver/index.tsPerformance Implications
None on a normal test run — the function returns immediately unless
SLOBS_FAIL_SCREENSHOT_DIRis set. When enabled, adds one screenshot capture per failing test, on the already-failing path.