Skip to content

refactor: Use npx jest as default jest_cmd#7

Open
SirWrexes wants to merge 3 commits into
mattkubej:masterfrom
SirWrexes:npx-jest
Open

refactor: Use npx jest as default jest_cmd#7
SirWrexes wants to merge 3 commits into
mattkubej:masterfrom
SirWrexes:npx-jest

Conversation

@SirWrexes
Copy link
Copy Markdown

  • Slightly better start perf: No need to climb the directory tree
  • More flexible: Either runs the locally installed version or asks to install it temporarily*
  • Jest users (should) always have NPM installed, and as such, have npx available.

*A temporary install through npx still requires a config file present somewhere in the current working directory or above in the tree.
A default config file could fix that, but I think it should be the user's choice to set it up or not.
However, it would be nice to have an option to set the path to a global config file, and maybe recycle the old tree-climbing functions to find a local config, and then use the default if none is found... But then that wouldn't work with Jest configs from inside package.json. 😕

@SirWrexes
Copy link
Copy Markdown
Author

Woops, it seems my formatter aggressively shifted all indentation there.

+ Slightly better start perf: No need to climb the directory tree
+ More flexible: Can run Jest outside of projects
+ Jest users (should) always have NPM installed, and as such, have `npx`
  available.
This patch allows users to set `jest_cmd` via the global `g:jest_cmd`.
Useful for [per-project configuration](https://github.com/windwp/nvim-projectconfig).

The global variable `g:jest_cmd` will **always** have precedence over plugin
configuration.
@SirWrexes
Copy link
Copy Markdown
Author

I've got this use-case where I'm using ts-jest in a mono-repo and Jest is not picking up the TS configuration for one of the modules of the repo.
I wanted to be able to set a per-project config that would let me override jest_cmd with pnpm $(git rev-parse --show-toplevel)/relative/path/to/module test so I've added 9474264.

I'm using nvim-projectconfig and have a simple lua file for my project containing vim.g.jest_cmd = that long command thing and it works like a charm !

Remove unnecessary dependency Jest (all that's really needed is `npm`).
Update comment about `jest_cmd` to accomodate new features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant