finish first MVP with test-runner-detection for Go, Mocha.js, Jest.js and ViTest.js
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
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()
|
||||
@@ -23,4 +31,43 @@ describe("test-samurai core", function()
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user