lazytest

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 17 Imported by: 0

README

LazyTest 🥱🧪
LazyTest is a command line tool that helps you view, search and run tests in your project.

the lazytest tui

Features ⭐

Run a test

Run a test suite

Run all tests

Run failed tests

Run passed tests

Search for a test

Resize the panes

Sometimes test names may exceed the size of the pane. Or you may need more space for the output text. Unfortunately, tview, the TUI library that LazyTest uses, does not support horizontal scrolling (and it's probably not going to be implemented any time soon).

As an alternative, LazyTest panes can be resized with the + and - keys.

Installation ⬇️

Go

You can use Go to install LazyTest

go install github.com/kampanosg/lazytest@latest

Brew

[!WARNING] Brew is not yet available, I am working on it.

Build from source

[!IMPORTANT] You need Go v1.22 to build the project.

Makefile

You can build the project with make

make

An executable called lazytest will be built. You can move it to your $PATH

Bakery

If you're a Bakery fan (well, thank you!), LazyTest comes with a Bakefile that you can use with bake. You can just run

bake

An executable called lazytest will be built. You can move it to your $PATH

Engines 🏎️

"Engines" are a core concept in LazyTest. It allows the tool to be extensible and work with many languages and test frameworks. LazyTest uses engines to parse the codebase and determine which files contain tests. Engines also provide instructions on how to run a given test.

You can write a new Engine by implementing the following interface:

type LazyEngine interface {
	Load(dir string) (*models.LazyTree, error)
	GetIcon() string
}

The Load function parses the contents of dir and constructs a LazyTree which includes all the tests. The tree is then passed to the TUI that renders it on the terminal

https://github.com/kampanosg/lazytest/blob/c0ce2bfdbc501a91c26662c20bbe154c907dd500/pkg/engines/golang/engine.go#L37-L71

Available Engines

LazyTests comes packed with the following engines:

Usage ⚙️

LazyTest aims to be as intuitive and easy to use as possible. If you're familiar with other terminal applications, LazyTest should (hopefully) feel natural. The table below lists all the available keys and modes.

Key Description Where
? Opens the help dialog
j/k Navigate up/down Tests Panel
↑/↓ Navigate up down Tests Panel
Enter/Space Fold/Unfold a node Tests Panel
1 Focus on the Tests Panel
2 Focus on the Output Panel
3 Focus on the History Panel
4 Focus on the Timings Panel
r Run a Test or Test Suite Tests Panel
a Run all Tests Tests Panel
p Run Passed Tests (from previous run) Tests Panel
f Run Failed Tests (from previous run) Tests Panel
/ Enter Search Mode Tests Panel
Esc Exit Search Mode Search Panel
Enter Go to Search Results Search Panel
C Clear Search Results Tests Panel
+ Increase the Tests Panel size
- Decrease the Tests Panel size
0 Reset the layout
y Copy the test name/test suite path Tests Panel
Y Copy the (current) output Tests Panel
q Quit the app

Use it with ToggleTerm

ToggleTerm is a popular NeoVim plugin that lets you "persist and toggle multiple terminals during an editing session". It can be used with LazyTest, to avoid context-switching when you have to run your tests.

You can add the following to your NeoVim config:

local Terminal  = require('toggleterm.terminal').Terminal

local lazytest = Terminal:new({
  cmd = "lazytest",
  dir = ".",
  direction = "float",
  float_opts = {
    border = "curved",
  },
  -- function to run on opening the terminal
  on_open = function(term)
    vim.cmd("startinsert!")
    vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "<cmd>close<CR>", {noremap = true, silent = true})
  end,
  -- function to run on closing the terminal
  on_close = function(term)
    vim.cmd("startinsert!")
  end,
})

function _lazytest_toggle()
  lazytest:toggle()
end

vim.api.nvim_set_keymap("n", "<C-t>", "<cmd>lua _lazytest_toggle()<CR>", {noremap = true, silent = true})

The above binds <C-t> to bring up a new floating terminal and executes the ./lazytest command. You can quit the terminal by pressing q. Make sure you include this config to your init.lua.

[!NOTE] You can view and example of my NeoVim x LazyTest configuration here

Flags

LazyTest supports the following flags that can be passed with the executable

Flag Description Example
dir the directory to start searching for tests lazytest -dir /Code/example/project
excl engines to exclude lazytest -excl=rust,zig
version the current version of LazyTest

Inspiration & Similar Projects 💬

LazyTest is heavily inspired by the following projects. Go check them out - their work is excellent!

  • LazyGit - A simple terminal UI for git commands
  • NeoTest - A framework for interacting with tests within NeoVim.

Mandatory GIF 🖼️


The average developer when being asked to write tests

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
tui
tui/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL