Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Ability to run test of current scope #486

Open
maxkuzn opened this issue Feb 12, 2025 · 0 comments
Open

[Feature] Ability to run test of current scope #486

maxkuzn opened this issue Feb 12, 2025 · 0 comments

Comments

@maxkuzn
Copy link

maxkuzn commented Feb 12, 2025

Description

Currently, when running the nearest test using:

require("neotest").run.run()

Neotest executes the first test before the current line. However, in some cases, tests can be nested. For example, in Go:

func TestFoo(t *testing.T) {
	t.Run("subtest 1", func(t *testing.T) {
		// ...
	})

	// cursor here

	t.Run("subtest 2", func(t *testing.T) {
		// ...
	})
}

If the cursor is placed between t.Run("subtest 1") and t.Run("subtest 2"), I would expect Neotest to run the entire TestFoo. However, it currently runs "subtest 1".

Additionally, the summary buffer highlights "subtest 1", but I would expect it to highlight TestFoo, since the cursor isn't inside "subtest 1" anymore.

Expected Behavior

Neotest should run the test that fully contains the cursor, rather than defaulting to the first test before it.

Proposal

Would it be possible to add an option to run the most specific (innermost) test scope that the cursor is currently inside?
As I see it, it can be done either with additional option for neotest configuration or option for specified functions: run.run() and summary.open().

P.S. I'm willing to contribute a fix for this, but I’d need some guidance.

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

No branches or pull requests

1 participant