microsoft/rushstack

[heft] heft-jest-plugin: jest --outputFile argument cannot be invoked

DavidRieman opened this issue · 3 comments

Summary

Ideally we should be able to route heft test output to a file with a regular command line arguments instead of requiring > or | piping.

Jest has a helpful CLI argument outputFile which accomplishes this output routing and might be a little more platform-agnostic than relying on shell specifics for > or |. However, the heft jest plugin does not acknowledge and forward this helpful argument, so it blocks us from using it.

Repro steps

  • heft run --only test --output-file=temp/test.log

Expected result:
Run the tests, with Jest itself sending output to the target file.

Actual result:
heft run: error: Unrecognized arguments: --output-file=temp/test.log

Details

I'm proposing we rig heft-jest-plugin to forward an argument of the form --output-file=path to the Jest --outputFile=path CLI argument form. Since adding this is probably very similar to my last contribution a while ago, I'd be willing to perform this upgrade myself, if you guys consider this feature worth merging. (I checked and see latest code doesn't have this.)

Standard questions

Question Answer
@rushstack/heft version? 0.63.2
Operating system? Windows
Would you consider contributing a PR? Yes
Node.js version (node -v)? v18.16.1

What would you want this argument to do? Would it forward all of the Heft logs to the specified file, or would it just forward Jest's portion of the logs? Heft does its own logging for Jest, so, presumably that would get disabled with this argument.

This feels like it should be able to be accomplished by adding a reporter to the Jest config, or modifying the reporter configuration.

I think we'd consider taking this contribution, depending on how this would actually work. There's also a consideration around watch mode: what would the expected behavior in that case base?

We could also consider implementing a feature allowing all of Heft's logs to be written to a file (or files - for STDOUT and STDERR) via a CLI parameter.

I was thinking it would just forward the argument to jest, and only work with the jest output. If so, now I guess the format would be more like: heft run --only test --jest-output-file=temp/test.log.

That said, capturing all of the wrapping heft logging plus the jest output itself in one searchable log file does sound more generically useful for more automated analysis scenarios - just a larger change than I can commit to contribute myself.