Skip to content

Testing

prjctimg edited this page Aug 5, 2026 · 1 revision

Testing

p5.nvim has two test suites: a Lua suite (Plenary Busted) for the Neovim side and a Python suite (pytest) for server.py.

Lua Tests

Located under tests/p5/, run with Plenary:

nvim --headless --clean -u tests/init.lua \
  -c "PlenaryBustedDirectory tests/p5/ {init='tests/init.lua', sequential=true}" \
  -c "qa!"

sequential=true and the init option are required: Plenary launches a separate child nvim per spec file without -u tests/init.lua, so the spawn guard must be injected through the init option rather than the invocation.

The Spawn Guard

tests/init.lua installs a global spawn guard that wraps vim.fn.jobstart, vim.fn.system, and vim.system. Any command that would launch a real browser or network process is dropped deterministically (the on_exit callback fires synchronously, but no process is started):

  • Browsers: chrome, chromium, google-chrome, chromium-browser, microsoft-edge
  • Openers: xdg-open, open
  • Network: curl, wget
  • The dev server: python3 …server.py

This guarantees that a test run can never orphan real Chrome windows or hit the network — the single most important invariant for keeping the suite fast and hermetic. Because specs capture module functions after init.lua loads, a spec's after_each restoring orig_jobstart restores the guard, so deferred callbacks (e.g. vim.defer_fn(launch_browser, 300)) can never reach the real process.

Specs

Spec Covers
core_spec.lua path resolution, config, cache
cdp_spec.lua panel open/close, connect, eval, breakpoints, screenshot, perf, canvas state
server_spec.lua server lifecycle gating
project_spec.lua sketchspace scaffolding
libraries_spec.lua library install/uninstall logic
gist_spec.lua gist create/sync/edit (stubbed gh)
gist_integration_spec.lua real GitHub calls — gated behind P5_NETWORK_TESTS=1, off by default
health_spec.lua :checkhealth p5
docs_spec.lua generated docs/help consistency
no_spawn_spec.lua verifies the spawn guard itself

Python Tests

The server.py logic (HTTP routing, CDP proxy, perf sampling, breakpoint resolution) is tested with pytest:

python3 -m pytest tests/test_cdp_client.py -q

These tests mock the Chrome debugging endpoint, so no browser is required.

Linting / Formatting

  • Lua — stylua with the repo's .stylua.toml (tabs, 120-column width)
  • Python — the suite follows pep8 conventions; keep server.py dependency-free

CI

Pushing a tag (v*) runs the full suite in CI before creating the release — see .github/workflows/release.yml.

Clone this wiki locally