Skip to content

Commit

Permalink
add neotest (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
pr7prashant committed Aug 27, 2024
1 parent d60410b commit 3bf88d1
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
"FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" },
"LuaSnip": { "branch": "master", "commit": "b84eeb3641b08324287587b426ec974b888390d9" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
Expand All @@ -17,10 +18,13 @@
"mini.nvim": { "branch": "main", "commit": "7e30f58071dd963f2a6e81415aa121eb090da2c0" },
"neo-tree.nvim": { "branch": "main", "commit": "8c75e8a2949cd6cd35525799200a8d34471ee9eb" },
"neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" },
"neotest": { "branch": "master", "commit": "32ff2ac21135a372a42b38ae131e531e64833bd3" },
"neotest-jest": { "branch": "main", "commit": "514fd4eae7da15fd409133086bb8e029b65ac43f" },
"nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" },
"nvim-autopairs": { "branch": "master", "commit": "48ca9aaee733911424646cb1605f27bc01dedbe3" },
"nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
"nvim-lspconfig": { "branch": "master", "commit": "a89de2e049b5f89a0ee55029d5a31213bd4de6f8" },
"nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" },
"nvim-treesitter": { "branch": "master", "commit": "63e1337f1b60c84a4100ebedfb1dc80924c49122" },
"nvim-treesitter-context": { "branch": "master", "commit": "0f3332788e0bd37716fbd25f39120dcfd557c90f" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "375c2d86cee6674afd75b4f727ce3a80065552f7" },
Expand Down
4 changes: 2 additions & 2 deletions lua/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ vim.keymap.set('i', 'jk', '<Esc>')
-- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous Diagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next Diagnostic message' })
vim.keymap.set('n', '<leader>de', vim.diagnostic.open_float, { desc = 'Show Diagnostic Error messages' })
vim.keymap.set('n', '<leader>dq', vim.diagnostic.setloclist, { desc = 'Open Diagnostic Quickfix list' })
vim.keymap.set('n', '<leader>De', vim.diagnostic.open_float, { desc = 'Show Diagnostic Error messages' })
vim.keymap.set('n', '<leader>Dq', vim.diagnostic.setloclist, { desc = 'Open Diagnostic Quickfix list' })

-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
Expand Down
4 changes: 2 additions & 2 deletions lua/plugins/gitsigns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ M.config = function()
gitsigns.blame_line { full = true }
end, { desc = 'Blame Line' })
map('n', '<leader>gtb', gitsigns.toggle_current_line_blame, { desc = 'Toggle Current Line Blame' })
map('n', '<leader>tb', gitsigns.toggle_current_line_blame, { desc = 'Git Toggle Current Line Blame' })
map('n', '<leader>Tb', gitsigns.toggle_current_line_blame, { desc = 'Git Toggle Current Line Blame' })
map('n', '<leader>hd', gitsigns.diffthis, { desc = 'Diff This' })
map('n', '<leader>hD', function()
gitsigns.diffthis '~'
end, { desc = 'Diff This ~' })
map('n', '<leader>gtd', gitsigns.toggle_deleted, { desc = 'Toggle Deleted' })
map('n', '<leader>td', gitsigns.toggle_deleted, { desc = 'Git Toggle Deleted' })
map('n', '<leader>Td', gitsigns.toggle_deleted, { desc = 'Git Toggle Deleted' })

-- Text object
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', { desc = 'Select Hunk' })
Expand Down
2 changes: 1 addition & 1 deletion lua/plugins/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ local M = {
--
-- This may be unwanted, since they displace some of your code
if client and client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then
map('<leader>th', function()
map('<leader>Th', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end, 'Toggle Inlay Hints')
end
Expand Down
103 changes: 103 additions & 0 deletions lua/plugins/neotest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
local M = {
'nvim-neotest/neotest',
dependencies = {
'nvim-neotest/nvim-nio',
'nvim-lua/plenary.nvim',
'antoinemadec/FixCursorHold.nvim',
'nvim-treesitter/nvim-treesitter',
'nvim-neotest/neotest-jest',
},

config = function()
require('neotest').setup {
adapters = {
require 'neotest-jest' {
jestCommand = 'npm test --',
jestConfigFile = function(file)
if string.find(file, '/packages/') and string.match(file, '(.-/[^/]+/)src') then
return string.match(file, '(.-/[^/]+/)src') .. 'jest.config.ts'
end

return vim.fn.getcwd() .. '/jest.config.ts'
end,
env = { CI = true },
cwd = function(file)
if string.find(file, '/packages/') then
return string.match(file, '(.-/[^/]+/)src')
end
return vim.fn.getcwd()
end,
},
},
}
end,

keys = {
{ '<leader>t', '', desc = '+test' },
{
'<leader>tt',
function()
require('neotest').run.run(vim.fn.expand '%')
end,
desc = 'Run File',
},
{
'<leader>tT',
function()
require('neotest').run.run(vim.uv.cwd())
end,
desc = 'Run All Test Files',
},
{
'<leader>tr',
function()
require('neotest').run.run()
end,
desc = 'Run Nearest',
},
{
'<leader>tl',
function()
require('neotest').run.run_last()
end,
desc = 'Run Last',
},
{
'<leader>ts',
function()
require('neotest').summary.toggle()
end,
desc = 'Toggle Summary',
},
{
'<leader>to',
function()
require('neotest').output.open { enter = true, auto_close = true }
end,
desc = 'Show Output',
},
{
'<leader>tO',
function()
require('neotest').output_panel.toggle()
end,
desc = 'Toggle Output Panel',
},
{
'<leader>tS',
function()
require('neotest').run.stop()
end,
desc = 'Stop',
},
{
'<leader>tw',
function()
require('neotest').watch.toggle(vim.fn.expand '%')
end,
desc = 'Toggle Watch',
},
},
}

return M
6 changes: 4 additions & 2 deletions lua/plugins/which-key.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ local M = {
mode = { 'n', 'v' },
{ '<leader>b', group = 'Buffer' },
{ '<leader>c', group = 'Code' },
{ '<leader>d', group = 'Diagnostics' },
{ '<leader>d', group = 'Debug' },
{ '<leader>D', group = 'Diagnostics' },
{ '<leader>g', group = 'Git' },
{ '<leader>gt', group = 'Git Toggle' },
{ '<leader>h', group = 'Git Hunk' },
{ '<leader>l', group = 'LSP' },
{ '<leader>T', group = 'Toggle' },
{ '<leader>s', group = 'Search' },
{ '<leader>t', group = 'Toggle' },
{ '<leader>t', group = 'Test' },
{ 'g', group = 'Goto' },
{ 'z', group = 'Fold' },
{ '[', group = 'Prev' },
Expand Down

0 comments on commit 3bf88d1

Please sign in to comment.