Skip to content

fix: stop a file spinning forever when its tests aren't discovered yet - #20

Merged
wassimk merged 3 commits into
mainfrom
wm/fix-stuck-neotest-spinner
Nov 2, 2026
Merged

wassimk merged 3 commits into
mainfrom
wm/fix-stuck-neotest-spinner

Conversation

@wassimk

@wassimk wassimk commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Pressing <leader>tt (neotest.run.run()) before neotest had discovered a file's tests left the file's spinner running forever in the summary. Running the test again didn't clear it. Running the whole file did.

Cause

With no test children yet, neotest's nearest position is the file. Our build_spec had no items for it and returned nil. neotest then breaks the run into tests, finds none, and ends without results. It only clears "running" for positions that get a result, so the file stayed running.

Fix

  • build_spec discovers an undiscovered file on the spot (the same discoverTests call, factored out of discover_positions). It runs the test at the cursor when the file is in the current window, and every test otherwise.
  • A file with no tests at all raises an error, which neotest reports and uses to clear the running state.
  • results always reports the position that was run.

Testing

  • make test: 200 passing, 0 failures. The four new tests failed before the fix.
  • make lint: clean
  • Reproduced in a large Rails app (headless): before, the file stayed running with no result. After, the run resolved bin/rails test …/donation_test.rb:163 for the test under the cursor, passed, and the file stopped running.

Running the nearest test before neotest had discovered a file's tests
made neotest run the file itself. With no test items, build_spec
returned nil, neotest found nothing to split the run into, and the
file never got a result, so it stayed marked as running until the
whole file was run.

build_spec now discovers the file on the spot and runs the test at the
cursor, or every test when the file isn't in the current window. It
errors when the file has no tests, which neotest reports and clears.
results also always reports the position that was run.
@wassimk wassimk self-assigned this Nov 2, 2026
…back

collect_leaf_items returns a fresh list, the no-tests error lives with
the discovery it checks, and results keeps one fallback for the run
position instead of two copies of the failed result. The cursor
fixture in the spec uses luassert stubs.
Raising from build_spec skipped neotest's runner cleanup, so the file
stayed in its running table, and the message arrived wrapped in a stack
trace. Now the fallback notifies with a short reason and returns a spec
that exits at once, which results marks as skipped.

A failed discovery says so instead of reporting no tests, and the
current-buffer check compares resolved paths so symlinked projects
still pick the test at the cursor.
@wassimk
wassimk merged commit dc7cb87 into main Nov 2, 2026
3 checks passed
@wassimk
wassimk deleted the wm/fix-stuck-neotest-spinner branch November 2, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant