Skip to content

Commit 4b3f93c

Browse files
committed
refactor: minor code cleanup
- Remove a duplicate function - Consistent variable naming (from camelCase to snake_case)
1 parent 8ba0729 commit 4b3f93c

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed

lua/neotest-stenciljs/init.lua

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,23 @@ local function get_cwd(file_path)
284284
end
285285

286286
local function parsed_json_to_results(data, output_file, consoleOut)
287+
local function parsed_json_to_results(data, output_file, console_out)
287288
local tests = {}
288289

289-
for _, testResult in pairs(data.testResults) do
290-
local testFn = testResult.name
290+
for _, test_result in pairs(data.testResults) do
291+
local test_file = test_result.name
291292

292-
for _, assertionResult in pairs(testResult.assertionResults) do
293-
local status, name = assertionResult.status, assertionResult.title
293+
for _, assertion_result in pairs(test_result.assertionResults) do
294+
local status, name = assertion_result.status, assertion_result.title
294295

295296
if name == nil then
296-
logger.error("Failed to find parsed test result ", assertionResult)
297+
logger.error("Failed to find parsed test result ", assertion_result)
297298
return {}
298299
end
299300

300-
local keyid = testFn
301+
local keyid = test_file
301302

302-
for _, value in ipairs(assertionResult.ancestorTitles) do
303+
for _, value in ipairs(assertion_result.ancestorTitles) do
303304
if value ~= "" then
304305
keyid = keyid .. "::" .. value
305306
end
@@ -314,19 +315,19 @@ local function parsed_json_to_results(data, output_file, consoleOut)
314315
tests[keyid] = {
315316
status = status,
316317
short = name .. ": " .. status,
317-
output = consoleOut,
318-
location = assertionResult.location,
318+
output = console_out,
319+
location = assertion_result.location,
319320
}
320321

321-
if not vim.tbl_isempty(assertionResult.failureMessages) then
322+
if not vim.tbl_isempty(assertion_result.failureMessages) then
322323
local errors = {}
323324

324-
for i, failMessage in ipairs(assertionResult.failureMessages) do
325-
local msg = clean_ansi(failMessage)
325+
for i, fail_message in ipairs(assertion_result.failureMessages) do
326+
local msg = clean_ansi(fail_message)
326327

327328
errors[i] = {
328-
line = (assertionResult.location and assertionResult.location.line - 1 or nil),
329-
column = (assertionResult.location and assertionResult.location.column or nil),
329+
line = (assertion_result.location and assertion_result.location.line - 1 or nil),
330+
column = (assertion_result.location and assertion_result.location.column or nil),
330331
message = msg,
331332
}
332333

@@ -425,28 +426,6 @@ end
425426
function adapter.results(spec, b, tree)
426427
spec.context.stop_stream()
427428

428-
local output_file = spec.context.results_path
429-
local success, data = pcall(lib.files.read, output_file)
430-
431-
if not success then
432-
logger.error("No test output file found ", output_file)
433-
return {}
434-
end
435-
436-
local ok, parsed = pcall(vim.json.decode, data, { luanil = { object = true } })
437-
if not ok then
438-
logger.error("Failed to parse test output json ", output_file)
439-
return {}
440-
end
441-
442-
local results = parsed_json_to_results(parsed, output_file, b.output)
443-
return results
444-
end
445-
446-
---@async
447-
---@param spec neotest.RunSpec
448-
---@return neotest.Result[]
449-
function adapter.results(spec, b, tree)
450429
local output_file = spec.context.results_path
451430

452431
local success, data = pcall(lib.files.read, output_file)

0 commit comments

Comments
 (0)