mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-03 05:54:39 +02:00
tests: refactored tests a bit
This commit is contained in:
parent
1d42e45fd2
commit
4cc586a3f1
1 changed files with 45 additions and 23 deletions
|
@ -5,7 +5,6 @@ _G.LazyVim = require("lazyvim.util")
|
|||
|
||||
describe("Extra", function()
|
||||
local Config = require("lazy.core.config")
|
||||
local Loader = require("lazy.core.loader")
|
||||
assert(vim.tbl_count(Config.plugins) > 0, "Lazy not properly setup")
|
||||
|
||||
---@type {modname:string, modpath:string}[]
|
||||
|
@ -19,8 +18,13 @@ describe("Extra", function()
|
|||
return name:match("%.lua$")
|
||||
end, { limit = math.huge, type = "file", path = "lua/lazyvim/plugins/extras" })
|
||||
)
|
||||
|
||||
local ignore = { "lazyvim.plugins.extras.ui.treesitter-rewrite" }
|
||||
extras = vim.tbl_filter(function(extra)
|
||||
return not vim.tbl_contains(ignore, extra.modname)
|
||||
end, extras)
|
||||
|
||||
local lsp_to_pkg = require("mason-lspconfig.mappings.server").lspconfig_to_package
|
||||
local pkg_to_lsp = require("mason-lspconfig.mappings.server").package_to_lspconfig
|
||||
|
||||
local tsspec = Plugin.Spec.new({
|
||||
import = "lazyvim.plugins.treesitter",
|
||||
|
@ -32,27 +36,37 @@ describe("Extra", function()
|
|||
assert(type(tsensure) == "table", "No ensure_installed in nvim-treesitter spec")
|
||||
|
||||
for _, extra in ipairs(extras) do
|
||||
it(extra.modname .. " is valid", function()
|
||||
local mod = require(extra.modname)
|
||||
local spec = Plugin.Spec.new({
|
||||
local name = extra.modname:sub(#"lazyvim.plugins.extras" + 2)
|
||||
describe(name, function()
|
||||
---@type any, LazySpecLoader
|
||||
local mod, spec
|
||||
|
||||
it("spec is valid", function()
|
||||
mod = require(extra.modname)
|
||||
assert.is_not_nil(mod)
|
||||
spec = Plugin.Spec.new({
|
||||
{ "williamboman/mason.nvim", opts = { ensure_installed = {} } },
|
||||
{ "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } },
|
||||
mod,
|
||||
}, { optional = true })
|
||||
assert.is_not_nil(mod)
|
||||
assert(#spec.notifs == 0, "Invalid spec: " .. vim.inspect(spec.notifs))
|
||||
end)
|
||||
|
||||
if extra.modname:find("%.lang%.") then
|
||||
it("has recommended set", function()
|
||||
assert(mod.recommended, "`recommended` not set for " .. extra.modname)
|
||||
local lspconfig = spec.plugins["nvim-lspconfig"]
|
||||
end)
|
||||
end
|
||||
|
||||
local lspconfig = spec.plugins["nvim-lspconfig"]
|
||||
if lspconfig then
|
||||
it("does not install LSP servers with mason.nvim", function()
|
||||
local lspconfig_opts = Plugin.values(lspconfig, "opts", false)
|
||||
local mason = spec.plugins["mason.nvim"]
|
||||
local mason_opts = Plugin.values(mason, "opts", false)
|
||||
|
||||
for lsp in pairs(lspconfig_opts.servers or {}) do
|
||||
local lsp_pkg = pkg_to_lsp[lsp]
|
||||
local lsp_pkg = lsp_to_pkg[lsp]
|
||||
assert(
|
||||
not (lsp_pkg and vim.tbl_contains(mason_opts.ensure_installed, lsp_pkg)),
|
||||
"LSP server "
|
||||
|
@ -62,15 +76,23 @@ describe("Extra", function()
|
|||
.. " is installed automatically. Please remove from the mason.nvim spec"
|
||||
)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local ts = spec.plugins["nvim-treesitter"]
|
||||
local opts = Plugin.values(ts, "opts", false)
|
||||
for _, v in ipairs(opts.ensure_installed) do
|
||||
assert(
|
||||
not vim.tbl_contains(tsensure, v),
|
||||
"TS lang " .. v .. " is already a default. Please remove from the mason.nvim spec"
|
||||
|
||||
if not vim.tbl_isempty(opts.ensure_installed) then
|
||||
it("does not install defaut Treesitter langs", function()
|
||||
local invalid = vim.tbl_filter(function(v)
|
||||
return vim.tbl_contains(tsensure, v)
|
||||
end, opts.ensure_installed or {})
|
||||
assert.same(
|
||||
{},
|
||||
invalid,
|
||||
"These Treesitter langs are installed by default. Please remove them from the extra."
|
||||
)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue