[heft-jest-plugin] Add heft-jest CLI wrapper for VSCode Jest extension integration #5485
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.
Summary
Fixes #5483
The VSCode Jest extension cannot work with Heft because it sends Jest-specific CLI parameters (
--testLocationInResults,--json,--outputFile,--reporters, etc.) that Heft doesn't recognize.This PR adds a
heft-jestCLI wrapper that translates Jest CLI arguments to Heft equivalents, enabling seamless VSCode Jest extension integration.Details
bin/heft-jest- Binary entry pointsrc/heft-jest-cli.ts- Parses Jest CLI args and spawnsheft testorheft test-watchwith translated parameters--testPathPattern--test-path-pattern--testNamePattern/-t--test-name-pattern--updateSnapshot/-u--update-snapshots--maxWorkers--max-workers--testTimeout--test-timeout-ms--no-coverage--disable-code-coverage--watchAll/--watchheft test-watch--json,--outputFile,--reporters, etc.) are filtered outUsage (
.vscode/settings.json):{ "jest.jestCommandLine": "npx heft-jest" }How it was tested
Original prompt
This section details on the original issue you should resolve
<issue_title>[heft] Integrate with VSCode extension for Jest</issue_title>
<issue_description>## Summary
This issue relates to the conversation in the Rush stack Zulip forum: #heft > Jest extension in VSCode
When using the heft-jest-plugin, the Jest extension to VSCode cannot start, and thus Testing panel and Test Results window are inoperable.
Running tests via the command-line works as expected -- the actual Jest tests are executed and reported as expected.
Details
Navigate to the Testing pane, and run tests. The TestResults window shows an error:
This is expected. The heft-jest-plugin documentation discusses the differences from ts-jest. The key point is that Jest expects to transform Typescript itself from the src folder, while heft-jest-plugin runs tests from transformed code, typically in the lib folder.
While expected, it is not the desired result.
The extension allows for changing the start command. I tried using the command
npm run test(and the package.json entry isHowever, the Test results window now shows:
The extension's start command is expected to receive a specific set of parameters that are passed to the Jest command. Those parameters are as follows:
In the Zulip thread, @octogonz added the following (and requested this issue):
Standard questions
Please answer these questions to help us investigate your issue more quickly:
@rushstack/heftversion?node -v)?Comments on the Issue (you are @copilot in this section)
@iclanton This would be useful. Creating a script to wrap `heft test` (assuming that's what the project's rig or `heft.json` specifies, although it could try to dynamically determine the Heft command) in something that the extension can call probably wouldn't be too complex. Lets's see if Copilot is able to come up with something, or at least a starting point.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.