detect and use project jest.setup.{j,t}s files
All checks were successful
tests / test (push) Successful in 8s

This commit is contained in:
2026-01-08 12:42:44 +01:00
parent e4b4097999
commit a6c9da2f9a
3 changed files with 91 additions and 9 deletions

View File

@@ -279,6 +279,62 @@ describe("test-samurai-jest-runner", function()
end)
end)
it("adds jest.setup.js from project root to setupFilesAfterEnv", function()
with_project(JEST_PACKAGE, function(root)
write_file(root .. "/jest.setup.js", "console.log('setup')")
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, root .. "/foo.test.ts")
local cmd_spec = runner.build_file_command(bufnr)
assert.are.same(
{
"npx",
"jest",
"--testLocationInResults",
"--reporters",
get_reporter_path(),
"--setupFilesAfterEnv",
get_setup_path(),
"--setupFilesAfterEnv",
root .. "/jest.setup.js",
"--runTestsByPath",
root .. "/foo.test.ts",
},
cmd_spec.cmd
)
assert.equals(root, cmd_spec.cwd)
end)
end)
it("adds jest.setup.ts from test/.bin when root setup is missing", function()
with_project(JEST_PACKAGE, function(root)
write_file(root .. "/test/.bin/jest.setup.ts", "console.log('setup')")
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, root .. "/bar.test.ts")
local cmd_spec = runner.build_file_command(bufnr)
assert.are.same(
{
"npx",
"jest",
"--testLocationInResults",
"--reporters",
get_reporter_path(),
"--setupFilesAfterEnv",
get_setup_path(),
"--setupFilesAfterEnv",
root .. "/test/.bin/jest.setup.ts",
"--runTestsByPath",
root .. "/bar.test.ts",
},
cmd_spec.cmd
)
assert.equals(root, cmd_spec.cwd)
end)
end)
it("build_all_command runs project tests", function()
with_project(JEST_PACKAGE, function(root)
local bufnr = vim.api.nvim_create_buf(false, true)