reporting-labs 0.6.22 → 0.6.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  <p align="center">
4
4
  <a href="https://www.npmjs.com/package/reporting-labs"><img src="https://img.shields.io/npm/v/reporting-labs.svg?label=npm" alt="npm"></a>
5
+ <a href="https://npm-stat.com/charts.html?package=reporting-labs&from=2026-09-18"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fnaveenautomationlabs.github.io%2Freporting-labs%2Fbadges%2Fnpm-downloads.json" alt="npm downloads"></a>
5
6
  <a href="https://reportinglabs.dev"><img src="https://img.shields.io/badge/docs-reportinglabs.dev-1A56DB.svg" alt="Docs"></a>
6
7
  <a href="https://reportinglabs.dev/support"><img src="https://img.shields.io/badge/%E2%99%A5%20Support-reportingLabs-E5405E?style=flat" alt="Support reportingLabs"></a>
7
8
  </p>
@@ -228,6 +229,10 @@ Each call shows in the test detail and in the **API** tab with method, URL, stat
228
229
 
229
230
  If you do not use the config file, add `import 'reporting-labs/auto'` at the top of `playwright.config.ts` instead.
230
231
 
232
+ ### What the browser saw
233
+
234
+ The same import also listens to the browser while a test runs. Uncaught JavaScript errors from the app, `console.error` messages and requests that failed or got a 4xx/5xx are recorded with their time. On a failed test they show under **What the browser saw**, timed against the failure ("HTTP 500 · POST /api/cart/coupon · 3.0s before the failure", "JS error · Cannot read properties of undefined"), so a UI failure caused by the backend or by a crash in the app reads as that, not as "element not found".
235
+
231
236
  Only calls that do not go through Playwright (Node `fetch`, axios, a Java service) need a manual record:
232
237
 
233
238
  ```ts
@@ -312,6 +317,7 @@ are right; data tables and the steps left unrun need 8+.
312
317
  ### Failures: everything you need to triage
313
318
 
314
319
  - **Bug report** button on every failed test: a ready-to-paste ticket with priority, owner, story, environment, test data, steps to reproduce (taken from the test's own steps, the failing one marked), expected vs actual, the error, API calls and attachment names. Pick Markdown, Jira or plain text, edit if you like, copy or download.
320
+ - **Video in step with the test**: with `video` on, a test's video sits above its steps. Click ▶ on any step to watch that moment, or **Watch the failure** to see the 5 seconds before it; the step playing lights up as the video runs. A popup or second tab has its own recording, and every player follows the steps.
315
321
  - **Run again**: every test shows the command that runs just that test, with a Copy button, e.g. `npx playwright test tests/checkout.spec.ts:12 --project=chromium`. **Copy re-run command** on the Failures tab does the same for all failed tests at once. With playwright-bdd it runs `npx bddgen` first; Cypress and WebdriverIO re-run the spec file (`--spec`).
316
322
  - **By owner**: who to ping, with failed and flaky counts. Click an owner to filter.
317
323
  - **Download CSV / JSON**: all failed and flaky tests with title, spec, project, priority, owner, ticket, attempts, duration, first error line and new/known status. Ready for Jira or a sheet.
package/dist/auto.js CHANGED
@@ -154,6 +154,79 @@ function patchContext(ctx) {
154
154
  };
155
155
  proto[PATCHED] = true;
156
156
  }
157
+ /* ---------- what the browser saw ---------- */
158
+ const WATCHED = '__reportingLabsBrowserEvents';
159
+ const MAX_EVENTS = 50; // per test attempt: a page that logs an error every frame stays readable
160
+ const seen = new Map();
161
+ const oneLine = (s, max = 2000) => String(s ?? '').replace(/\u001b\[[0-9;]*m/g, '').slice(0, max);
162
+ /** One browser event, attached to the running test with its time. Nothing while no test runs. */
163
+ function note(ev) {
164
+ const info = currentTest();
165
+ if (!info)
166
+ return;
167
+ const key = info.testId + ':' + info.retry;
168
+ const n = (seen.get(key) ?? 0) + 1;
169
+ seen.set(key, n);
170
+ if (n > MAX_EVENTS)
171
+ return;
172
+ info.attach('rl:browser', { body: JSON.stringify({ t: Date.now(), ...ev }), contentType: 'application/x-rl-browser' }).catch(() => { });
173
+ }
174
+ /** A recorded page opened. Playwright names the test's videos video.webm, video-1.webm, ... in the order their pages
175
+ * opened, so the n-th note here is when video n starts: the report can then play a popup's recording in step too. */
176
+ const pagesSeen = new Map();
177
+ function notePage() {
178
+ const info = currentTest();
179
+ if (!info)
180
+ return;
181
+ const key = info.testId + ':' + info.retry;
182
+ const i = pagesSeen.get(key) ?? 0;
183
+ pagesSeen.set(key, i + 1);
184
+ info.attach('rl:page', { body: JSON.stringify({ i, t: Date.now() }), contentType: 'application/x-rl-page' }).catch(() => { });
185
+ }
186
+ /** Listen to a browser context: uncaught page errors, console.error, and requests that failed or got 4xx/5xx. */
187
+ function watchContext(ctx) {
188
+ if (!ctx || typeof ctx.on !== 'function' || ctx[WATCHED])
189
+ return;
190
+ ctx[WATCHED] = true;
191
+ const onPage = (page) => {
192
+ if (safe(() => page.video()))
193
+ notePage();
194
+ page.on('pageerror', (err) => note({ kind: 'error', text: oneLine(err?.message || err), stack: oneLine(err?.stack, 4000), url: safe(() => page.url()) }));
195
+ page.on('console', (msg) => {
196
+ if (msg.type() !== 'error')
197
+ return;
198
+ // the browser's own note for a request that got 4xx/5xx: the request is already listed
199
+ if (/^Failed to load resource\b/.test(String(msg.text())))
200
+ return;
201
+ const loc = safe(() => msg.location());
202
+ note({ kind: 'console', text: oneLine(msg.text()), url: loc?.url ? `${loc.url}${loc.lineNumber ? ':' + loc.lineNumber : ''}` : undefined });
203
+ });
204
+ };
205
+ try {
206
+ for (const p of ctx.pages())
207
+ onPage(p);
208
+ }
209
+ catch { /* no pages yet */ }
210
+ ctx.on('page', onPage);
211
+ ctx.on('requestfailed', (req) => {
212
+ const why = safe(() => req.failure()?.errorText);
213
+ if (why && /ERR_ABORTED|NS_BINDING_ABORTED|cancelled/i.test(why))
214
+ return; // navigating away, not an app problem
215
+ note({ kind: 'request', method: req.method(), url: req.url(), text: why || 'Request failed' });
216
+ });
217
+ ctx.on('response', (res) => {
218
+ const status = res.status();
219
+ if (status < 400 || /\/favicon\.ico(\?|$)/.test(res.url()))
220
+ return;
221
+ note({ kind: 'request', method: safe(() => res.request().method()), url: res.url(), status, text: safe(() => res.statusText()) || '' });
222
+ });
223
+ }
224
+ function safe(fn) { try {
225
+ return fn();
226
+ }
227
+ catch {
228
+ return undefined;
229
+ } }
157
230
  /** Wrap `obj[name]` (found on the prototype chain) so `after(result)` sees each resolved return value. */
158
231
  function wrapAsync(obj, name, after) {
159
232
  let proto = obj;
@@ -198,11 +271,14 @@ function install() {
198
271
  const onBrowser = (browser) => {
199
272
  if (!browser || typeof browser.newContext !== 'function')
200
273
  return;
201
- wrapAsync(browser, 'newContext', ctx => ctx?.request && patchContext(ctx.request));
274
+ wrapAsync(browser, 'newContext', ctx => { if (ctx?.request)
275
+ patchContext(ctx.request); watchContext(ctx); });
202
276
  try {
203
- for (const ctx of browser.contexts())
277
+ for (const ctx of browser.contexts()) {
204
278
  if (ctx?.request)
205
279
  patchContext(ctx.request);
280
+ watchContext(ctx);
281
+ }
206
282
  }
207
283
  catch { /* not a browser */ }
208
284
  };
@@ -212,7 +288,8 @@ function install() {
212
288
  wrapAsync(bt, 'launch', onBrowser);
213
289
  wrapAsync(bt, 'connect', onBrowser);
214
290
  wrapAsync(bt, 'connectOverCDP', onBrowser);
215
- wrapAsync(bt, 'launchPersistentContext', ctx => ctx?.request && patchContext(ctx.request));
291
+ wrapAsync(bt, 'launchPersistentContext', ctx => { if (ctx?.request)
292
+ patchContext(ctx.request); watchContext(ctx); });
216
293
  }
217
294
  }
218
295
  install();
@@ -61,7 +61,10 @@ export default class ReportingLabsReporter implements Reporter {
61
61
  private serializeError;
62
62
  private outcome;
63
63
  private titlePath;
64
+ /** A video's first frame: Playwright saves the n-th recorded page of a test as video-n.webm (the first as video.webm). */
65
+ private withVideoStart;
64
66
  private serializeResult;
67
+ private browserEvent;
65
68
  private serializeStep;
66
69
  private serializeAttachment;
67
70
  }
package/dist/reporter.js CHANGED
@@ -52,7 +52,7 @@ const comments_1 = require("./comments");
52
52
  const DEFAULT_EMBED_LIMIT = 2 * 1024 * 1024;
53
53
  /** Attach steps created by log() and the automatic API capture; the data shows in its own section, so hide the step. */
54
54
  function isInternalAttach(s) {
55
- return s.category === 'test.attach' && /^Attach "(rl:log|(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS) )/.test(s.title);
55
+ return s.category === 'test.attach' && /^Attach "(rl:log|rl:browser|rl:page|(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS) )/.test(s.title);
56
56
  }
57
57
  /** Playwright 1.63+ moved the target out of the title: title `Click`, subtitle `getByRole('button')`; title `Navigate`,
58
58
  * subtitle `/login`. Put it back next to the title, as the report showed before. A test.step's own subtitle and
@@ -621,9 +621,18 @@ class ReportingLabsReporter {
621
621
  }
622
622
  return parts;
623
623
  }
624
+ /** A video's first frame: Playwright saves the n-th recorded page of a test as video-n.webm (the first as video.webm). */
625
+ withVideoStart(out, a, pageOpened) {
626
+ if (!out || !a.path || !a.contentType.startsWith('video/'))
627
+ return out;
628
+ const m = /^video(?:-(\d+))?\.webm$/.exec(path.basename(a.path));
629
+ const t = m ? pageOpened[m[1] ? Number(m[1]) : 0] : undefined;
630
+ return t != null ? { ...out, videoStart: t } : out;
631
+ }
624
632
  serializeResult(r, test) {
625
- const logs = [], data = [], api = [];
633
+ const logs = [], data = [], api = [], browser = [];
626
634
  const normal = [];
635
+ const pageOpened = []; // when each recorded page opened, in order (reporting-labs/auto)
627
636
  for (const a of r.attachments) {
628
637
  const body = a.body ?? (a.path && fs.existsSync(a.path) ? fs.readFileSync(a.path) : undefined);
629
638
  if (a.contentType === 'application/x-rl-log' && body) {
@@ -641,6 +650,22 @@ class ReportingLabsReporter {
641
650
  catch { /* ignore */ }
642
651
  continue;
643
652
  }
653
+ if (a.contentType === 'application/x-rl-page' && body) {
654
+ try {
655
+ const pg = JSON.parse(body.toString());
656
+ if (Number.isInteger(pg.i) && typeof pg.t === 'number')
657
+ pageOpened[pg.i] = pg.t;
658
+ }
659
+ catch { /* ignore */ }
660
+ continue;
661
+ }
662
+ if (a.contentType === 'application/x-rl-browser' && body) {
663
+ try {
664
+ browser.push(this.browserEvent(JSON.parse(body.toString())));
665
+ }
666
+ catch { /* ignore */ }
667
+ continue;
668
+ }
644
669
  if (a.contentType === 'application/x-rl-data' && body) {
645
670
  data.push(this.toDataBlock(a.name, body.toString()));
646
671
  continue;
@@ -668,16 +693,22 @@ class ReportingLabsReporter {
668
693
  workerIndex: r.parallelIndex,
669
694
  errors: r.errors.map(e => this.serializeError(e)),
670
695
  steps: r.steps.filter(s => !isInternalAttach(s)).map(s => this.serializeStep(s)),
671
- attachments: normal.map(a => this.serializeAttachment(a, test)).filter(Boolean),
696
+ attachments: normal.map(a => this.withVideoStart(this.serializeAttachment(a, test), a, pageOpened)).filter(Boolean),
672
697
  stdout: r.stdout.map(c => this.masker.maskStr(stripAnsi(c.toString()))),
673
698
  stderr: r.stderr.map(c => this.masker.maskStr(stripAnsi(c.toString()))),
699
+ ...(browser.length ? { browser: browser.sort((x, y) => x.t - y.t) } : {}),
674
700
  };
675
701
  }
702
+ browserEvent(e) {
703
+ const m = (s) => (s == null ? undefined : this.masker.maskStr(String(s)));
704
+ return { t: Number(e.t) || 0, kind: e.kind, text: m(e.text) ?? '', url: m(e.url), method: e.method, status: e.status, stack: m(e.stack) };
705
+ }
676
706
  serializeStep(s) {
677
707
  return {
678
708
  title: this.masker.maskStr(stepTitle(s)),
679
709
  category: s.category,
680
710
  duration: s.duration,
711
+ start: s.startTime.getTime(),
681
712
  error: s.error?.message ? this.masker.maskStr(stripAnsi(s.error.message)) : undefined,
682
713
  steps: s.steps.filter(c => !isInternalAttach(c)).map(c => this.serializeStep(c)),
683
714
  };
@@ -316,6 +316,7 @@ li.collapsed>ul{display:none}
316
316
  .vids figure{margin:0;border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;background:#000}
317
317
  .vids video{width:100%;display:block;max-height:420px;background:#000}
318
318
  .vids figcaption{font:11px var(--mono);padding:6px 8px;color:var(--ink-2);background:var(--surface-2)}
319
+ .vids figure{transition:opacity .2s} .vids figure.off{opacity:.45}
319
320
  .trace-card{border:1px solid var(--line);border-radius:var(--radius);padding:12px 14px;display:flex;flex-direction:column;gap:8px;font-size:13px}
320
321
  .trace-how{color:var(--ink-2);font-size:12px} .trace-how code{font:12px var(--mono);background:var(--surface-2);padding:1px 5px;border-radius:3px}
321
322
  .trace-card .dl{align-self:flex-start;font-size:12px;padding:6px 10px;border:1px solid var(--accent);border-radius:var(--radius);text-decoration:none}
@@ -514,6 +515,23 @@ html,body{-webkit-font-smoothing:antialiased}
514
515
  /* tests view */
515
516
  .main{margin-top:20px}
516
517
  .list{top:12px;max-height:calc(100vh - 24px)}
518
+ /* one column (phones, narrow windows): the list scrolls away instead of staying pinned over the test detail below it */
519
+ @media (max-width:900px){.list{position:static;max-height:60vh}}
520
+ /* ---------- what the browser saw; video in step with the steps ---------- */
521
+ .bev-list{border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;background:var(--surface)}
522
+ .bev{display:grid;grid-template-columns:104px minmax(0,1fr) auto;gap:4px 12px;padding:8px 12px;border-top:1px solid var(--line);font-size:13px;align-items:start}
523
+ .bev:first-child{border-top:0}
524
+ .bev .k{font-weight:600;font-size:12px;padding-top:1px} .bev.error .k,.bev.request .k{color:var(--fail)} .bev.console .k{color:var(--flaky-ink)}
525
+ .bev .m{min-width:0;overflow-wrap:anywhere;color:var(--ink);line-height:1.45} .bev .m code{font:12px var(--mono)} .bev .u{font:11.5px var(--mono);color:var(--ink-3)}
526
+ .bev .w{font-size:12px;color:var(--ink-3);white-space:nowrap;padding-top:1px} .bev.near{background:var(--fail-bg)} .bev.near .w{color:var(--fail);font-weight:600}
527
+ .bev details summary{font-size:12px;color:var(--ink-3);cursor:pointer;margin-top:2px} .bev pre{font:11.5px/1.45 var(--mono);white-space:pre-wrap;overflow-wrap:anywhere;margin:4px 0 0;color:var(--ink-2)}
528
+ @media (max-width:640px){.bev{grid-template-columns:1fr auto} .bev .m{grid-column:1/-1;grid-row:2}}
529
+ .bev-jump{display:block;margin-top:10px;padding:0;background:none;border:0;font:500 12.5px var(--sans);color:var(--fail);text-align:left;cursor:pointer} .bev-jump:hover{text-decoration:underline}
530
+ .vsync{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:0 0 8px} .vsync .hint{flex:1;min-width:180px;color:var(--ink-3);font-size:12px}
531
+ .vplay{flex:none;width:20px;height:20px;border-radius:50%;border:1px solid var(--line);background:var(--surface);color:var(--accent-2);font-size:8px;line-height:1;cursor:pointer;display:inline-grid;place-items:center;padding:0 0 0 1px}
532
+ .vplay:hover{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
533
+ .step.now{background:color-mix(in srgb,var(--accent) 16%,transparent);box-shadow:inset 3px 0 0 var(--accent)}
534
+ @media print{.vplay,.vsync .btn,.bev-jump{display:none}}
517
535
  .tools{padding:12px;gap:8px;background:var(--surface)}
518
536
  .tools input,.tools select{border-radius:8px;background:var(--bg);border-color:var(--line)}
519
537
  .tools input:focus,.tools select:focus{border-color:var(--accent);outline:0;box-shadow:0 0 0 3px var(--accent-tint)}
@@ -1773,6 +1791,8 @@ function select(id, quiet){
1773
1791
  const t=data.tests.find(x=>x.id===id); if(!t) return;
1774
1792
  state.selected=id; state.retry=t.results.length-1; if(!quiet){ if(state.view!=='tests') showView('tests'); else setHash(); } refresh(true); renderDetail(t);
1775
1793
  const it=document.querySelector('.item[data-id="'+id+'"]'); if(it&&it.scrollIntoView) it.scrollIntoView({block:'nearest'});
1794
+ // one column: the detail is below the list, so bring it into view
1795
+ if(!quiet&&window.innerWidth<=900){ const d=$('#detail'); if(d&&d.scrollIntoView) d.scrollIntoView({block:'start'}); }
1776
1796
  }
1777
1797
  function renderDetail(t, d, retryIdx){
1778
1798
  d=d||$('#detail'); d.innerHTML='';
@@ -1795,10 +1815,49 @@ function renderDetail(t, d, retryIdx){
1795
1815
  const r=t.results[retry]; if(!r){ d.append(h('p',{class:'empty'},'This test did not run.')); return; }
1796
1816
  const body=h('div',{});
1797
1817
  if(t.note&&retry===t.results.length-1) body.append(h('div',{class:'note '+(t.outcome==='passed'?'ok':'warn')}, t.note));
1798
- if(r.errors.length){ body.append(h('h4',{},r.errors.length>1?'Errors':'Error'), ...r.errors.map(errorView)); }
1799
- if(r.steps.length){ const stepTotal=Math.max(1, r.duration||0, r.steps.reduce((a,x)=>a+x.duration,0)); const tree=stepTree(r.steps, stepTotal), nested=r.steps.some(x=>x.steps.length);
1818
+ const failedRun=r.status!=='passed'&&r.status!=='skipped', fail=failedRun? failMoment(r) : null;
1819
+ const bsec=browserView(r, fail);
1820
+ if(r.errors.length){ body.append(h('h4',{},r.errors.length>1?'Errors':'Error'), ...r.errors.map(errorView));
1821
+ const near=fail!=null? (r.browser||[]).filter(e=>e.t<=fail&&fail-e.t<=5000).length : 0;
1822
+ if(near&&bsec) body.append(h('button',{class:'bev-jump',type:'button',onclick:()=>bsec.scrollIntoView({block:'start',behavior:'smooth'})}, 'The browser reported '+near+' problem'+(near>1?'s':'')+' in the 5 seconds before this failure. See what the browser saw ↓')); }
1823
+ if(bsec&&failedRun) body.append(bsec);
1824
+ // each video's first frame on the wall clock: given by the runner (Node.js: when its page opened; Java, Python: the
1825
+ // page closed minus the video's length), or for an older Node.js report the first video from its "Create page" step.
1826
+ // A popup or second tab has its own recording: every player follows the steps, each from its own start.
1827
+ const allVids=r.attachments.filter(a=>a.src&&a.contentType.startsWith('video/')),
1828
+ starts=allVids.map((a,i)=>a.videoStart||(i===0? videoStart(r.steps) : null)), v0=starts.some(x=>x!=null)? Math.min(...starts.filter(x=>x!=null)) : null;
1829
+ let sync=null;
1830
+ if(v0!=null){
1831
+ const many=allVids.length>1;
1832
+ const figs=allVids.map((a,i)=>videoFigure(a, many? 'page '+(i+1)+(starts[i]!=null&&i>0? ', opened at '+ms(Math.max(0,starts[i]-r.startTime)) : '') : null)),
1833
+ players=figs.map((f,i)=>({...f, s0:starts[i]})).filter(p=>p.s0!=null), tree=()=>body.querySelectorAll('.step[data-s]');
1834
+ const len=p=>isFinite(p.v.duration)? p.v.duration*1000 : Infinity, covers=(p,abs)=>abs>=p.s0&&abs<=p.s0+len(p);
1835
+ const light=at=>{ let cur=null; for(const el of tree()){ if(el.offsetParent&&+el.dataset.s<=at&&at<=+el.dataset.e) cur=el; } for(const el of body.querySelectorAll('.step.now')) if(el!==cur) el.classList.remove('now'); if(cur) cur.classList.add('now'); };
1836
+ const show=(p,on)=>{ if(many){ p.fig.classList.toggle('off',!on); } };
1837
+ sync={ from:v0, seek:abs=>{
1838
+ // the players recording at that moment play from it; the others wait (dimmed) and join when their page opens
1839
+ let first=null;
1840
+ for(const p of players){ if(covers(p,abs)){ p.v.currentTime=(abs-p.s0)/1000; p.v.play().catch(()=>{}); show(p,true); first=first||p; } else { p.v.pause(); p.v.currentTime=abs<p.s0||!isFinite(len(p))? 0 : len(p)/1000; show(p,false); } }
1841
+ if(!first){ first=players.reduce((a,b)=>b.s0<a.s0?b:a); first.v.currentTime=Math.max(0,(abs-first.s0)/1000); first.v.play().catch(()=>{}); show(first,true); }
1842
+ first.v.scrollIntoView({block:'nearest',behavior:'smooth'}); } };
1843
+ // a step that starts after every recording ended (closing the browser) has nothing to show
1844
+ const hideLate=()=>{ if(players.some(p=>!isFinite(p.v.duration))) return; const end=Math.max(...players.map(p=>p.s0+len(p))); for(const b of body.querySelectorAll('.vplay[data-s]')) if(+b.dataset.s>=end) b.hidden=true; };
1845
+ for(const p of players){
1846
+ p.v.addEventListener('loadedmetadata',hideLate);
1847
+ p.v.addEventListener('timeupdate',()=>{ if(many&&p.fig.classList.contains('off')) return; const at=p.s0+p.v.currentTime*1000; light(at);
1848
+ // a page opened while this one plays: start its recording too
1849
+ if(many&&!p.v.paused) for(const o of players) if(o!==p&&o.v.paused&&covers(o,at)&&o.v.currentTime*1000<at-o.s0-400){ o.v.currentTime=(at-o.s0)/1000; o.v.play().catch(()=>{}); show(o,true); } });
1850
+ if(many) p.v.addEventListener('ended',()=>show(p,false));
1851
+ }
1852
+ body.append(h('h4',{},many?'Videos':'Video'), h('div',{class:'vsync'},
1853
+ h('span',{class:'hint'}, many? 'In step with the test: each page (a popup, a second tab) has its own recording, and they play together. The step playing lights up below. Click ▶ on a step to watch it.' : 'In step with the test: the step playing lights up below. Click ▶ on a step to watch it.'),
1854
+ fail!=null? h('button',{class:'btn primary',type:'button',onclick:()=>sync.seek(fail-5000)},'▶ Watch the failure') : null),
1855
+ h('div',{class:'vids'}, figs.map(f=>f.fig)));
1856
+ }
1857
+ if(r.steps.length){ const stepTotal=Math.max(1, r.duration||0, r.steps.reduce((a,x)=>a+x.duration,0)); const tree=stepTree(r.steps, stepTotal, sync), nested=r.steps.some(x=>x.steps.length);
1800
1858
  body.append(h('h4',{class:'st-h'},data.bdd?'Scenario steps':'Steps', h('span',{class:'hint'},'bar = share of '+ms(stepTotal)),
1801
1859
  nested? h('span',{class:'st-tools'}, h('button',{type:'button',onclick:()=>setSteps(tree,false)},'Expand all'), h('button',{type:'button',onclick:()=>setSteps(tree,true)},'Collapse all')) : null), tree); }
1860
+ if(bsec&&!failedRun) body.append(bsec);
1802
1861
  if(r.logs.length){ const t0=r.startTime; body.append(h('h4',{},'Log'), h('div',{class:'logs'}, r.logs.map(l=>h('div',{class:'ln'+(/\b(error|fail|exception)\b/i.test(l.msg)?' err':/\bwarn/i.test(l.msg)?' warn':'')}, h('span',{class:'ts'},'+'+ms(Math.max(0,l.t-t0))), h('span',{class:'lm'},l.msg))))); }
1803
1862
  for(const b of r.data){ body.append(h('h4',{},b.name), dataBlock(b)); }
1804
1863
  if(r.api.length){ body.append(h('h4',{},r.api.length+' API call'+(r.api.length>1?'s':'')), ...r.api.map(c=>apiPanel(c,r))); body.append(h('div',{class:'mask-note'},'Secrets and auth headers are masked as ****')); }
@@ -1812,9 +1871,7 @@ function renderDetail(t, d, retryIdx){
1812
1871
  for(const a of imgs){ const m=a.name.match(/^(.*)-(expected|actual|diff)(\.\w+)?$/); if(m){ const set=cmp.get(m[1])||{}; set[m[2]]=a; cmp.set(m[1],set); } }
1813
1872
  const plainImgs=imgs.filter(a=>!/-(expected|actual|diff)(\.\w+)?$/.test(a.name));
1814
1873
  for(const [name,set] of cmp) if(set.expected&&set.actual) body.append(h('h4',{},'Visual comparison · '+name), compare(set)); else for(const k of Object.keys(set)) plainImgs.push(set[k]);
1815
- if(vids.length){ body.append(h('h4',{},vids.length>1?'Videos':'Video'), h('div',{class:'vids'}, vids.map(a=>{ const fig=h('figure',{}); const v=h('video',{src:a.src,controls:'',preload:'metadata',playsinline:''});
1816
- v.addEventListener('error',()=>{ const code=v.error&&v.error.code; const why=code===4?'The file is missing, or it is not a format this browser can play.':code===2?'The file could not be read.':'The file could not be decoded.'; v.replaceWith(h('div',{class:'att-err'}, h('b',{},'Video could not be loaded.'), ' '+why+' Expected at ', h('code',{},a.src), '. Common causes: on macOS, Chrome cannot read files next to a report opened from Downloads, Desktop or Documents until you allow it under System Settings → Privacy & Security → Files and Folders (or move the project elsewhere); or the assets folder was replaced by a newer run. Setting embedVideos: true in the reporter options puts videos inside the HTML and avoids both.')); });
1817
- fig.append(v, h('figcaption',{}, a.name, a.size?h('span',{},' · '+kb(a.size)):null, ' · ', h('a',{href:a.src,download:'',target:'_blank',rel:'noopener',title:'Downloads when the report is served over http; opens in a new tab when opened as a file'},'download'))); return fig; }))); }
1874
+ if(vids.length&&v0==null){ body.append(h('h4',{},vids.length>1?'Videos':'Video'), h('div',{class:'vids'}, vids.map(a=>videoFigure(a).fig))); }
1818
1875
  if(plainImgs.length){ body.append(h('h4',{},plainImgs.length>1?'Screenshots':'Screenshot'), h('div',{class:'att'}, plainImgs.map(a=>h('figure',{}, h('img',{src:a.src,alt:a.name,loading:'lazy',onclick:()=>lightbox(a.src)}), h('figcaption',{},a.name))))); }
1819
1876
  if(traces.length){ body.append(h('h4',{},'Trace'), h('div',{class:'trace'}, traces.map(a=>h('div',{class:'trace-card'},
1820
1877
  h('div',{}, h('b',{},a.name), a.size?h('span',{style:'color:var(--ink-3)'},' · '+kb(a.size)):null),
@@ -1828,15 +1885,43 @@ function renderDetail(t, d, retryIdx){
1828
1885
  if(!body.children.length) body.append(h('p',{style:'color:var(--ink-3)'}, r.status==='skipped'?'Skipped — nothing was executed.'+(skipReason(t)?' Reason: '+skipReason(t):''):'Passed with no steps or attachments recorded.'));
1829
1886
  d.append(body);
1830
1887
  }
1831
- function stepTree(steps, total){
1888
+ function videoFigure(a, label){ const fig=h('figure',{}); const v=h('video',{src:a.src,controls:'',preload:'metadata',playsinline:''});
1889
+ v.addEventListener('error',()=>{ const code=v.error&&v.error.code; const why=code===4?'The file is missing, or it is not a format this browser can play.':code===2?'The file could not be read.':'The file could not be decoded.'; v.replaceWith(h('div',{class:'att-err'}, h('b',{},'Video could not be loaded.'), ' '+why+' Expected at ', h('code',{},a.src), '. Common causes: on macOS, Chrome cannot read files next to a report opened from Downloads, Desktop or Documents until you allow it under System Settings → Privacy & Security → Files and Folders (or move the project elsewhere); or the assets folder was replaced by a newer run. Setting embedVideos: true in the reporter options puts videos inside the HTML and avoids both.')); });
1890
+ fig.append(v, h('figcaption',{}, a.name, label?h('span',{},' · '+label):null, a.size?h('span',{},' · '+kb(a.size)):null, ' · ', h('a',{href:a.src,download:'',target:'_blank',rel:'noopener',title:'Downloads when the report is served over http; opens in a new tab when opened as a file'},'download'))); return {fig, v}; }
1891
+ /* Playwright starts recording a page's video when the page is created: the first "Create page" step ends at the
1892
+ video's 0:00 (measured within ~20ms). Without that step (other runners) the video is not lined up with steps. */
1893
+ function videoStart(steps){ for(const s of steps){ if(s.category==='pw:api'&&/^Create page\b/.test(s.title)&&s.start!=null) return s.start+s.duration; const k=videoStart(s.steps); if(k!=null) return k; } return null; }
1894
+ /* When the test failed: the end of the first step that failed, else the end of the attempt. */
1895
+ function failMoment(r){ let at=null; const walk=ss=>{ for(const s of ss){ if(s.error&&s.start!=null) at=at==null? s.start+s.duration : Math.min(at, s.start+s.duration); walk(s.steps); } }; walk(r.steps); return at!=null? at : r.startTime+r.duration; }
1896
+ /* What the browser reported while the test ran (captured by reporting-labs/auto): uncaught JavaScript errors,
1897
+ console.error and failed requests, timed against the failure. */
1898
+ function browserView(r, fail){
1899
+ const ev=r.browser||[]; if(!ev.length) return null;
1900
+ const count=k=>ev.filter(e=>e.kind===k).length;
1901
+ const parts=[[count('error'),'JavaScript error'],[count('console'),'console error'],[count('request'),'failed request']].filter(x=>x[0]).map(([c,l])=>c+' '+l+(c>1?'s':''));
1902
+ const when=e=> fail!=null? (e.t<=fail? ms(fail-e.t)+' before the failure' : ms(e.t-fail)+' after it') : 'at '+ms(Math.max(0,e.t-r.startTime));
1903
+ const label=e=> e.kind==='error'?'JS error':e.kind==='console'?'console.error':e.status?'HTTP '+e.status:'No response';
1904
+ const row=e=>h('div',{class:'bev '+e.kind+(fail!=null&&e.t<=fail&&fail-e.t<=5000?' near':'')},
1905
+ h('span',{class:'k'},label(e)),
1906
+ h('div',{class:'m'}, e.kind==='request'? [h('code',{},(e.method?e.method+' ':'')+e.url), e.text? h('div',{class:'u'},e.text) : null] : [h('div',{},e.text), e.url? h('div',{class:'u'},e.url) : null],
1907
+ e.stack&&e.stack!==e.text? h('details',{}, h('summary',{},'Stack'), h('pre',{},e.stack)) : null),
1908
+ h('span',{class:'w'},when(e)));
1909
+ const shown=ev.slice(-30), sec=h('div',{class:'bev-sec'});
1910
+ sec.append(h('h4',{},'What the browser saw', h('span',{class:'hint'},parts.join(' · ')+(ev.length>shown.length?' · the last '+shown.length+' shown':''))), h('div',{class:'bev-list'}, shown.map(row)));
1911
+ return sec;
1912
+ }
1913
+ function stepTree(steps, total, sync){
1832
1914
  return h('ul',{class:'steps'}, steps.map(s=>{
1833
1915
  const bad=!!s.error, skip=s.status==='skipped', kids=s.steps.length>0, pct=total?Math.min(100,s.duration/total*100):0;
1834
1916
  // a step with sub-steps starts collapsed; the path to a failure starts open unless expandFailedSteps is false
1835
1917
  const li=h('li',{class:kids&&(data.options.expandFailedSteps===false||!hasError(s))?'collapsed':''});
1836
- const row=h('div',{class:'step'+(bad?' bad':'')+(skip?' skip':'')},
1837
- h('span',{class:'tw'}, kids? '▸' : ''), data.bdd?null:h('span',{class:'cat'},s.category), gherkin(s.title), total&&!skip? h('span',{class:'tb',title:Math.round(pct)+'% of the test'}, h('i',{class:pct>=30?'slow':'',style:'width:'+Math.max(pct,s.duration>0?1.5:0)+'%'})) : null, h('span',{class:'d'},skip?'not run':ms(s.duration)));
1918
+ const timed=s.start!=null&&!skip;
1919
+ const row=h('div',{class:'step'+(bad?' bad':'')+(skip?' skip':''),'data-s':timed?s.start:null,'data-e':timed?s.start+s.duration:null},
1920
+ h('span',{class:'tw'}, kids? '▸' : ''), data.bdd?null:h('span',{class:'cat'},s.category), gherkin(s.title), total&&!skip? h('span',{class:'tb',title:Math.round(pct)+'% of the test'}, h('i',{class:pct>=30?'slow':'',style:'width:'+Math.max(pct,s.duration>0?1.5:0)+'%'})) : null, h('span',{class:'d'},skip?'not run':ms(s.duration)),
1921
+ // only for steps the video shows: not the browser launch and page setup that end before recording starts
1922
+ sync&&timed&&s.start+s.duration>sync.from+100? h('button',{class:'vplay',type:'button','data-s':s.start,title:'Play the video from this step','aria-label':'Play the video from this step',onclick:e=>{e.stopPropagation();sync.seek(s.start);}},'▶') : null);
1838
1923
  if(kids){ row.style.cursor='pointer'; row.addEventListener('click',()=>{li.classList.toggle('collapsed'); row.querySelector('.tw').textContent=li.classList.contains('collapsed')?'▸':'▾';}); if(!li.classList.contains('collapsed')) row.querySelector('.tw').textContent='▾'; }
1839
- li.append(row); if(bad) li.append(h('div',{class:'e'},s.error)); if(kids) li.append(stepTree(s.steps, total));
1924
+ li.append(row); if(bad) li.append(h('div',{class:'e'},s.error)); if(kids) li.append(stepTree(s.steps, total, sync));
1840
1925
  return li;
1841
1926
  }));
1842
1927
  }
package/dist/template.js CHANGED
@@ -387,6 +387,7 @@ li.collapsed>ul{display:none}
387
387
  .vids figure{margin:0;border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;background:#000}
388
388
  .vids video{width:100%;display:block;max-height:420px;background:#000}
389
389
  .vids figcaption{font:11px var(--mono);padding:6px 8px;color:var(--ink-2);background:var(--surface-2)}
390
+ .vids figure{transition:opacity .2s} .vids figure.off{opacity:.45}
390
391
  .trace-card{border:1px solid var(--line);border-radius:var(--radius);padding:12px 14px;display:flex;flex-direction:column;gap:8px;font-size:13px}
391
392
  .trace-how{color:var(--ink-2);font-size:12px} .trace-how code{font:12px var(--mono);background:var(--surface-2);padding:1px 5px;border-radius:3px}
392
393
  .trace-card .dl{align-self:flex-start;font-size:12px;padding:6px 10px;border:1px solid var(--accent);border-radius:var(--radius);text-decoration:none}
@@ -585,6 +586,23 @@ html,body{-webkit-font-smoothing:antialiased}
585
586
  /* tests view */
586
587
  .main{margin-top:20px}
587
588
  .list{top:12px;max-height:calc(100vh - 24px)}
589
+ /* one column (phones, narrow windows): the list scrolls away instead of staying pinned over the test detail below it */
590
+ @media (max-width:900px){.list{position:static;max-height:60vh}}
591
+ /* ---------- what the browser saw; video in step with the steps ---------- */
592
+ .bev-list{border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;background:var(--surface)}
593
+ .bev{display:grid;grid-template-columns:104px minmax(0,1fr) auto;gap:4px 12px;padding:8px 12px;border-top:1px solid var(--line);font-size:13px;align-items:start}
594
+ .bev:first-child{border-top:0}
595
+ .bev .k{font-weight:600;font-size:12px;padding-top:1px} .bev.error .k,.bev.request .k{color:var(--fail)} .bev.console .k{color:var(--flaky-ink)}
596
+ .bev .m{min-width:0;overflow-wrap:anywhere;color:var(--ink);line-height:1.45} .bev .m code{font:12px var(--mono)} .bev .u{font:11.5px var(--mono);color:var(--ink-3)}
597
+ .bev .w{font-size:12px;color:var(--ink-3);white-space:nowrap;padding-top:1px} .bev.near{background:var(--fail-bg)} .bev.near .w{color:var(--fail);font-weight:600}
598
+ .bev details summary{font-size:12px;color:var(--ink-3);cursor:pointer;margin-top:2px} .bev pre{font:11.5px/1.45 var(--mono);white-space:pre-wrap;overflow-wrap:anywhere;margin:4px 0 0;color:var(--ink-2)}
599
+ @media (max-width:640px){.bev{grid-template-columns:1fr auto} .bev .m{grid-column:1/-1;grid-row:2}}
600
+ .bev-jump{display:block;margin-top:10px;padding:0;background:none;border:0;font:500 12.5px var(--sans);color:var(--fail);text-align:left;cursor:pointer} .bev-jump:hover{text-decoration:underline}
601
+ .vsync{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:0 0 8px} .vsync .hint{flex:1;min-width:180px;color:var(--ink-3);font-size:12px}
602
+ .vplay{flex:none;width:20px;height:20px;border-radius:50%;border:1px solid var(--line);background:var(--surface);color:var(--accent-2);font-size:8px;line-height:1;cursor:pointer;display:inline-grid;place-items:center;padding:0 0 0 1px}
603
+ .vplay:hover{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
604
+ .step.now{background:color-mix(in srgb,var(--accent) 16%,transparent);box-shadow:inset 3px 0 0 var(--accent)}
605
+ @media print{.vplay,.vsync .btn,.bev-jump{display:none}}
588
606
  .tools{padding:12px;gap:8px;background:var(--surface)}
589
607
  .tools input,.tools select{border-radius:8px;background:var(--bg);border-color:var(--line)}
590
608
  .tools input:focus,.tools select:focus{border-color:var(--accent);outline:0;box-shadow:0 0 0 3px var(--accent-tint)}
@@ -1839,6 +1857,8 @@ function select(id, quiet){
1839
1857
  const t=data.tests.find(x=>x.id===id); if(!t) return;
1840
1858
  state.selected=id; state.retry=t.results.length-1; if(!quiet){ if(state.view!=='tests') showView('tests'); else setHash(); } refresh(true); renderDetail(t);
1841
1859
  const it=document.querySelector('.item[data-id="'+id+'"]'); if(it&&it.scrollIntoView) it.scrollIntoView({block:'nearest'});
1860
+ // one column: the detail is below the list, so bring it into view
1861
+ if(!quiet&&window.innerWidth<=900){ const d=$('#detail'); if(d&&d.scrollIntoView) d.scrollIntoView({block:'start'}); }
1842
1862
  }
1843
1863
  function renderDetail(t, d, retryIdx){
1844
1864
  d=d||$('#detail'); d.innerHTML='';
@@ -1861,10 +1881,49 @@ function renderDetail(t, d, retryIdx){
1861
1881
  const r=t.results[retry]; if(!r){ d.append(h('p',{class:'empty'},'This test did not run.')); return; }
1862
1882
  const body=h('div',{});
1863
1883
  if(t.note&&retry===t.results.length-1) body.append(h('div',{class:'note '+(t.outcome==='passed'?'ok':'warn')}, t.note));
1864
- if(r.errors.length){ body.append(h('h4',{},r.errors.length>1?'Errors':'Error'), ...r.errors.map(errorView)); }
1865
- if(r.steps.length){ const stepTotal=Math.max(1, r.duration||0, r.steps.reduce((a,x)=>a+x.duration,0)); const tree=stepTree(r.steps, stepTotal), nested=r.steps.some(x=>x.steps.length);
1884
+ const failedRun=r.status!=='passed'&&r.status!=='skipped', fail=failedRun? failMoment(r) : null;
1885
+ const bsec=browserView(r, fail);
1886
+ if(r.errors.length){ body.append(h('h4',{},r.errors.length>1?'Errors':'Error'), ...r.errors.map(errorView));
1887
+ const near=fail!=null? (r.browser||[]).filter(e=>e.t<=fail&&fail-e.t<=5000).length : 0;
1888
+ if(near&&bsec) body.append(h('button',{class:'bev-jump',type:'button',onclick:()=>bsec.scrollIntoView({block:'start',behavior:'smooth'})}, 'The browser reported '+near+' problem'+(near>1?'s':'')+' in the 5 seconds before this failure. See what the browser saw ↓')); }
1889
+ if(bsec&&failedRun) body.append(bsec);
1890
+ // each video's first frame on the wall clock: given by the runner (Node.js: when its page opened; Java, Python: the
1891
+ // page closed minus the video's length), or for an older Node.js report the first video from its "Create page" step.
1892
+ // A popup or second tab has its own recording: every player follows the steps, each from its own start.
1893
+ const allVids=r.attachments.filter(a=>a.src&&a.contentType.startsWith('video/')),
1894
+ starts=allVids.map((a,i)=>a.videoStart||(i===0? videoStart(r.steps) : null)), v0=starts.some(x=>x!=null)? Math.min(...starts.filter(x=>x!=null)) : null;
1895
+ let sync=null;
1896
+ if(v0!=null){
1897
+ const many=allVids.length>1;
1898
+ const figs=allVids.map((a,i)=>videoFigure(a, many? 'page '+(i+1)+(starts[i]!=null&&i>0? ', opened at '+ms(Math.max(0,starts[i]-r.startTime)) : '') : null)),
1899
+ players=figs.map((f,i)=>({...f, s0:starts[i]})).filter(p=>p.s0!=null), tree=()=>body.querySelectorAll('.step[data-s]');
1900
+ const len=p=>isFinite(p.v.duration)? p.v.duration*1000 : Infinity, covers=(p,abs)=>abs>=p.s0&&abs<=p.s0+len(p);
1901
+ const light=at=>{ let cur=null; for(const el of tree()){ if(el.offsetParent&&+el.dataset.s<=at&&at<=+el.dataset.e) cur=el; } for(const el of body.querySelectorAll('.step.now')) if(el!==cur) el.classList.remove('now'); if(cur) cur.classList.add('now'); };
1902
+ const show=(p,on)=>{ if(many){ p.fig.classList.toggle('off',!on); } };
1903
+ sync={ from:v0, seek:abs=>{
1904
+ // the players recording at that moment play from it; the others wait (dimmed) and join when their page opens
1905
+ let first=null;
1906
+ for(const p of players){ if(covers(p,abs)){ p.v.currentTime=(abs-p.s0)/1000; p.v.play().catch(()=>{}); show(p,true); first=first||p; } else { p.v.pause(); p.v.currentTime=abs<p.s0||!isFinite(len(p))? 0 : len(p)/1000; show(p,false); } }
1907
+ if(!first){ first=players.reduce((a,b)=>b.s0<a.s0?b:a); first.v.currentTime=Math.max(0,(abs-first.s0)/1000); first.v.play().catch(()=>{}); show(first,true); }
1908
+ first.v.scrollIntoView({block:'nearest',behavior:'smooth'}); } };
1909
+ // a step that starts after every recording ended (closing the browser) has nothing to show
1910
+ const hideLate=()=>{ if(players.some(p=>!isFinite(p.v.duration))) return; const end=Math.max(...players.map(p=>p.s0+len(p))); for(const b of body.querySelectorAll('.vplay[data-s]')) if(+b.dataset.s>=end) b.hidden=true; };
1911
+ for(const p of players){
1912
+ p.v.addEventListener('loadedmetadata',hideLate);
1913
+ p.v.addEventListener('timeupdate',()=>{ if(many&&p.fig.classList.contains('off')) return; const at=p.s0+p.v.currentTime*1000; light(at);
1914
+ // a page opened while this one plays: start its recording too
1915
+ if(many&&!p.v.paused) for(const o of players) if(o!==p&&o.v.paused&&covers(o,at)&&o.v.currentTime*1000<at-o.s0-400){ o.v.currentTime=(at-o.s0)/1000; o.v.play().catch(()=>{}); show(o,true); } });
1916
+ if(many) p.v.addEventListener('ended',()=>show(p,false));
1917
+ }
1918
+ body.append(h('h4',{},many?'Videos':'Video'), h('div',{class:'vsync'},
1919
+ h('span',{class:'hint'}, many? 'In step with the test: each page (a popup, a second tab) has its own recording, and they play together. The step playing lights up below. Click ▶ on a step to watch it.' : 'In step with the test: the step playing lights up below. Click ▶ on a step to watch it.'),
1920
+ fail!=null? h('button',{class:'btn primary',type:'button',onclick:()=>sync.seek(fail-5000)},'▶ Watch the failure') : null),
1921
+ h('div',{class:'vids'}, figs.map(f=>f.fig)));
1922
+ }
1923
+ if(r.steps.length){ const stepTotal=Math.max(1, r.duration||0, r.steps.reduce((a,x)=>a+x.duration,0)); const tree=stepTree(r.steps, stepTotal, sync), nested=r.steps.some(x=>x.steps.length);
1866
1924
  body.append(h('h4',{class:'st-h'},data.bdd?'Scenario steps':'Steps', h('span',{class:'hint'},'bar = share of '+ms(stepTotal)),
1867
1925
  nested? h('span',{class:'st-tools'}, h('button',{type:'button',onclick:()=>setSteps(tree,false)},'Expand all'), h('button',{type:'button',onclick:()=>setSteps(tree,true)},'Collapse all')) : null), tree); }
1926
+ if(bsec&&!failedRun) body.append(bsec);
1868
1927
  if(r.logs.length){ const t0=r.startTime; body.append(h('h4',{},'Log'), h('div',{class:'logs'}, r.logs.map(l=>h('div',{class:'ln'+(/\b(error|fail|exception)\b/i.test(l.msg)?' err':/\bwarn/i.test(l.msg)?' warn':'')}, h('span',{class:'ts'},'+'+ms(Math.max(0,l.t-t0))), h('span',{class:'lm'},l.msg))))); }
1869
1928
  for(const b of r.data){ body.append(h('h4',{},b.name), dataBlock(b)); }
1870
1929
  if(r.api.length){ body.append(h('h4',{},r.api.length+' API call'+(r.api.length>1?'s':'')), ...r.api.map(c=>apiPanel(c,r))); body.append(h('div',{class:'mask-note'},'Secrets and auth headers are masked as ****')); }
@@ -1878,9 +1937,7 @@ function renderDetail(t, d, retryIdx){
1878
1937
  for(const a of imgs){ const m=a.name.match(/^(.*)-(expected|actual|diff)(\.\w+)?$/); if(m){ const set=cmp.get(m[1])||{}; set[m[2]]=a; cmp.set(m[1],set); } }
1879
1938
  const plainImgs=imgs.filter(a=>!/-(expected|actual|diff)(\.\w+)?$/.test(a.name));
1880
1939
  for(const [name,set] of cmp) if(set.expected&&set.actual) body.append(h('h4',{},'Visual comparison · '+name), compare(set)); else for(const k of Object.keys(set)) plainImgs.push(set[k]);
1881
- if(vids.length){ body.append(h('h4',{},vids.length>1?'Videos':'Video'), h('div',{class:'vids'}, vids.map(a=>{ const fig=h('figure',{}); const v=h('video',{src:a.src,controls:'',preload:'metadata',playsinline:''});
1882
- v.addEventListener('error',()=>{ const code=v.error&&v.error.code; const why=code===4?'The file is missing, or it is not a format this browser can play.':code===2?'The file could not be read.':'The file could not be decoded.'; v.replaceWith(h('div',{class:'att-err'}, h('b',{},'Video could not be loaded.'), ' '+why+' Expected at ', h('code',{},a.src), '. Common causes: on macOS, Chrome cannot read files next to a report opened from Downloads, Desktop or Documents until you allow it under System Settings → Privacy & Security → Files and Folders (or move the project elsewhere); or the assets folder was replaced by a newer run. Setting embedVideos: true in the reporter options puts videos inside the HTML and avoids both.')); });
1883
- fig.append(v, h('figcaption',{}, a.name, a.size?h('span',{},' · '+kb(a.size)):null, ' · ', h('a',{href:a.src,download:'',target:'_blank',rel:'noopener',title:'Downloads when the report is served over http; opens in a new tab when opened as a file'},'download'))); return fig; }))); }
1940
+ if(vids.length&&v0==null){ body.append(h('h4',{},vids.length>1?'Videos':'Video'), h('div',{class:'vids'}, vids.map(a=>videoFigure(a).fig))); }
1884
1941
  if(plainImgs.length){ body.append(h('h4',{},plainImgs.length>1?'Screenshots':'Screenshot'), h('div',{class:'att'}, plainImgs.map(a=>h('figure',{}, h('img',{src:a.src,alt:a.name,loading:'lazy',onclick:()=>lightbox(a.src)}), h('figcaption',{},a.name))))); }
1885
1942
  if(traces.length){ body.append(h('h4',{},'Trace'), h('div',{class:'trace'}, traces.map(a=>h('div',{class:'trace-card'},
1886
1943
  h('div',{}, h('b',{},a.name), a.size?h('span',{style:'color:var(--ink-3)'},' · '+kb(a.size)):null),
@@ -1894,15 +1951,43 @@ function renderDetail(t, d, retryIdx){
1894
1951
  if(!body.children.length) body.append(h('p',{style:'color:var(--ink-3)'}, r.status==='skipped'?'Skipped — nothing was executed.'+(skipReason(t)?' Reason: '+skipReason(t):''):'Passed with no steps or attachments recorded.'));
1895
1952
  d.append(body);
1896
1953
  }
1897
- function stepTree(steps, total){
1954
+ function videoFigure(a, label){ const fig=h('figure',{}); const v=h('video',{src:a.src,controls:'',preload:'metadata',playsinline:''});
1955
+ v.addEventListener('error',()=>{ const code=v.error&&v.error.code; const why=code===4?'The file is missing, or it is not a format this browser can play.':code===2?'The file could not be read.':'The file could not be decoded.'; v.replaceWith(h('div',{class:'att-err'}, h('b',{},'Video could not be loaded.'), ' '+why+' Expected at ', h('code',{},a.src), '. Common causes: on macOS, Chrome cannot read files next to a report opened from Downloads, Desktop or Documents until you allow it under System Settings → Privacy & Security → Files and Folders (or move the project elsewhere); or the assets folder was replaced by a newer run. Setting embedVideos: true in the reporter options puts videos inside the HTML and avoids both.')); });
1956
+ fig.append(v, h('figcaption',{}, a.name, label?h('span',{},' · '+label):null, a.size?h('span',{},' · '+kb(a.size)):null, ' · ', h('a',{href:a.src,download:'',target:'_blank',rel:'noopener',title:'Downloads when the report is served over http; opens in a new tab when opened as a file'},'download'))); return {fig, v}; }
1957
+ /* Playwright starts recording a page's video when the page is created: the first "Create page" step ends at the
1958
+ video's 0:00 (measured within ~20ms). Without that step (other runners) the video is not lined up with steps. */
1959
+ function videoStart(steps){ for(const s of steps){ if(s.category==='pw:api'&&/^Create page\b/.test(s.title)&&s.start!=null) return s.start+s.duration; const k=videoStart(s.steps); if(k!=null) return k; } return null; }
1960
+ /* When the test failed: the end of the first step that failed, else the end of the attempt. */
1961
+ function failMoment(r){ let at=null; const walk=ss=>{ for(const s of ss){ if(s.error&&s.start!=null) at=at==null? s.start+s.duration : Math.min(at, s.start+s.duration); walk(s.steps); } }; walk(r.steps); return at!=null? at : r.startTime+r.duration; }
1962
+ /* What the browser reported while the test ran (captured by reporting-labs/auto): uncaught JavaScript errors,
1963
+ console.error and failed requests, timed against the failure. */
1964
+ function browserView(r, fail){
1965
+ const ev=r.browser||[]; if(!ev.length) return null;
1966
+ const count=k=>ev.filter(e=>e.kind===k).length;
1967
+ const parts=[[count('error'),'JavaScript error'],[count('console'),'console error'],[count('request'),'failed request']].filter(x=>x[0]).map(([c,l])=>c+' '+l+(c>1?'s':''));
1968
+ const when=e=> fail!=null? (e.t<=fail? ms(fail-e.t)+' before the failure' : ms(e.t-fail)+' after it') : 'at '+ms(Math.max(0,e.t-r.startTime));
1969
+ const label=e=> e.kind==='error'?'JS error':e.kind==='console'?'console.error':e.status?'HTTP '+e.status:'No response';
1970
+ const row=e=>h('div',{class:'bev '+e.kind+(fail!=null&&e.t<=fail&&fail-e.t<=5000?' near':'')},
1971
+ h('span',{class:'k'},label(e)),
1972
+ h('div',{class:'m'}, e.kind==='request'? [h('code',{},(e.method?e.method+' ':'')+e.url), e.text? h('div',{class:'u'},e.text) : null] : [h('div',{},e.text), e.url? h('div',{class:'u'},e.url) : null],
1973
+ e.stack&&e.stack!==e.text? h('details',{}, h('summary',{},'Stack'), h('pre',{},e.stack)) : null),
1974
+ h('span',{class:'w'},when(e)));
1975
+ const shown=ev.slice(-30), sec=h('div',{class:'bev-sec'});
1976
+ sec.append(h('h4',{},'What the browser saw', h('span',{class:'hint'},parts.join(' · ')+(ev.length>shown.length?' · the last '+shown.length+' shown':''))), h('div',{class:'bev-list'}, shown.map(row)));
1977
+ return sec;
1978
+ }
1979
+ function stepTree(steps, total, sync){
1898
1980
  return h('ul',{class:'steps'}, steps.map(s=>{
1899
1981
  const bad=!!s.error, skip=s.status==='skipped', kids=s.steps.length>0, pct=total?Math.min(100,s.duration/total*100):0;
1900
1982
  // a step with sub-steps starts collapsed; the path to a failure starts open unless expandFailedSteps is false
1901
1983
  const li=h('li',{class:kids&&(data.options.expandFailedSteps===false||!hasError(s))?'collapsed':''});
1902
- const row=h('div',{class:'step'+(bad?' bad':'')+(skip?' skip':'')},
1903
- h('span',{class:'tw'}, kids? '▸' : ''), data.bdd?null:h('span',{class:'cat'},s.category), gherkin(s.title), total&&!skip? h('span',{class:'tb',title:Math.round(pct)+'% of the test'}, h('i',{class:pct>=30?'slow':'',style:'width:'+Math.max(pct,s.duration>0?1.5:0)+'%'})) : null, h('span',{class:'d'},skip?'not run':ms(s.duration)));
1984
+ const timed=s.start!=null&&!skip;
1985
+ const row=h('div',{class:'step'+(bad?' bad':'')+(skip?' skip':''),'data-s':timed?s.start:null,'data-e':timed?s.start+s.duration:null},
1986
+ h('span',{class:'tw'}, kids? '▸' : ''), data.bdd?null:h('span',{class:'cat'},s.category), gherkin(s.title), total&&!skip? h('span',{class:'tb',title:Math.round(pct)+'% of the test'}, h('i',{class:pct>=30?'slow':'',style:'width:'+Math.max(pct,s.duration>0?1.5:0)+'%'})) : null, h('span',{class:'d'},skip?'not run':ms(s.duration)),
1987
+ // only for steps the video shows: not the browser launch and page setup that end before recording starts
1988
+ sync&&timed&&s.start+s.duration>sync.from+100? h('button',{class:'vplay',type:'button','data-s':s.start,title:'Play the video from this step','aria-label':'Play the video from this step',onclick:e=>{e.stopPropagation();sync.seek(s.start);}},'▶') : null);
1904
1989
  if(kids){ row.style.cursor='pointer'; row.addEventListener('click',()=>{li.classList.toggle('collapsed'); row.querySelector('.tw').textContent=li.classList.contains('collapsed')?'▸':'▾';}); if(!li.classList.contains('collapsed')) row.querySelector('.tw').textContent='▾'; }
1905
- li.append(row); if(bad) li.append(h('div',{class:'e'},s.error)); if(kids) li.append(stepTree(s.steps, total));
1990
+ li.append(row); if(bad) li.append(h('div',{class:'e'},s.error)); if(kids) li.append(stepTree(s.steps, total, sync));
1906
1991
  return li;
1907
1992
  }));
1908
1993
  }
package/dist/types.d.ts CHANGED
@@ -221,6 +221,8 @@ export interface StepData {
221
221
  error?: string;
222
222
  /** 'skipped' when the runner never executed it (a Cucumber step after a failed one) */
223
223
  status?: 'skipped';
224
+ /** When it started (ms since epoch), so the report can line steps up with the video. */
225
+ start?: number;
224
226
  steps: StepData[];
225
227
  }
226
228
  export interface AttachmentData {
@@ -232,6 +234,8 @@ export interface AttachmentData {
232
234
  text?: string;
233
235
  /** bytes on disk, when known */
234
236
  size?: number;
237
+ /** A video's first frame (ms since epoch), when the runner knows it: lines the video up with the steps. */
238
+ videoStart?: number;
235
239
  }
236
240
  export interface ResultData {
237
241
  retry: number;
@@ -257,6 +261,19 @@ export interface ResultData {
257
261
  text?: string;
258
262
  }[];
259
263
  api: ApiCall[];
264
+ /** What the browser reported while the test ran: uncaught JavaScript errors, console.error, failed requests. */
265
+ browser?: BrowserEvent[];
266
+ }
267
+ export interface BrowserEvent {
268
+ /** ms since epoch */
269
+ t: number;
270
+ kind: 'error' | 'console' | 'request';
271
+ text: string;
272
+ url?: string;
273
+ method?: string;
274
+ /** HTTP status of a request that got a 4xx/5xx; absent when it got no response at all */
275
+ status?: number;
276
+ stack?: string;
260
277
  }
261
278
  export interface TestData {
262
279
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reporting-labs",
3
- "version": "0.6.22",
3
+ "version": "0.6.24",
4
4
  "description": "reportingLabs – beautiful, customizable single-file HTML test reports. One line of config. Playwright adapter included, more runners on the way.",
5
5
  "keywords": [
6
6
  "test-report",