fix TSamFailedOnly and the output formatting for the mocha-runner
This commit is contained in:
@@ -273,6 +273,67 @@ describe("test-samurai output formatting", function()
|
||||
assert.is_false(has_raw_json)
|
||||
end)
|
||||
|
||||
it("formats mocha json-stream array output as PASS/FAIL lines", function()
|
||||
test_samurai.setup({
|
||||
runner_modules = {
|
||||
"test-samurai.runners.js-mocha",
|
||||
},
|
||||
})
|
||||
|
||||
local pass_line = vim.json.encode({
|
||||
"pass",
|
||||
{
|
||||
title = "GET: /",
|
||||
fullTitle = "API :: /brands... GET: /",
|
||||
},
|
||||
})
|
||||
|
||||
local orig_jobstart = vim.fn.jobstart
|
||||
vim.fn.jobstart = function(_cmd, opts)
|
||||
if opts and opts.on_stdout then
|
||||
opts.on_stdout(1, { pass_line }, nil)
|
||||
end
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit(1, 0, nil)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/output_mocha_json_stream.test.js")
|
||||
vim.bo[bufnr].filetype = "javascript"
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {
|
||||
'describe("outer", function() {',
|
||||
' it("inner 1", function() {',
|
||||
" -- inside 1",
|
||||
" })",
|
||||
"})",
|
||||
})
|
||||
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
|
||||
core.run_nearest()
|
||||
|
||||
local out_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(out_buf, 0, -1, false)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
|
||||
local has_pass = false
|
||||
local has_raw_json = false
|
||||
for _, line in ipairs(lines) do
|
||||
if line == "[ PASS ] - API :: /brands... GET: /" then
|
||||
has_pass = true
|
||||
elseif line == pass_line then
|
||||
has_raw_json = true
|
||||
end
|
||||
end
|
||||
|
||||
assert.is_true(has_pass)
|
||||
assert.is_false(has_raw_json)
|
||||
end)
|
||||
|
||||
it("does not print raw JSON when JSON arrives on stdout and stderr", function()
|
||||
test_samurai.setup({
|
||||
runner_modules = {
|
||||
@@ -426,15 +487,19 @@ describe("test-samurai output formatting", function()
|
||||
assert.is_true(#job_calls >= 2)
|
||||
local failed_cmd = job_calls[2].cmd or {}
|
||||
local saw_grep = false
|
||||
local saw_fgrep = false
|
||||
local saw_title = false
|
||||
for _, arg in ipairs(failed_cmd) do
|
||||
if arg == "--grep" then
|
||||
saw_grep = true
|
||||
elseif arg == "--fgrep" then
|
||||
saw_fgrep = true
|
||||
elseif arg == "outer inner 2" then
|
||||
saw_title = true
|
||||
end
|
||||
end
|
||||
assert.is_true(saw_grep)
|
||||
assert.is_false(saw_grep)
|
||||
assert.is_true(saw_fgrep)
|
||||
assert.is_true(saw_title)
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user