aboutsummaryrefslogtreecommitdiffstats
path: root/lua/plugins/test.lua
blob: e2cfb59539030a92d4a9712560499783ac2e6181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
return {
  "vim-test/vim-test",
  keys = { { "<leader>t", desc = "Open Test menu" } },
  dependencies = {
    "anuvyklack/hydra.nvim",
  },
  config = function()
    local hydra = require "hydra"

    vim.cmd [[
    let test#php#pest#executable = './vendor/bin/sail test'
    let test#strategy = 'harpoon'
    let test#neovim#term_position = 'vert'
    let g:test#preserve_screen = 0
    let g:test#harpoon_term = 3
    let g:test#harpoon#gototerminal= 0
]]

    local hint = [[
 Vim Tests
 _n_: Near test  _f_: Current file   _s_: Test Suit ^
 _l_: Test Last  _g_: Visit
 _w_: Watch last Test  _p_: stop watch
 ^ ^                                          _<Esc>_ ^
]]
    local auto_cmd_id = nil
    local stopAutoCommand = function()
      if auto_cmd_id ~= nil then
        vim.api.nvim_del_autocmd(auto_cmd_id)
        auto_cmd_id = nil
      end
    end
    local startAutoCommand = function()
      stopAutoCommand()
      auto_cmd_id = vim.api.nvim_create_autocmd({"BufWritePost"}, {
        pattern = {"*.php", "*.feature", "*.yaml"},
        command  = "TestLast",
      })
    end

    hydra {
      name = "vimtest",
      hint = hint,
      mode = "n",
      config = {
        color = "teal",
        invoke_on_body = true,
        hint = {
          border = "rounded",
          position = "bottom",
        },
      },
      body = "<leader>t",
      heads = {
        { "n", ":TestNearest<CR>" },
        { "f", ":TestFile<CR>" },
        { "s", ":TestSuit<CR>" },
        { "l", ":TestLast<CR>" },
        { "g", ":TestVisit<CR>" },
        { "w", startAutoCommand },
        { "p", stopAutoCommand },
        { "<Esc>", nil, { exit = true } },
      },
    }
  end,
}