diff options
Diffstat (limited to 'tests/middleware_spec.lua')
| -rw-r--r-- | tests/middleware_spec.lua | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/tests/middleware_spec.lua b/tests/middleware_spec.lua index 5c629ee6..9128d962 100644 --- a/tests/middleware_spec.lua +++ b/tests/middleware_spec.lua @@ -1,39 +1,72 @@ local util = require "lspconfig.util" +local a = require "nvim-lsp-installer.core.async" local servers = require "nvim-lsp-installer.servers" local middleware = require "nvim-lsp-installer.middleware" describe("middleware", function() - it("should register on_setup hook with lspconfig", function() + local server + before_each(function() -- 1. setup dummy server local default_options = { cmd = { "dummy-lsp" }, cmd_env = { PATH = "/keep/my/path/out/your/f/mouth" }, } - local server = ServerGenerator { - name = "dummy", + server = ServerGenerator { default_options = default_options, } servers.register(server) -- 2. register hook middleware.register_lspconfig_hook() + end) - -- 3. call lspconfig hook - local config = { - name = "dummy", - cmd = { "should", "be", "overwritten" }, - custom = "setting", - cmd_env = { SOME_DEFAULT_ENV = "important" }, - } - util.on_setup(config) - assert.are.same({ - cmd = { "dummy-lsp" }, - name = "dummy", - custom = "setting", - cmd_env = { - PATH = "/keep/my/path/out/your/f/mouth", - SOME_DEFAULT_ENV = "important", - }, - }, config) + after_each(function() + -- reset hook + util.on_setup = nil end) + + it( + "should apply config changes to installed servers", + async_test(function() + server:install() + assert.wait_for(function() + assert.is_true(server:is_installed()) + end) + local config = { + name = "dummy", + cmd = { "should", "be", "overwritten" }, + custom = "setting", + cmd_env = { SOME_DEFAULT_ENV = "important" }, + } + util.on_setup(config) + assert.are.same({ + cmd = { "dummy-lsp" }, + name = "dummy", + custom = "setting", + cmd_env = { + PATH = "/keep/my/path/out/your/f/mouth", + SOME_DEFAULT_ENV = "important", + }, + }, config) + end) + ) + + it( + "should not apply config changes to uninstalled servers", + async_test(function() + local config = { + name = "uninstalled_dummy", + cmd = { "should", "not", "be", "overwritten" }, + custom = "setting", + cmd_env = { SOME_DEFAULT_ENV = "important" }, + } + util.on_setup(config) + assert.are.same({ + name = "uninstalled_dummy", + cmd = { "should", "not", "be", "overwritten" }, + custom = "setting", + cmd_env = { SOME_DEFAULT_ENV = "important" }, + }, config) + end) + ) end) |
