plugins_load_spec.lua 2.2 KB

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