2024-12-03 14:58:15 +00:00
|
|
|
local stdio = require("@lune/stdio")
|
|
|
|
|
|
|
|
local frktest = require("../../lune_packages/frktest")
|
|
|
|
local Reporter = frktest._reporters.lune_console_reporter
|
|
|
|
|
2024-12-04 05:49:01 +00:00
|
|
|
local watch = require("../lib/channel")
|
2024-12-03 15:35:24 +00:00
|
|
|
|
2024-12-03 14:58:15 +00:00
|
|
|
local STYLE = table.freeze({
|
2024-12-03 15:35:24 +00:00
|
|
|
suite = function(name: string)
|
|
|
|
return `{stdio.style("bold")}{stdio.color("purple")}SUITE{stdio.style("reset")} {name}`
|
|
|
|
end,
|
|
|
|
|
2024-12-04 06:05:54 +00:00
|
|
|
report = function(name: string, state: "success" | "error" | "skip", elapsed: number)
|
|
|
|
local state_color: stdio.Color = if state == "success" then "green"
|
2024-12-03 15:35:24 +00:00
|
|
|
elseif state == "error" then "red"
|
|
|
|
elseif state == "skip" then "yellow"
|
|
|
|
else error("Invalid test state")
|
|
|
|
return ` {stdio.style("bold")}{stdio.color(state_color)}{if state == "skip" then "SKIP" else "TEST"}{stdio.style(
|
|
|
|
"reset"
|
|
|
|
)} {name} [{stdio.style("dim")}{string.format("%.2fms", elapsed)}{stdio.style("reset")}]`
|
|
|
|
end,
|
2024-12-03 14:58:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
local ReporterExt = {}
|
|
|
|
function ReporterExt.init()
|
2024-12-03 15:35:24 +00:00
|
|
|
frktest.test.on_suite_enter(function(suite)
|
|
|
|
print(STYLE.suite(suite.name))
|
|
|
|
end)
|
|
|
|
|
|
|
|
frktest.test.on_suite_leave(function()
|
|
|
|
stdio.write("\n")
|
|
|
|
end)
|
|
|
|
|
|
|
|
local send_ts, recv_ts = watch((nil :: any) :: number)
|
|
|
|
|
|
|
|
frktest.test.on_test_enter(function()
|
|
|
|
-- Send over some high precision timestamp when the test starts
|
|
|
|
return send_ts(os.clock())
|
|
|
|
end)
|
|
|
|
|
|
|
|
frktest.test.on_test_leave(function(test)
|
|
|
|
print(
|
|
|
|
STYLE.report(
|
|
|
|
test.name,
|
|
|
|
if test.failed then "error" else "success",
|
|
|
|
|
|
|
|
-- Await receival of the timestamp and convert the difference to ms
|
2024-12-04 06:27:20 +00:00
|
|
|
(os.clock() - recv_ts()) * 1000
|
2024-12-03 15:35:24 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
frktest.test.on_test_skipped(function(test)
|
2024-12-04 06:27:20 +00:00
|
|
|
print(STYLE.report(test.name, "skip", 0))
|
2024-12-03 15:35:24 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
Reporter.init()
|
2024-12-03 14:58:15 +00:00
|
|
|
end
|
|
|
|
|
2024-12-03 15:35:24 +00:00
|
|
|
return setmetatable(ReporterExt, { __index = Reporter })
|