Fix subprocess module loading issue for build_position #185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When
build_positionis passed as a string'require("neotest-jest").build_position'tolib.treesitter.parse_positions(), it fails to load in subprocess context. This causes several issues:module 'neotest-jest' not founderrorsThis issue was reported in #165.
Root Cause
Neotest uses subprocesses for parsing test positions for performance. When a string is passed as
build_position, neotest tries toloadstring()and execute it in the subprocess. However, in the subprocess context,require("neotest-jest")fails because the module isn't properly loaded in that isolated environment.From the neotest source code:
The subprocess tries to execute
require("neotest-jest").build_positionbut the module context doesn't exist there.Solution
This PR changes line 286 from:
To:
By passing the function directly instead of a string reference, neotest automatically disables subprocess mode for this adapter (as documented in neotest's code):
This fallback to non-subprocess parsing avoids all module loading issues while maintaining functionality.
Trade-offs
Testing
Tested with:
.test.ts,.spec.js)Fixes #165