finish first MVP with test-runner-detection for Go, Mocha.js, Jest.js and ViTest.js
This commit is contained in:
@@ -67,9 +67,38 @@ local function find_t_runs(lines, func)
|
||||
return subtests
|
||||
end
|
||||
|
||||
local function escape_pattern(str)
|
||||
local escaped = str:gsub("(%W)", "%%%1")
|
||||
return "^" .. escaped .. "$"
|
||||
local function build_run_pattern(spec)
|
||||
local name = spec.test_path or ""
|
||||
local escaped = name:gsub("(%W)", "%%%1")
|
||||
if spec.scope == "function" then
|
||||
return "^" .. escaped .. "$|^" .. escaped .. "/"
|
||||
else
|
||||
return "^" .. escaped .. "$"
|
||||
end
|
||||
end
|
||||
|
||||
local function build_pkg_arg(spec)
|
||||
local file = spec.file
|
||||
local cwd = spec.cwd
|
||||
if not file or not cwd or file == "" or cwd == "" then
|
||||
return "./..."
|
||||
end
|
||||
|
||||
local dir = vim.fs.dirname(file)
|
||||
if dir == cwd then
|
||||
return "./"
|
||||
end
|
||||
|
||||
if file:sub(1, #cwd) ~= cwd then
|
||||
return "./..."
|
||||
end
|
||||
|
||||
local rel = dir:sub(#cwd + 2)
|
||||
if not rel or rel == "" then
|
||||
return "./"
|
||||
end
|
||||
|
||||
return "./" .. rel
|
||||
end
|
||||
|
||||
function runner.is_test_file(bufnr)
|
||||
@@ -134,8 +163,9 @@ function runner.find_nearest(bufnr, row, _col)
|
||||
end
|
||||
|
||||
function runner.build_command(spec)
|
||||
local pattern = escape_pattern(spec.test_path)
|
||||
local cmd = { "go", "test", "./...", "-run", pattern }
|
||||
local pattern = build_run_pattern(spec)
|
||||
local pkg = build_pkg_arg(spec)
|
||||
local cmd = { "go", "test", "-v", pkg, "-run", pattern }
|
||||
return {
|
||||
cmd = cmd,
|
||||
cwd = spec.cwd,
|
||||
|
||||
Reference in New Issue
Block a user