From 720016d4fa525770d13e0933b05c919a5939622c Mon Sep 17 00:00:00 2001 From: William Boman Date: Wed, 13 Jul 2022 03:34:33 +0200 Subject: fix(api): fix the :MasonUninstall command (#66) --- tests/helpers/lua/dummy2_package.lua | 14 +++++++ tests/mason/api/command_spec.lua | 77 ++++++++++++++++++++++++++++++++++++ tests/minimal_init.vim | 1 + 3 files changed, 92 insertions(+) create mode 100644 tests/helpers/lua/dummy2_package.lua create mode 100644 tests/mason/api/command_spec.lua (limited to 'tests') diff --git a/tests/helpers/lua/dummy2_package.lua b/tests/helpers/lua/dummy2_package.lua new file mode 100644 index 00000000..424e47d7 --- /dev/null +++ b/tests/helpers/lua/dummy2_package.lua @@ -0,0 +1,14 @@ +local Pkg = require "mason-core.package" + +return Pkg.new { + name = "dummy2", + desc = [[This is a dummy2 package.]], + categories = { Pkg.Cat.LSP }, + languages = { Pkg.Lang.Dummy2Lang }, + homepage = "https://example.com", + ---@async + ---@param ctx InstallContext + install = function(ctx) + ctx.receipt:with_primary_source { type = "dummy2" } + end, +} diff --git a/tests/mason/api/command_spec.lua b/tests/mason/api/command_spec.lua new file mode 100644 index 00000000..06b2e5db --- /dev/null +++ b/tests/mason/api/command_spec.lua @@ -0,0 +1,77 @@ +local spy = require "luassert.spy" +local match = require "luassert.match" +local log = require "mason-core.log" + +local a = require "mason-core.async" +local api = require "mason.api.command" +local registry = require "mason-registry" +local Pkg = require "mason-core.package" + +describe(":Mason", function() + it( + "should open the UI window", + async_test(function() + api.Mason() + a.scheduler() + local win = vim.api.nvim_get_current_win() + local buf = vim.api.nvim_win_get_buf(win) + assert.equals("mason.nvim", vim.api.nvim_buf_get_option(buf, "filetype")) + end) + ) +end) + +describe(":MasonInstall", function() + it( + "should install the provided packages", + async_test(function() + local dummy = registry.get_package "dummy" + local dummy2 = registry.get_package "dummy2" + spy.on(Pkg, "install") + api.MasonInstall { fargs = { "dummy@1.0.0", "dummy2" } } + assert.spy(Pkg.install).was_called(2) + assert.spy(Pkg.install).was_called_with(match.is_ref(dummy), { version = "1.0.0" }) + assert + .spy(Pkg.install) + .was_called_with(match.is_ref(dummy2), match.tbl_containing { version = match.is_nil() }) + end) + ) + + it( + "should open the UI window", + async_test(function() + local dummy = registry.get_package "dummy" + spy.on(dummy, "install") + api.MasonInstall { fargs = { "dummy" } } + local win = vim.api.nvim_get_current_win() + local buf = vim.api.nvim_win_get_buf(win) + assert.equals("mason.nvim", vim.api.nvim_buf_get_option(buf, "filetype")) + end) + ) +end) + +describe(":MasonUninstall", function() + it( + "should uninstall the provided packages", + async_test(function() + local dummy = registry.get_package "dummy" + local dummy2 = registry.get_package "dummy" + spy.on(Pkg, "uninstall") + api.MasonUninstall { fargs = { "dummy", "dummy2" } } + assert.spy(Pkg.uninstall).was_called(2) + assert.spy(Pkg.uninstall).was_called_with(match.is_ref(dummy)) + assert.spy(Pkg.uninstall).was_called_with(match.is_ref(dummy2)) + end) + ) +end) + +describe(":MasonLog", function() + it("should open the log file", function() + api.MasonLog() + assert.equals(2, #vim.api.nvim_list_tabpages()) + local win = vim.api.nvim_get_current_win() + local buf = vim.api.nvim_win_get_buf(win) + vim.api.nvim_buf_call(buf, function() + assert.equals(log.outfile, vim.fn.expand "%") + end) + end) +end) diff --git a/tests/minimal_init.vim b/tests/minimal_init.vim index 86ed2ba2..1a4bfb31 100644 --- a/tests/minimal_init.vim +++ b/tests/minimal_init.vim @@ -18,6 +18,7 @@ lua require("test_helpers") lua <