David-Kunz / jester

A Neovim plugin to easily run and debug Jest tests
The Unlicense
200 stars 11 forks source link

How to override CMD and run both files and specific tests? #11

Closed tomspeak closed 2 years ago

tomspeak commented 2 years ago

I am using create-react-app so need to override the cmd to make sure it's loaded correctly.

require("jester").setup({
  cmd = "NODE_PATH=. react-scripts test --testPathPattern=$file --testNamePattern='$result'",
})

This works great for

:lua require"jester".run()

But it breaks

:lua require"jester".run_file()

because it tries to filter test names matching /$result/

David-Kunz commented 2 years ago

Hi @tomspeak ,

When you execute run_file, then there is no $result replacement, this is only available for tests/test suites.

You could overwrite cmd only for run like this:

require"jester".run({ cmd = "NODE_PATH=. react-scripts test --testPathPattern=$file --testNamePattern='$result'" })
tomspeak commented 2 years ago

That's exactly what I needed thank you!

My final set up that's working is

MY_JESTER = require("jester")
MY_JESTER.setup({})
vim.api.nvim_set_keymap(
  "n",
  "<leader>t",
  "<cmd>lua MY_JESTER.run({ cmd = 'NODE_PATH=. react-scripts test --testPathPattern=$file --testNamePattern=\\'$result\\'' })<CR>"
  ,
  { noremap = true }
)
vim.api.nvim_set_keymap(
  "n",
  "<leader>T",
  "<cmd>lua require'jester'.run_file({ cmd = 'NODE_PATH=. react-scripts test --testPathPattern=$file' })<CR>",
  { noremap = true }
)

I'm new to neovim/lua, appreciate if you spot anything bad!