74 lines
2.0 KiB
Lua
74 lines
2.0 KiB
Lua
local test_samurai = require("test-samurai")
|
|
local core = require("test-samurai.core")
|
|
local util = require("test-samurai.util")
|
|
|
|
local orig_find_root = util.find_root
|
|
local orig_fs_stat = vim.loop.fs_stat
|
|
local orig_readfile = vim.fn.readfile
|
|
|
|
describe("test-samurai core", function()
|
|
before_each(function()
|
|
test_samurai.setup()
|
|
util.find_root = orig_find_root
|
|
vim.loop.fs_stat = orig_fs_stat
|
|
vim.fn.readfile = orig_readfile
|
|
end)
|
|
|
|
it("selects Go runner for _test.go files", function()
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/foo_test.go")
|
|
local runner = core.get_runner_for_buf(bufnr)
|
|
assert.is_not_nil(runner)
|
|
assert.equals("go", runner.name)
|
|
end)
|
|
|
|
it("selects JS jest runner for *.test.ts files", function()
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/foo.test.ts")
|
|
vim.bo[bufnr].filetype = "typescript"
|
|
|
|
local runner = core.get_runner_for_buf(bufnr)
|
|
assert.is_not_nil(runner)
|
|
assert.equals("js-jest", runner.name)
|
|
end)
|
|
|
|
it("prefers mocha runner when mocha is in package.json", function()
|
|
util.find_root = function(_, _)
|
|
return "/tmp/mocha_proj"
|
|
end
|
|
|
|
vim.loop.fs_stat = function(path)
|
|
if path == "/tmp/mocha_proj/package.json" then
|
|
return { type = "file" }
|
|
end
|
|
return nil
|
|
end
|
|
|
|
vim.fn.readfile = function(path)
|
|
if path == "/tmp/mocha_proj/package.json" then
|
|
return {
|
|
"{",
|
|
' "devDependencies": { "mocha": "^10.0.0" }',
|
|
"}",
|
|
}
|
|
end
|
|
return {}
|
|
end
|
|
|
|
test_samurai.setup()
|
|
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/mocha_proj/foo.test.ts")
|
|
vim.bo[bufnr].filetype = "typescript"
|
|
|
|
local runner = core.get_runner_for_buf(bufnr)
|
|
|
|
util.find_root = orig_find_root
|
|
vim.loop.fs_stat = orig_fs_stat
|
|
vim.fn.readfile = orig_readfile
|
|
|
|
assert.is_not_nil(runner)
|
|
assert.equals("js-mocha", runner.name)
|
|
end)
|
|
end)
|