add TSamFile and TSamAll command with default keymaps

This commit is contained in:
2025-12-23 23:35:40 +01:00
parent 463d0ae2f7
commit 61f9a7dcb4
8 changed files with 281 additions and 41 deletions

View File

@@ -172,4 +172,38 @@ function runner.build_command(spec)
}
end
function runner.build_file_command(bufnr)
local path = util.get_buf_path(bufnr)
if not path or path == "" then
return nil
end
local root = util.find_root(path, { "go.mod", ".git" })
if not root or root == "" then
root = vim.loop.cwd()
end
local spec = { file = path, cwd = root }
local pkg = build_pkg_arg(spec)
local cmd = { "go", "test", "-v", pkg }
return {
cmd = cmd,
cwd = root,
}
end
function runner.build_all_command(bufnr)
local path = util.get_buf_path(bufnr)
local root
if path and path ~= "" then
root = util.find_root(path, { "go.mod", ".git" })
end
if not root or root == "" then
root = vim.loop.cwd()
end
local cmd = { "go", "test", "-v", "./..." }
return {
cmd = cmd,
cwd = root,
}
end
return runner

View File

@@ -4,4 +4,5 @@ return js.new({
name = "js-mocha",
framework = "mocha",
command = { "npx", "mocha" },
all_glob = "test/**/*.test.js",
})

View File

@@ -220,6 +220,7 @@ function M.new(opts)
runner.name = cfg.name or "js"
runner.framework = cfg.framework or "jest"
runner.command = cfg.command or { "npx", runner.framework }
runner.all_glob = cfg.all_glob
runner.filetypes = {}
if cfg.filetypes then
@@ -312,6 +313,62 @@ function M.new(opts)
}
end
function runner.build_file_command(bufnr)
local path = util.get_buf_path(bufnr)
if not path or path == "" then
return nil
end
local root
if runner.framework == "jest" then
root = find_jest_root(path)
else
root = util.find_root(path, {
"jest.config.js",
"jest.config.ts",
"vitest.config.ts",
"vitest.config.js",
"package.json",
"node_modules",
})
end
local cmd = vim.deepcopy(runner.command)
table.insert(cmd, path)
return {
cmd = cmd,
cwd = root,
}
end
function runner.build_all_command(bufnr)
local path = util.get_buf_path(bufnr)
local root
if path and path ~= "" then
if runner.framework == "jest" then
root = find_jest_root(path)
else
root = util.find_root(path, {
"jest.config.js",
"jest.config.ts",
"vitest.config.ts",
"vitest.config.js",
"package.json",
"node_modules",
})
end
end
if not root or root == "" then
root = vim.loop.cwd()
end
local cmd = vim.deepcopy(runner.command)
if runner.framework == "mocha" and runner.all_glob then
table.insert(cmd, runner.all_glob)
end
return {
cmd = cmd,
cwd = root,
}
end
return runner
end