Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion capture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The first time you run this, it will copy `capture/fixture/` into a work directo

## Scenarios

Defined in `captures.config.ts`, currently: `nuxt-dev`, `nuxt-dev-static`, `nuxt-dev-restart`, `nuxt-dev-install-module` (interactive dev UI, pinned with `NUXT_TUI=1`), `nuxt-dev-plain`, `nuxt-dev-plain-static`, `nuxt-dev-plain-restart` (classic log output, pinned with `NUXT_TUI=plain`), `nuxt-init`, `nuxt-curl`, `nuxt-task-list`, `nuxt-module-search`.
Defined in `captures.config.ts`, currently: `nuxt-dev`, `nuxt-dev-static`, `nuxt-dev-restart`, `nuxt-dev-install-module`, `nuxt-dev-logs` (interactive dev UI, pinned with `NUXT_TUI=1`), `nuxt-dev-plain`, `nuxt-dev-plain-static`, `nuxt-dev-plain-restart` (classic log output, pinned with `NUXT_TUI=plain`), `nuxt-init`, `nuxt-curl`, `nuxt-task-list`, `nuxt-module-search`.

Dev captures pin the UI mode explicitly because the dev UI otherwise decides based on the environment (CI, test, terminal size), which would make recordings machine-dependent.

Expand All @@ -42,6 +42,8 @@ A scenario is a command plus an optional `drive` function that types into the se

Each SVG is scrubbed of ports, LAN addresses, home and temporary directories, and (for dev scenarios) the QR code. Each capture's `<desc>` records which rules were applied.

Whether a re-recording replaces the committed SVG is decided by its `.txt` fingerprint, which also pins versions, timings, dates and spinner phases. A scenario can add rules that apply only to the fingerprint with `fingerprint`; `nuxt-dev-logs` uses `clock`, since which log rows print a time depends on where the seconds fell.

## Stubbed APIs

`nuxt module search` is recorded against `capture/fixture-data/modules.json` instead of the live `api.nuxt.com`. You can refresh the fixture when the docs should show newer modules.
Expand Down
37 changes: 37 additions & 0 deletions capture/captures.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface Capture {
animated?: boolean
/** Rules from `lib/scrub.ts` applied to the captured bytes. */
scrub?: string[]
/** Rules from `lib/scrub.ts` applied only when deciding whether the committed SVG is stale. */
fingerprint?: string[]
/** Drives the session: waits, keystrokes, file edits. */
drive?: (context: CaptureContext) => Promise<void>
/** Extra environment for the pty. */
Expand Down Expand Up @@ -188,6 +190,41 @@ export const captures: Capture[] = [
}
},
},
{
id: 'nuxt-dev-logs',
title: 'nuxt dev (browsing logs)',
command: '$NUXT dev --no-clear --takeover',
cwd: 'app',
animated: true,
rows: 26,
scrub: DEV_SCRUB,
fingerprint: ['clock'],
stopAfterDrive: true,
env: TUI_ENV,
async drive({ session }) {
await session.waitFor(/ready in \d/, 180_000)
const port = session.output().match(/localhost:(\d+)/)?.[1] ?? '3000'
for (const cart of ['c_8f3a21', 'c_19be07']) {
await fetch(`http://localhost:${port}/api/checkout?cart=${cart}`)
await session.wait(500)
}
await session.waitFor(/βœ– 2 errors/, 30_000)
await session.wait(1000)
// Relative to the last error: other logs can still arrive after it.
session.send('e')
await session.wait(3500)
session.send('\u001B')
await session.wait(2000)
for (const key of ['\u001B[A', '\u001B[A', '\u001B[B', '\u001B[B']) {
session.send(key)
await session.wait(1500)
}
session.send('T')
await session.wait(2500)
session.send('q')
await session.wait(1000)
},
},
{
id: 'nuxt-dev-plain',
title: 'nuxt dev (plain output)',
Expand Down
10 changes: 10 additions & 0 deletions capture/fixture/server/api/checkout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function applyDiscount(cart: string, code: string) {
throw new Error(`Failed to apply discount code ${code} to cart ${cart}: the pricing service responded with 422 Unprocessable Entity (the code expired on 2026-09-01 and cannot be combined with items already on sale)`)
}

export default defineEventHandler((event) => {
const cart = String(getQuery(event).cart ?? 'guest')
console.log(`[checkout] loading cart ${cart} with options ${JSON.stringify({ currency: 'EUR', locale: 'en-GB', include: ['items', 'discounts', 'shipping', 'tax'], expand: true })}`)
console.warn(`[checkout] prices for cart ${cart} were cached more than 10 minutes ago, recalculating totals against https://pricing.example.com/v2/carts/${cart}/recalculate?currency=EUR&include=tax`)
applyDiscount(cart, 'SUMMER-2026')
})
22 changes: 22 additions & 0 deletions capture/lib/frames.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ describe('capture fingerprint', () => {
}
})

describe('scrubbing the log view clock', () => {
const muted = '\u001B[90m'
const reset = '\u001B[39m'
const log = (rows: string[]) => buildFingerprint([{ at: 0, data: rows.join('\r\n') }], { rows: 24, scrubRules: ['dates', 'clock'] })

it('should not depend on which rows the time was printed on', () => {
const shown = log([` ${muted}14:42:32${reset} Vite server built`, ` ${muted}14:42:33${reset} [nitro] built`])
const blank = log([` ${muted}14:42:32${reset} Vite server built`, `${' '.repeat(11)}[nitro] built`])
expect(blank).toBe(shown)
})

it('should blank the time before an indented message', () => {
expect(log([` ${muted}14:42:32${reset} ➜ DevTools`])).toBe(log([`${' '.repeat(13)}➜ DevTools`]))
})

it('should keep the gutter and indentation of continuation rows', () => {
const lines = log([`\u001B[32mβ–Ž \u001B[39m${muted}14:42:32${reset} selected`, `${' '.repeat(13)}continued`]).split('\n')
expect(lines).toContain(`β–Ž${' '.repeat(10)}selected`)
expect(lines).toContain(`${' '.repeat(13)}continued`)
})
})

describe('scrubbing a right-aligned tag', () => {
const TAG = 'nitro'
const WIDTH = 96
Expand Down
13 changes: 12 additions & 1 deletion capture/lib/scrub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { homedir } from 'node:os'
interface ScrubStep {
pattern: RegExp
replacement: (match: RegExpMatchArray) => string
/** Leave the replacement unstyled instead of inheriting the first replaced character's style. */
unstyled?: boolean
}

interface ScrubRule {
Expand Down Expand Up @@ -78,6 +80,15 @@ const RULES: Record<string, ScrubRule> = {
{ pattern: /\b\d{2}:\d{2}:\d{2}\b/g, replacement: () => '12:00:00' },
],
},
clock: {
id: 'clock',
description: 'log view clock column blanked',
steps: [
// The log view only prints a time that differs from the row above, so
// which rows carry one depends on where the seconds fell.
{ pattern: /(?<=^.{2})(?:\d{2}:\d{2}:\d{2}| {8}) (?= *\S)/g, replacement: () => ' '.repeat(9), unstyled: true },
],
},
spinner: {
id: 'spinner',
description: 'spinner glyphs pinned to one phase',
Expand Down Expand Up @@ -172,7 +183,7 @@ function applyStep(line: string, styles: (Style | undefined)[], step: ScrubStep)
const replacement = step.replacement(match)
out += replacement
for (let index = 0; index < replacement.length; index++) {
outStyles.push(styles[start])
outStyles.push(step.unstyled ? undefined : styles[start])
}
last = start + match[0].length
}
Expand Down
Loading
Loading