Problem: spawned compiler processes and watching autocmds were never cleaned up when Neovim exited, leaving orphaned processes running. Solution: register a VimLeavePre autocmd in commands setup that calls compiler.stop_all(), which kills active processes, unwatches all buffers, and stops the reload server.
58 lines
1.5 KiB
Lua
58 lines
1.5 KiB
Lua
local helpers = require('spec.helpers')
|
|
|
|
describe('commands', function()
|
|
before_each(function()
|
|
helpers.reset_config()
|
|
end)
|
|
|
|
describe('setup', function()
|
|
it('creates the :Preview command', function()
|
|
require('preview.commands').setup()
|
|
local cmds = vim.api.nvim_get_commands({})
|
|
assert.is_not_nil(cmds.Preview)
|
|
end)
|
|
|
|
it('registers VimLeavePre autocmd', function()
|
|
require('preview.commands').setup()
|
|
local aus = vim.api.nvim_get_autocmds({ event = 'VimLeavePre' })
|
|
local found = false
|
|
for _, au in ipairs(aus) do
|
|
if au.callback then
|
|
found = true
|
|
break
|
|
end
|
|
end
|
|
assert.is_true(found)
|
|
end)
|
|
end)
|
|
|
|
describe('dispatch', function()
|
|
it('does not error on :Preview compile with no provider', function()
|
|
require('preview.commands').setup()
|
|
assert.has_no.errors(function()
|
|
vim.cmd('Preview compile')
|
|
end)
|
|
end)
|
|
|
|
it('does not error on :Preview status', function()
|
|
require('preview.commands').setup()
|
|
assert.has_no.errors(function()
|
|
vim.cmd('Preview status')
|
|
end)
|
|
end)
|
|
|
|
it('does not error on :Preview open', function()
|
|
require('preview.commands').setup()
|
|
assert.has_no.errors(function()
|
|
vim.cmd('Preview open')
|
|
end)
|
|
end)
|
|
|
|
it('does not error on :Preview toggle with no provider', function()
|
|
require('preview.commands').setup()
|
|
assert.has_no.errors(function()
|
|
vim.cmd('Preview toggle')
|
|
end)
|
|
end)
|
|
end)
|
|
end)
|