initialize with first MVP
This commit is contained in:
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