Skip to content

Commit 1a4ce43

Browse files
committed
test: e2e testing
1 parent d85c8af commit 1a4ce43

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

.busted

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ return {
3838
ROOT = {'./test/integration/'},
3939
pattern = '', -- No fancy pattern for integration tests
4040
},
41+
e2e={
42+
ROOT={'./test/e2e/'},
43+
pattern='',
44+
}
4145
}
4246

4347
-- vim:ft=lua

makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ unit-test:
3333
integration-test:
3434
@./test/bin/busted --run integration
3535

36+
end-to-end-test:
37+
@./test/bin/nvim --headless -c "set loadplugins" -c "luafile ./scripts/e2e.lua"
38+
3639
test: unit-test integration-test
3740

3841
clean:

scripts/e2e.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
vim.cmd("edit .busted")
2+
vim.secure.trust({
3+
action = "allow",
4+
bufnr = 0,
5+
})
6+
7+
local neotest = require("neotest")
8+
local nb = require("lua.neotest-busted")
9+
10+
local function consumer(client)
11+
client.listeners.results = function(_, results, partial)
12+
if partial == false then
13+
local has_errors = false
14+
for _, result in pairs(results) do
15+
for _, e in ipairs(result.errors or {}) do
16+
has_errors = true
17+
io.stdout:write(e.message .. "\n\n")
18+
end
19+
end
20+
if has_errors then
21+
vim.cmd("cq!")
22+
end
23+
io.stdout:write("All e2e tests passed!\n\n")
24+
vim.cmd("qa!")
25+
end
26+
end
27+
end
28+
neotest.setup({ adapters = { nb }, consumers = { consumer } })
29+
neotest.run.run("./test/e2e/")

test/e2e/stdout.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- NOTE: tests tests should be run from within Neovim to make sure the plugin
2+
-- can handle text output from within a test. Ideally this should be run as an
3+
-- end-to-end test, but I cannot figure out how to write these because Neotest
4+
-- runs everything asynchronously.
5+
6+
local output_handler = require 'neotest-busted._output-handler'
7+
8+
describe('Test which write to standard output', function()
9+
10+
it('Has an explicit line break', function()
11+
print('Some text written to standard output\n')
12+
assert.is_true(true)
13+
end)
14+
15+
it('Has no explicit line break', function()
16+
print('Some text written to standard output')
17+
assert.is_true(true)
18+
end)
19+
20+
it('Contains the result marker from the output handler', function()
21+
print(string.format('%sThis could trip us up', output_handler.marker))
22+
assert.is_true(true)
23+
end)
24+
end)

0 commit comments

Comments
 (0)