A Neovim plugin for running and debugging tests (jest only) in Nx monorepos.
The difference of using it instead other test plugins for neovim is that you can take advantage of the NX cache and graph dependencies.
- Run tests for all projects
- Run tests for a specific project
- Run tests for the current file
- Run or debug a single test
- Run tests for affected projects
- Watch mode support
- Integrated debugging with Node.js inspector
- Configurable terminal position
- Neovim >= 0.5.0
- plenary.nvim
- An Nx monorepo using
pnpm - Node.js
Using lazy.nvim:
{
"andtankian/nxtest.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
},
opts = {
terminal_position = "buffer" -- default
},
}The plugin can be configured with the following options:
require('nxtest').setup({
-- Where to open the terminal window
-- Possible values: "vertical", "horizontal", "buffer"
terminal_position = "buffer" -- default
})buffer: Opens in a new buffer (default)vertical: Opens in a vertical splithorizontal: Opens in a horizontal split
:NxTestAll- Run tests for all projects in the monorepo:NxTest- Run tests for the current project (determined by project.json):NxTestFile- Run tests for the current file in watch mode:NxTestSingle- Run the test under cursor in watch mode:NxTestDebugSingle- Debug the test under cursor with Node.js inspector:NxTestAffected- Run tests for projects affected by recent changes
All commands support additional arguments that will be passed directly to the nx command.
- Navigate to a test file in your Nx monorepo
- Use any of the commands above to run or debug tests
- Place your cursor on a test case (it or test block)
- Run
:NxTestSingleto run just that test - The test will run in watch mode
- The plugin will automatically detect the test context (describe block) if present
- Place your cursor on a test case
- Run
:NxTestDebugSingle - The test will start in debug mode with the
--inspect-waitflag - Connect your debugger (e.g., Chrome DevTools) to continue execution
- The Node.js inspector will be available at the default port
- Run
:NxTestAffected - The plugin will use Nx's affected command to determine which projects have been impacted by recent changes
- Tests will run only for the affected projects
The plugin expects:
- A valid Nx monorepo structure
project.jsonfiles in project roots with a validnamefield- pnpm as the package manager
- Jest as the test runner
lua/
nxtest/
init.lua -- Main entry point
commands.lua -- Command definitions
config.lua -- Configuration handling
terminal.lua -- Terminal management
test_runner.lua -- Test execution logic
utils/
init.lua -- Utility functions
project.lua -- Project-related utilities
Contributions are welcome! Please feel free to submit a Pull Request.
MIT