Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testrunner):🎁 add duration to test runs #235

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/easy-dotnet/test-runner/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local function aggregate_status(node, options)
end

local function parse_status(result, test_line, options)
if result.duration then test_line.duration = result.duration end
--TODO: handle more cases like cancelled etc...
if result.outcome == "Passed" then
test_line.icon = options.icons.passed
Expand Down
27 changes: 25 additions & 2 deletions lua/easy-dotnet/test-runner/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,28 @@ local function calculate_highlight(node)
return nil
end

local function convert_time(timeStr)
local hours, minutes, seconds, microseconds = timeStr:match("(%d+):(%d+):(%d+)%.(%d+)")
hours = tonumber(hours)
minutes = tonumber(minutes)
seconds = tonumber(seconds)
microseconds = tonumber(microseconds)

local totalSeconds = hours * 3600 + minutes * 60 + seconds + microseconds / 1000000

if totalSeconds >= 3600 then
return string.format("%.1f h", totalSeconds / 3600)
elseif totalSeconds >= 60 then
return string.format("%.1f m", totalSeconds / 60)
elseif totalSeconds >= 1 then
return string.format("%.1f s", totalSeconds)
elseif totalSeconds > 0 then
return string.format("< 1 ms")
else
return "< 1 ms"
end
end

local function node_to_string(node)
local total_tests = 0
---@param i TestNode
Expand All @@ -165,12 +187,13 @@ local function node_to_string(node)
end)

local formatted = string.format(
"%s%s%s%s %s",
"%s%s%s%s %s %s",
string.rep(" ", node.indent or 0),
node.preIcon and (node.preIcon .. " ") or "",
node.name,
node.icon and node.icon ~= M.options.icons.passed and (" " .. node.icon) or "",
node.type ~= "subcase" and node.type ~= "test" and string.format("(%s)", total_tests) or ""
node.type ~= "subcase" and node.type ~= "test" and string.format("(%s)", total_tests) or "",
node.duration and convert_time(node.duration) or ""
)

return formatted
Expand Down
1 change: 1 addition & 0 deletions lua/easy-dotnet/test-runner/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local M = {}
---@field expanded boolean
---@field highlight string
---@field preIcon string
---@field duration string | nil
---@field icon string
---@field expand table | nil
---@field children table<string, TestNode>
Expand Down
3 changes: 2 additions & 1 deletion lua/easy-dotnet/test-runner/test-parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local logger = require("easy-dotnet.logger")
local M = {}

local file_template = [[
//v5
//v6
#r "nuget: Newtonsoft.Json"
open System
open System.IO
Expand All @@ -21,6 +21,7 @@ let transformTestCase (testCase: JObject) : JProperty =
let newTestCase = new JObject()
newTestCase.["outcome"] <- testCase.["@outcome"]
newTestCase.["id"] <- testCase.["@testId"]
newTestCase.["duration"] <- testCase.["@duration"]

let errorInfo = testCase.SelectToken("$.Output.ErrorInfo")
if errorInfo <> null && errorInfo.["StackTrace"] <> null then
Expand Down
Loading