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

@@ -1,5 +1,6 @@
local jest = require("test-samurai.runners.js-jest")
local mocha = require("test-samurai.runners.js-mocha")
local util = require("test-samurai.util")
describe("test-samurai js runner (jest)", function()
it("detects JS/TS test files by name and filetype", function()
@@ -36,8 +37,7 @@ describe("test-samurai js runner (jest)", function()
return { "/tmp/package.json" }
end
-- Cursor in der zweiten it()-Body
local row_inside_second = 6 -- 0-basiert -> Zeile mit "-- inside 2"
local row_inside_second = 6
local spec, err = jest.find_nearest(bufnr, row_inside_second, 0)
vim.fs.find = orig_fs_find
@@ -76,8 +76,7 @@ describe("test-samurai js runner (jest)", function()
return { "/tmp/package.json" }
end
-- Cursor auf der Leerzeile zwischen den beiden it()-Blöcken
local row_between = 4 -- 0-basiert -> leere Zeile zwischen den Tests
local row_between = 4
local spec, err = jest.find_nearest(bufnr, row_between, 0)
vim.fs.find = orig_fs_find
@@ -139,4 +138,25 @@ describe("test-samurai js runner (mocha)", function()
)
assert.equals("/tmp/project", cmd_spec.cwd)
end)
it("builds mocha all command with default glob", function()
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, "/tmp/project/test/foo_all.test.js")
vim.bo[bufnr].filetype = "javascript"
local orig_find_root = util.find_root
util.find_root = function(path, markers)
return "/tmp/project"
end
local cmd_spec = mocha.build_all_command(bufnr)
util.find_root = orig_find_root
assert.are.same(
{ "npx", "mocha", "test/**/*.test.js" },
cmd_spec.cmd
)
assert.equals("/tmp/project", cmd_spec.cwd)
end)
end)

View File

@@ -1,7 +1,7 @@
local test_samurai = require("test-samurai")
local core = require("test-samurai.core")
describe("test-samurai output API", function()
describe("test-samurai public API", function()
it("delegates show_output to core", function()
local called = false
local orig = core.show_output
@@ -16,4 +16,49 @@ describe("test-samurai output API", function()
assert.is_true(called)
end)
it("delegates test_nearest to core.run_nearest", function()
local called = false
local orig = core.run_nearest
core.run_nearest = function()
called = true
end
test_samurai.test_nearest()
core.run_nearest = orig
assert.is_true(called)
end)
it("delegates test_file to core.run_file", function()
local called = false
local orig = core.run_file
core.run_file = function()
called = true
end
test_samurai.test_file()
core.run_file = orig
assert.is_true(called)
end)
it("delegates test_all to core.run_all", function()
local called = false
local orig = core.run_all
core.run_all = function()
called = true
end
test_samurai.test_all()
core.run_all = orig
assert.is_true(called)
end)
end)