fix TSamFailedOnly and the output formatting for the mocha-runner
This commit is contained in:
@@ -221,6 +221,77 @@ describe("TSamFailedOnly", function()
|
||||
assert.is_false(has_raw)
|
||||
end)
|
||||
|
||||
it("reruns failed mocha tests from json-stream array output without raw JSON", function()
|
||||
test_samurai.setup({
|
||||
runner_modules = {
|
||||
"test-samurai.runners.js-mocha",
|
||||
},
|
||||
})
|
||||
|
||||
local fail_line = vim.json.encode({
|
||||
event = "fail",
|
||||
fullTitle = "API :: /brands... GET: /",
|
||||
})
|
||||
local start_line = vim.json.encode({ "start", { total = 1 } })
|
||||
local end_line = vim.json.encode({ "end", { tests = 0 } })
|
||||
|
||||
local calls, orig_jobstart = stub_jobstart({
|
||||
exit_codes = { 1, 1 },
|
||||
stdout = { { fail_line }, { start_line, end_line } },
|
||||
})
|
||||
|
||||
local bufnr = mkbuf("/tmp/project/brands.test.js", "javascript", {
|
||||
'describe("API :: /brands...", function() {',
|
||||
' it("GET: /", function() {',
|
||||
" -- inside test",
|
||||
" })",
|
||||
"})",
|
||||
})
|
||||
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
|
||||
core.run_file()
|
||||
core.run_failed_only()
|
||||
|
||||
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
|
||||
|
||||
assert.equals(2, #calls)
|
||||
assert.are.same(
|
||||
{ "npx", "mocha", "--reporter", "json-stream", "/tmp/project/brands.test.js" },
|
||||
calls[1].cmd
|
||||
)
|
||||
local failed_cmd = calls[2].cmd or {}
|
||||
local saw_grep = false
|
||||
local saw_fgrep = false
|
||||
local saw_title = false
|
||||
local plain_title = "API :: /brands... GET: /"
|
||||
for _, arg in ipairs(failed_cmd) do
|
||||
if arg == "--grep" then
|
||||
saw_grep = true
|
||||
elseif arg == "--fgrep" then
|
||||
saw_fgrep = true
|
||||
elseif arg == plain_title then
|
||||
saw_title = true
|
||||
end
|
||||
end
|
||||
assert.is_false(saw_grep)
|
||||
assert.is_true(saw_fgrep)
|
||||
assert.is_true(saw_title)
|
||||
|
||||
local has_raw = false
|
||||
for _, line in ipairs(lines) do
|
||||
if line == start_line or line == end_line then
|
||||
has_raw = true
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_false(has_raw)
|
||||
end)
|
||||
|
||||
it("does not affect TSamLast history", function()
|
||||
local json = vim.json.encode({
|
||||
testResults = {
|
||||
|
||||
@@ -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