jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.82k stars 291 forks source link

[FEATURE] Support ability to interpolate extension arguments in `jest.jestCommandLine` instead of appending #1156

Open djohnson-aperture opened 3 weeks ago

djohnson-aperture commented 3 weeks ago

Is your feature request related to a problem? Please describe. It would be convenient to offer a way to specify a spot within the test command to indicate where the extension args should be placed. I have a weird case where my jest command is actually provided to another command, but appending the arguments to the end fails to put the in the right context. Example Command: npx firebase emulators:exec 'jest'

Unfortunate Extension Command: npx firebase emulators:exec 'jest' --testNamePattern StudentPortalService --testPathPattern /Users/user/.../src/example\.spec\.ts

Describe the solution you'd like Detect a $JEST_EXTENSION_ARGS variable in the configured jest.jestCommandLine. If present, expand the arguments in its place. Otherwise, append arguments to end, as they're done now.

In my example, I would set jest.jestCommandLine to: npx firebase emulators:exec 'jest $JEST_EXTENSION_ARGS' which would expand to: npx firebase emulators:exec 'jest --testNamePattern StudentPortalService --testPathPattern /Users/user/.../src/example\.spec\.ts' and properly pass the args to the secondary command. To be clear, note that the arguments are now within the single quoted jest command, instead of trailing it.

Describe alternatives you've considered I've tried to find a solution using npm script variables, but there doesn't seem to be one that equates to "all trailing arguments".

connectdotz commented 2 weeks ago

hmmm... will a shell-script like the following work? Let's call this my-jest.sh:

# !/bin/sh
npx firebase emulators:exec 'jest $@'

then set "jest.jestCommandLine": ./my-jest.sh