Skip to content

Commit f462d38

Browse files
committed
refactor(e2e): exercise public behavior
1 parent c58b8f8 commit f462d38

12 files changed

Lines changed: 419 additions & 596 deletions

‎tests/e2e/astrocore_spec.lua‎

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -659,48 +659,48 @@ T["AUTOCMD-05 creates local parent directories and skips URI write targets"] = f
659659
child = helpers.start_ready_child()
660660

661661
local path = helpers.fixture_project(child) .. "/autocmd-create-dir/fallback/file.txt"
662+
local uri = "https://example.invalid/uri-write-target/file.txt"
662663
child.lua(([=[
663664
local path = %s
664-
local mkdir = vim.fn.mkdir
665-
_G.astronvim_test_mkdir_calls = {}
666-
vim.fn.mkdir = function(...)
667-
table.insert(_G.astronvim_test_mkdir_calls, { ... })
668-
return mkdir(...)
669-
end
665+
local uri = %s
670666
671667
vim.cmd "enew!"
672668
vim.api.nvim_buf_set_name(0, path)
673669
vim.api.nvim_buf_set_lines(0, 0, -1, false, { "created by autocmd" })
674670
vim.cmd.write()
675671
676672
vim.cmd "enew!"
677-
vim.api.nvim_buf_set_name(0, "https://example.invalid/uri-write-target/file.txt")
673+
vim.api.nvim_buf_set_name(0, uri)
678674
vim.api.nvim_exec_autocmds("BufWritePre", astronvim_test_autocmd_options(0))
679-
vim.fn.mkdir = mkdir
680-
]=]):format(vim.inspect(path)))
675+
]=]):format(vim.inspect(path), vim.inspect(uri)))
681676

682677
local state = child.lua_get(([=[
683-
{
684-
calls = _G.astronvim_test_mkdir_calls,
685-
directory_exists = vim.fn.isdirectory(%s) == 1,
686-
file_exists = vim.fn.filereadable(%s) == 1,
687-
contents = vim.fn.readfile(%s),
688-
}
689-
]=]):format(vim.inspect(vim.fs.dirname(path)), vim.inspect(path), vim.inspect(path)))
690-
assert.equals(1, #state.calls)
678+
(function()
679+
local uri_path = vim.fs.abspath(%s)
680+
local uri_directory = vim.fs.dirname(uri_path)
681+
return {
682+
directory_exists = vim.fn.isdirectory(%s) == 1,
683+
file_exists = vim.fn.filereadable(%s) == 1,
684+
contents = vim.fn.readfile(%s),
685+
uri_directory_exists = vim.fn.isdirectory(uri_directory) == 1,
686+
uri_file_exists = vim.fn.filereadable(uri_path) == 1,
687+
}
688+
end)()
689+
]=]):format(vim.inspect(uri), vim.inspect(vim.fs.dirname(path)), vim.inspect(path), vim.inspect(path)))
691690
assert.is_true(state.directory_exists)
692691
assert.is_true(state.file_exists)
693692
assert.same({ "created by autocmd" }, state.contents)
693+
assert.is_false(state.uri_directory_exists)
694+
assert.is_false(state.uri_file_exists)
694695
end
695696

696-
T["AUTOCMD-10 keeps unrelated buffers unchanged and manages q-close mappings"] = function()
697+
T["AUTOCMD-10 keeps unrelated buffers unchanged and closes or preserves q windows"] = function()
697698
child = helpers.start_ready_child()
698699

699700
child.lua 'vim.cmd "help help"'
700-
local help_mapping = child.lua_get "vim.fn.maparg('q', 'n', false, true)"
701-
assert.equals("<Cmd>close<CR>", help_mapping.rhs)
701+
helpers.wait_until(child, "vim.bo.buftype == 'help'", "help buffer")
702702
child.type_keys "q"
703-
helpers.wait_until(child, "#vim.api.nvim_list_wins() == 1", "help close mapping")
703+
helpers.wait_until(child, "#vim.api.nvim_list_wins() == 1 and vim.bo.buftype ~= 'help'", "help q close")
704704

705705
child.lua [[
706706
local target = vim.api.nvim_get_current_buf()
@@ -726,23 +726,26 @@ T["AUTOCMD-10 keeps unrelated buffers unchanged and manages q-close mappings"] =
726726
727727
local nofile = vim.api.nvim_create_buf(false, true)
728728
vim.bo[nofile].buftype = "nofile"
729-
vim.keymap.set("n", "q", "<Cmd>let g:astronvim_test_q_preserved = true<CR>", { buf = nofile })
729+
vim.keymap.set("n", "q", function() vim.g.astronvim_test_q_preserved = true end, { buf = nofile })
730730
vim.api.nvim_win_set_buf(0, nofile)
731731
vim.api.nvim_exec_autocmds("BufWinEnter", astronvim_test_autocmd_options(nofile))
732-
_G.astronvim_test_nofile = {
733-
bufnr = nofile,
734-
mapping = vim.fn.maparg("q", "n", false, true),
735-
}
736-
vim.api.nvim_buf_delete(nofile, { force = true })
732+
_G.astronvim_test_nofile = nofile
733+
vim.g.astronvim_test_q_preserved = false
734+
]]
737735

736+
child.type_keys "q"
737+
helpers.wait_until(child, "vim.g.astronvim_test_q_preserved == true", "preserve nofile q mapping")
738+
assert.equals(2, child.lua_get "#vim.api.nvim_list_wins()")
739+
740+
child.lua [[
741+
vim.api.nvim_buf_delete(_G.astronvim_test_nofile, { force = true })
738742
vim.fn.setqflist { { filename = "plain.txt", lnum = 1, text = "quickfix entry" } }
739743
vim.cmd.copen()
740744
vim.api.nvim_exec_autocmds("BufWinEnter", astronvim_test_autocmd_options(vim.api.nvim_get_current_buf()))
741-
_G.astronvim_test_quickfix = {
742-
bufnr = vim.api.nvim_get_current_buf(),
743-
mapping = vim.fn.maparg("q", "n", false, true),
744-
}
745745
]]
746+
assert.is_false(child.lua_get "vim.bo.buflisted")
747+
child.type_keys "q"
748+
helpers.wait_until(child, "vim.bo.buftype ~= 'quickfix'", "quickfix q close")
746749

747750
local state = child.lua_get [[(function()
748751
local large = _G.astronvim_test_large_buffer
@@ -760,18 +763,15 @@ T["AUTOCMD-10 keeps unrelated buffers unchanged and manages q-close mappings"] =
760763
autoformat = vim.b[large.target].autoformat,
761764
completion = vim.b[large.target].completion,
762765
},
763-
nofile = _G.astronvim_test_nofile,
764-
nofile_cache_cleared = vim.g.q_close_windows[_G.astronvim_test_nofile.bufnr] == nil,
765-
quickfix = _G.astronvim_test_quickfix,
766+
nofile_preserved = vim.g.astronvim_test_q_preserved == true,
767+
quickfix_closed = vim.bo.buftype ~= "quickfix",
766768
}
767769
end)()]]
768770

769771
assert.same({ list = false, autoformat = false, completion = false }, state.target)
770772
assert.same({ list = true, autoformat = true, completion = true }, state.large.untouched)
771-
assert.equals("<Cmd>let g:astronvim_test_q_preserved = true<CR>", state.nofile.mapping.rhs)
772-
assert.is_true(state.nofile_cache_cleared)
773-
assert.equals("<Cmd>close<CR>", state.quickfix.mapping.rhs)
774-
assert.equals("Close window", state.quickfix.mapping.desc)
773+
assert.is_true(state.nofile_preserved)
774+
assert.is_true(state.quickfix_closed)
775775
end
776776

777777
return T

0 commit comments

Comments
 (0)