|
| 1 | +--- |
| 2 | +name: quarto-preview-test |
| 3 | +description: Use when testing preview functionality, verifying live reload, or validating preview fixes. Covers starting preview with port/logging, browser verification via /agent-browser, and checking logs/filesystem for artifacts. |
| 4 | +--- |
| 5 | + |
| 6 | +# Quarto Preview Test |
| 7 | + |
| 8 | +Interactive testing of `quarto preview` with automated browser verification. |
| 9 | + |
| 10 | +## Tools |
| 11 | + |
| 12 | +| Tool | When to use | |
| 13 | +|------|-------------| |
| 14 | +| `/agent-browser` | **Preferred.** Token-efficient browser automation. Navigate, verify content, screenshot. | |
| 15 | +| Chrome DevTools MCP | Deep debugging: console messages, network requests, DOM inspection. | |
| 16 | +| `jq` / `grep` | Parse debug log output. | |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- Quarto dev version built (`./configure.sh` or `./configure.cmd`) |
| 21 | +- Test environment configured (`tests/configure-test-env.sh` or `.ps1`) |
| 22 | +- `/agent-browser` CLI installed (preferred), OR Chrome + Chrome DevTools MCP connected |
| 23 | + |
| 24 | +## Starting Preview |
| 25 | + |
| 26 | +Preview needs the test venv for Jupyter tests. Activate it first (`tests/.venv`), matching how `run-tests.sh` / `run-tests.ps1` do it. |
| 27 | + |
| 28 | +```bash |
| 29 | +# Linux/macOS |
| 30 | +source tests/.venv/bin/activate |
| 31 | +./package/dist/bin/quarto preview <file-or-dir> --no-browser --port 4444 |
| 32 | + |
| 33 | +# Windows (Git Bash) |
| 34 | +source tests/.venv/Scripts/activate |
| 35 | +./package/dist/bin/quarto.cmd preview <file-or-dir> --no-browser --port 4444 |
| 36 | +``` |
| 37 | + |
| 38 | +Use `--no-browser` to control browser connection. Use `--port` for a predictable URL. |
| 39 | + |
| 40 | +### With debug logging |
| 41 | + |
| 42 | +```bash |
| 43 | +./package/dist/bin/quarto preview <file> --no-browser --port 4444 --log-level debug 2>&1 | tee preview.log |
| 44 | +``` |
| 45 | + |
| 46 | +### In background |
| 47 | + |
| 48 | +```bash |
| 49 | +# Linux/macOS (after venv activation) |
| 50 | +./package/dist/bin/quarto preview <file> --no-browser --port 4444 & |
| 51 | +PREVIEW_PID=$! |
| 52 | +# ... run verification ... |
| 53 | +kill $PREVIEW_PID |
| 54 | + |
| 55 | +# Windows (Git Bash, after venv activation) |
| 56 | +./package/dist/bin/quarto.cmd preview <file> --no-browser --port 4444 & |
| 57 | +PREVIEW_PID=$! |
| 58 | +# ... run verification ... |
| 59 | +kill $PREVIEW_PID |
| 60 | +``` |
| 61 | + |
| 62 | +## Edit-Verify Cycle |
| 63 | + |
| 64 | +The core test pattern: |
| 65 | + |
| 66 | +1. Start preview with `--no-browser --port 4444` |
| 67 | +2. Use `/agent-browser` to navigate to `http://localhost:4444/` and verify content |
| 68 | +3. Edit source file, wait 3-5 seconds for re-render |
| 69 | +4. Verify content updated in browser |
| 70 | +5. Check filesystem for unexpected artifacts |
| 71 | +6. Stop preview, verify cleanup |
| 72 | + |
| 73 | +## What to Verify |
| 74 | + |
| 75 | +**In browser** (via `/agent-browser`): Page loads, content matches source, updates reflect edits. |
| 76 | + |
| 77 | +**In terminal/logs**: No `BadResource` errors, no crashes, preview stays responsive. |
| 78 | + |
| 79 | +**On filesystem**: No orphaned temp files, cleanup happens on exit. |
| 80 | + |
| 81 | +## Windows Limitations |
| 82 | + |
| 83 | +On Windows, `kill` from Git Bash does not trigger Quarto's `onCleanup` handler (SIGINT doesn't propagate to Windows processes the same way). Cleanup-on-exit verification requires an interactive terminal with Ctrl+C. For automated testing, verify artifacts *during* preview instead. |
| 84 | + |
| 85 | +## Context Types |
| 86 | + |
| 87 | +Preview behaves differently depending on input: |
| 88 | + |
| 89 | +| Input | Code path | |
| 90 | +|-------|-----------| |
| 91 | +| Single file (no project) | `preview()` -> `renderForPreview()` | |
| 92 | +| File within a project | May redirect to project preview via `serveProject()` | |
| 93 | +| Project directory | `serveProject()` -> `watchProject()` | |
| 94 | + |
| 95 | +See `llm-docs/preview-architecture.md` for the full architecture. |
| 96 | + |
| 97 | +## When NOT to Use |
| 98 | + |
| 99 | +- Automated smoke tests — use `tests/smoke/` instead |
| 100 | +- Testing render output only (no live preview needed) — use `quarto render` |
| 101 | +- CI environments without browser access |
| 102 | + |
| 103 | +## Test Matrix |
| 104 | + |
| 105 | +The full test matrix lives in `tests/docs/manual/preview/README.md`. Test fixtures live alongside it in `tests/docs/manual/preview/`. |
| 106 | + |
| 107 | +### Running specific tests by ID |
| 108 | + |
| 109 | +When invoked with test IDs (e.g., `/quarto-preview-test T17 T18`): |
| 110 | + |
| 111 | +1. Read `tests/docs/manual/preview/README.md` |
| 112 | +2. Find each requested test by its ID (e.g., `#### T17:`) |
| 113 | +3. Parse the **Setup**, **Steps**, and **Expected** fields |
| 114 | +4. Execute each test following the steps, using the fixtures in `tests/docs/manual/preview/` |
| 115 | +5. Report PASS/FAIL for each test with the actual vs expected result |
| 116 | + |
| 117 | +### Running tests by topic |
| 118 | + |
| 119 | +When invoked with a topic description instead of IDs (e.g., `/quarto-preview-test root URL` or "run preview tests for single-file"): |
| 120 | + |
| 121 | +1. Read `tests/docs/manual/preview/README.md` |
| 122 | +2. Search test titles and descriptions for matches (keywords, issue numbers, feature area) |
| 123 | +3. Present the matched tests to the user for confirmation before running: |
| 124 | + ``` |
| 125 | + Found these matching tests: |
| 126 | + - T17: Single-file preview — root URL accessible (#14298) |
| 127 | + - T18: Single-file preview — named output URL also accessible |
| 128 | + Run these? [Y/n] |
| 129 | + ``` |
| 130 | +4. Only execute after user confirms |
| 131 | + |
| 132 | +### Running without arguments |
| 133 | + |
| 134 | +When invoked without test IDs or topic (e.g., `/quarto-preview-test`), use the general Edit-Verify Cycle workflow described above for ad-hoc preview testing. The test matrix is for targeted regression testing. |
| 135 | + |
| 136 | +## Baseline Comparison |
| 137 | + |
| 138 | +Compare dev build against installed release to distinguish regressions: |
| 139 | + |
| 140 | +```bash |
| 141 | +quarto --version # installed |
| 142 | +./package/dist/bin/quarto --version # dev |
| 143 | +``` |
| 144 | + |
| 145 | +If both show the same issue, it's pre-existing. |
0 commit comments