AstroNvim中如何安装配置neotest-jest?
在AstroNvim中配置neotest-jest的步骤
1. 安装neotest-jest插件
在AstroNvim用户配置目录(通常是~/.config/nvim/lua/user/)下,创建或修改plugins/neotest.lua文件,通过lazy.nvim完成插件安装与基础配置:
return { "nvim-neotest/neotest", dependencies = { "haydenmeade/neotest-jest", }, opts = function(_, opts) -- 在原有neotest配置基础上添加jest适配器 table.insert(opts.adapters, require("neotest-jest")({ jestCommand = "npx jest", -- 可根据项目包管理工具调整,比如yarn项目改成"yarn test" jestConfigFile = "jest.config.js", -- 指定jest配置文件,默认会自动查找项目中的配置 env = { CI = true }, -- 可选,设置测试运行的环境变量 cwd = function(path) return vim.fn.getcwd() -- 可选,自定义jest运行的工作目录 end, })) end, }
2. 适配已有neotest配置
如果你的用户配置中已经存在neotest的自定义设置,只需确保将neotest-jest的配置项插入到opts.adapters数组中即可,无需覆盖原有配置。若之前未配置过neotest,上述代码会自动继承AstroNvim的默认neotest配置并添加jest适配器。
3. 验证配置有效性
打开任意Jest测试文件(如*.test.js、*.spec.ts),运行以下命令测试:
:Neotest run:执行当前文件所有测试:Neotest run nearest:执行光标所在的单个测试用例:Neotest summary:打开测试结果汇总窗口
若测试能正常执行并返回结果,说明配置成功。
内容的提问来源于stack exchange,提问作者Volodymyr Shevchuk
相关产品推荐
相关产品推荐

