diff --git a/lua/easy-dotnet/test-runner/keymaps.lua b/lua/easy-dotnet/test-runner/keymaps.lua index 8c81bf3..d823034 100644 --- a/lua/easy-dotnet/test-runner/keymaps.lua +++ b/lua/easy-dotnet/test-runner/keymaps.lua @@ -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 diff --git a/lua/easy-dotnet/test-runner/render.lua b/lua/easy-dotnet/test-runner/render.lua index 595f5f6..c8dbbc7 100644 --- a/lua/easy-dotnet/test-runner/render.lua +++ b/lua/easy-dotnet/test-runner/render.lua @@ -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 @@ -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 diff --git a/lua/easy-dotnet/test-runner/runner.lua b/lua/easy-dotnet/test-runner/runner.lua index d4987e7..4120db3 100644 --- a/lua/easy-dotnet/test-runner/runner.lua +++ b/lua/easy-dotnet/test-runner/runner.lua @@ -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 diff --git a/lua/easy-dotnet/test-runner/test-parser.lua b/lua/easy-dotnet/test-runner/test-parser.lua index 75b349d..9c9beee 100644 --- a/lua/easy-dotnet/test-runner/test-parser.lua +++ b/lua/easy-dotnet/test-runner/test-parser.lua @@ -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 @@ -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