remove built-in runner
This commit is contained in:
@@ -1,81 +1,35 @@
|
||||
local test_samurai = require("test-samurai")
|
||||
local core = require("test-samurai.core")
|
||||
local util = require("test-samurai.util")
|
||||
local config = require("test-samurai.config")
|
||||
|
||||
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()
|
||||
describe("test-samurai core (no bundled runners)", 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)
|
||||
it("defaults to an empty runner_modules list", function()
|
||||
local cfg = config.get()
|
||||
assert.is_true(type(cfg.runner_modules) == "table")
|
||||
assert.equals(0, #cfg.runner_modules)
|
||||
end)
|
||||
|
||||
it("does not fallback to Go runner when no runners are configured", function()
|
||||
test_samurai.setup({ runner_modules = {} })
|
||||
it("warns when no runner is installed for a test file", function()
|
||||
local notified = {}
|
||||
local orig_notify = vim.notify
|
||||
vim.notify = function(msg, level)
|
||||
table.insert(notified, { msg = msg, level = level })
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/no_runner_test.go")
|
||||
local runner = core.get_runner_for_buf(bufnr)
|
||||
assert.is_nil(runner)
|
||||
end)
|
||||
vim.bo[bufnr].filetype = "go"
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
|
||||
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"
|
||||
core.run_nearest()
|
||||
|
||||
local runner = core.get_runner_for_buf(bufnr)
|
||||
assert.is_not_nil(runner)
|
||||
assert.equals("js-jest", runner.name)
|
||||
end)
|
||||
vim.notify = orig_notify
|
||||
|
||||
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)
|
||||
assert.equals(1, #notified)
|
||||
assert.equals("[test-samurai] no runner installed for this kind of test", notified[1].msg)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user