Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

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-jest CLI wrapper that translates Jest CLI arguments to Heft equivalents, enabling seamless VSCode Jest extension integration.

Details

  • bin/heft-jest - Binary entry point
  • src/heft-jest-cli.ts - Parses Jest CLI args and spawns heft test or heft test-watch with translated parameters
  • Parameter translation:
    Jest Heft
    --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 / --watch Uses heft test-watch
  • VSCode-specific parameters (--json, --outputFile, --reporters, etc.) are filtered out

Usage (.vscode/settings.json):

{
  "jest.jestCommandLine": "npx heft-jest"
}

How it was tested

  • 29 unit tests covering argument translation, watch mode detection, and parameter filtering
  • Manual verification with typical VSCode Jest extension argument sets:
    node bin/heft-jest --testLocationInResults --json --outputFile "/tmp/results.json" \
      --no-coverage --reporters "default" --watchAll=false --testPathPattern "MyTest"
    # Output: [heft-jest] Running: heft test --disable-code-coverage --test-path-pattern MyTest
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:

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

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 is

"scripts": {
  "build": "heft build --clean",
  "test":"heft test-watch"
},

However, the Test results window now shows:

heft test-watch C:\Users\PAULSC~1\AppData\Local\Temp\jest_runner_heft_appconfig_plugin_paulschaeflein.json default c:\Users\PaulSchaeflein.vscode\extensions\orta.vscode-jest-6.4.4\out\reporter.js

usage: heft test-watch [-h] [-v] [--production] [--locales LOCALE] [--clean]
[--config RELATIVE_PATH] [--debug-heft-reporter]
[--detect-open-handles] [--disable-code-coverage]
[--find-related-tests SOURCE_FILE] [--log-heap-usage]
[--max-workers COUNT_OR_PERCENTAGE] [--silent]
[-t REGEXP] [--test-path-ignore-patterns REGEXP]
[--test-path-pattern REGEXP]
[--test-timeout-ms TIMEOUT] [-u] [--fix] [--serve]

heft test-watch: error: Unrecognized arguments: C:\Users\PAULSC~1\AppData\Local\Temp\jest_runner_heft_appconfig_plugin_paulschaeflein.json default c:\Users\PaulSchaeflein.vscode\extensions\orta.vscode-jest-6.4.4\out\reporter.js.

{
  "error": {
    "code": 1,
    "summary": "",
    "detail": ""
  }
}

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:

--testLocationInResults --json --useStderr --outputFile "C:\\Users\\PAULSC~1\\AppData\\Local\\Temp\\jest_runner_heft_appconfig_plugin_paulschaeflein_2.json --no-coverage --reporters "default" --reporters "c:\\Users\\PaulSchaeflein\\.vscode\\extensions\\orta.vscode-jest-6.4.4\\out\\reporter.js --colors --watchAll=false

In the Zulip thread, @octogonz added the following (and requested this issue):

The main work item is just to expose those CLI parameters as equivalent Heft parameters, and then provide a small heft-jest script that discards irrelevant parameters and remaps any slightly renamed parameters, when invoking Heft.

The important parameters are: --testLocationInResults, --json, --useStderr, --outputFile, --no-coverage, --reporters

But we would probably consolidate them, something like:

  • Heft --testResultsFile (equilalent to Jest --json + --useStderr + --outputFile)
  • --testLocationInResults
  • --no-coverage
  • Heft --testReporter (equivalent to Jest --reporters, but without delusions of removing HeftJestReporter)

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@rushstack/heft version? 1.1.6
Operating system? Windows
Would you consider contributing a PR? No (I am not talented enough to do that.)
Node.js version (node -v)? 22.16.0
</issue_description>

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.

Copilot AI and others added 2 commits December 3, 2025 19:44
…ension integration

Co-authored-by: iclanton <5010588+iclanton@users.noreply.github.com>
Co-authored-by: iclanton <5010588+iclanton@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate heft with VSCode extension for Jest [heft-jest-plugin] Add heft-jest CLI wrapper for VSCode Jest extension integration Dec 3, 2025
Copilot AI requested a review from iclanton December 3, 2025 20:05
Copilot finished work on behalf of iclanton December 3, 2025 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

[heft] Integrate with VSCode extension for Jest

2 participants