Skip to content

Commit

Permalink
fix(json-output): convert error object to string before encoding (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
svermeulen authored Sep 19, 2023
1 parent 0c5dcb1 commit e5e6691
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion busted/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ return function()
end

info.traceback = debug.traceback('', level)
info.message = msg
info.message = tostring(msg)

local file = busted.getFile(element)
return file and file.getTrace(file.name, info) or trimTrace(info)
Expand Down
12 changes: 10 additions & 2 deletions busted/outputHandlers/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ return function(options)
local handler = require 'busted.outputHandlers.base'()

handler.suiteEnd = function()
io_write(json.encode({
local error_info = {
pendings = handler.pendings,
successes = handler.successes,
failures = handler.failures,
errors = handler.errors,
duration = handler.getDuration()
}))
}
local ok, result = pcall(json.encode, error_info)

if ok then
io_write(result)
else
io_write("Failed to encode test results to json: " .. result)
end

io_write("\n")
io_flush()

Expand Down

0 comments on commit e5e6691

Please sign in to comment.