initialize with first MVP
This commit is contained in:
2
tests/minimal_init.lua
Normal file
2
tests/minimal_init.lua
Normal file
@@ -0,0 +1,2 @@
|
||||
vim.opt.runtimepath:append(vim.loop.cwd())
|
||||
require("plenary.busted")
|
||||
26
tests/test_samurai_core_spec.lua
Normal file
26
tests/test_samurai_core_spec.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
local test_samurai = require("test-samurai")
|
||||
local core = require("test-samurai.core")
|
||||
|
||||
describe("test-samurai core", function()
|
||||
before_each(function()
|
||||
test_samurai.setup()
|
||||
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)
|
||||
end)
|
||||
85
tests/test_samurai_go_spec.lua
Normal file
85
tests/test_samurai_go_spec.lua
Normal file
@@ -0,0 +1,85 @@
|
||||
local go_runner = require("test-samurai.runners.go")
|
||||
|
||||
describe("test-samurai go runner", function()
|
||||
it("detects Go test files by suffix", function()
|
||||
local bufnr1 = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr1, "/tmp/foo_test.go")
|
||||
assert.is_true(go_runner.is_test_file(bufnr1))
|
||||
|
||||
local bufnr2 = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr2, "/tmp/foo.go")
|
||||
assert.is_false(go_runner.is_test_file(bufnr2))
|
||||
end)
|
||||
|
||||
it("finds subtest when cursor is inside t.Run block", function()
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/foo_test.go")
|
||||
local lines = {
|
||||
"package main",
|
||||
"import \"testing\"",
|
||||
"",
|
||||
"func TestFoo(t *testing.T) {",
|
||||
" t.Run(\"first\", func(t *testing.T) {",
|
||||
" -- inside first",
|
||||
" })",
|
||||
"",
|
||||
" t.Run(\"second\", func(t *testing.T) {",
|
||||
" -- inside second",
|
||||
" })",
|
||||
"}",
|
||||
}
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
|
||||
local orig_fs_find = vim.fs.find
|
||||
vim.fs.find = function(markers, opts)
|
||||
return { "/tmp/go.mod" }
|
||||
end
|
||||
|
||||
local row_inside_first = 5
|
||||
local spec, err = go_runner.find_nearest(bufnr, row_inside_first, 0)
|
||||
|
||||
vim.fs.find = orig_fs_find
|
||||
|
||||
assert.is_nil(err)
|
||||
assert.is_not_nil(spec)
|
||||
assert.equals("TestFoo/first", spec.test_path)
|
||||
assert.equals("subtest", spec.scope)
|
||||
assert.equals("/tmp/foo_test.go", spec.file)
|
||||
assert.equals("/tmp", spec.cwd)
|
||||
end)
|
||||
|
||||
it("falls back to whole test function when between subtests", function()
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/foo_test.go")
|
||||
local lines = {
|
||||
"package main",
|
||||
"import \"testing\"",
|
||||
"",
|
||||
"func TestFoo(t *testing.T) {",
|
||||
" t.Run(\"first\", func(t *testing.T) {",
|
||||
" -- inside first",
|
||||
" })",
|
||||
"",
|
||||
" t.Run(\"second\", func(t *testing.T) {",
|
||||
" -- inside second",
|
||||
" })",
|
||||
"}",
|
||||
}
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
|
||||
local orig_fs_find = vim.fs.find
|
||||
vim.fs.find = function(markers, opts)
|
||||
return { "/tmp/go.mod" }
|
||||
end
|
||||
|
||||
local row_between = 7
|
||||
local spec, err = go_runner.find_nearest(bufnr, row_between, 0)
|
||||
|
||||
vim.fs.find = orig_fs_find
|
||||
|
||||
assert.is_nil(err)
|
||||
assert.is_not_nil(spec)
|
||||
assert.equals("TestFoo", spec.test_path)
|
||||
assert.equals("function", spec.scope)
|
||||
end)
|
||||
end)
|
||||
53
tests/test_samurai_js_spec.lua
Normal file
53
tests/test_samurai_js_spec.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
local jest = require("test-samurai.runners.js-jest")
|
||||
|
||||
describe("test-samurai js runner (jest)", function()
|
||||
it("detects JS/TS test files by name and filetype", function()
|
||||
local bufnr1 = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr1, "/tmp/foo.test.ts")
|
||||
vim.bo[bufnr1].filetype = "typescript"
|
||||
assert.is_true(jest.is_test_file(bufnr1))
|
||||
|
||||
local bufnr2 = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr2, "/tmp/foo.ts")
|
||||
vim.bo[bufnr2].filetype = "typescript"
|
||||
assert.is_false(jest.is_test_file(bufnr2))
|
||||
end)
|
||||
|
||||
it("finds nearest it() call as test name", 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 lines = {
|
||||
"describe(\"outer\", function() {",
|
||||
" it(\"inner 1\", function() {",
|
||||
" -- inside 1",
|
||||
" })",
|
||||
"",
|
||||
" it(\"inner 2\", function() {",
|
||||
" -- inside 2",
|
||||
" })",
|
||||
"})",
|
||||
}
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
|
||||
local orig_fs_find = vim.fs.find
|
||||
vim.fs.find = function(markers, opts)
|
||||
return { "/tmp/package.json" }
|
||||
end
|
||||
|
||||
local row_inside_second = 6
|
||||
local spec, err = jest.find_nearest(bufnr, row_inside_second, 0)
|
||||
|
||||
vim.fs.find = orig_fs_find
|
||||
|
||||
assert.is_nil(err)
|
||||
assert.is_not_nil(spec)
|
||||
assert.equals("inner 2", spec.test_name)
|
||||
assert.equals("jest", spec.framework)
|
||||
assert.equals("/tmp/foo.test.ts", spec.file)
|
||||
assert.equals("/tmp", spec.cwd)
|
||||
|
||||
local cmd_spec = jest.build_command(spec)
|
||||
assert.are.same({ "npx", "jest", "/tmp/foo.test.ts", "-t", "inner 2" }, cmd_spec.cmd)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user