plugins_load_spec.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. local a = require "plenary.async_lib.tests"
  2. a.describe("plugin-loader", function()
  3. local plugins = require "lvim.plugins"
  4. local loader = require "lvim.plugin-loader"
  5. a.it("should be able to load default packages without errors", function()
  6. loader.load { plugins, lvim.plugins }
  7. -- TODO: maybe there's a way to avoid hard-coding the names of the modules?
  8. local startup_plugins = {
  9. "packer",
  10. }
  11. for _, plugin in ipairs(startup_plugins) do
  12. assert.truthy(package.loaded[plugin])
  13. end
  14. end)
  15. a.it("should be able to load lsp packages without errors", function()
  16. loader.load { plugins, lvim.plugins }
  17. require("lvim.lsp").setup()
  18. local lsp_packages = {
  19. "lspconfig",
  20. "nlspsettings",
  21. "null-ls",
  22. }
  23. for _, plugin in ipairs(lsp_packages) do
  24. assert.truthy(package.loaded[plugin])
  25. end
  26. end)
  27. a.it("should be able to rollback plugins without errors", function()
  28. local plugin = { name = "onedarker.nvim" }
  29. plugin.path = vim.tbl_filter(function(package)
  30. return package:match(plugin.name)
  31. end, vim.api.nvim_list_runtime_paths())[1]
  32. local get_current_sha = function(repo)
  33. local res = vim.fn.system(string.format("git -C %s log -1 --pretty=%%h", repo)):gsub("\n", "")
  34. return res
  35. end
  36. plugin.test_sha = "316b1c9"
  37. _G.locked_sha = get_current_sha(plugin.path)
  38. loader.load { plugins, lvim.plugins }
  39. os.execute(string.format("git -C %s fetch --deepen 999 --quiet", plugin.path))
  40. os.execute(string.format("git -C %s checkout %s --quiet", plugin.path, plugin.test_sha))
  41. assert.equal(plugin.test_sha, get_current_sha(plugin.path))
  42. _G.completed = false
  43. _G.verify_sha = function()
  44. if _G.locked_sha ~= get_current_sha(plugin.path) then
  45. error "unmached results!"
  46. else
  47. _G.completed = true
  48. end
  49. end
  50. vim.cmd [[autocmd User PackerComplete lua _G.verify_sha()]]
  51. loader.sync_core_plugins()
  52. local ret = vim.wait(30 * 10 * 1000, function()
  53. return _G.completed == true
  54. end, 200)
  55. assert.True(ret)
  56. end)
  57. end)