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 = {
|
||||
|
||||
Reference in New Issue
Block a user