Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests

on:
pull_request:
push:
branches: [main]

jobs:
test:
name: Run Tests
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
neovim-version: ["stable", "nightly"]

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Install Neovim
uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.neovim-version }}

- name: Setup test environment
run: |
mkdir -p deps
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim
git clone --depth 1 https://github.com/akinsho/toggleterm.nvim deps/toggleterm.nvim

- name: Run tests
timeout-minutes: 10
run: |
nvim --version
nvim --headless -u tests/minimal_init.lua -c "luafile tests/run.lua"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ luac.out
*.x86_64
*.hex

# Test dependencies
deps/

20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: test prepare

prepare:
@echo "Preparing test environment..."
@mkdir -p deps
@if [ ! -d "deps/plenary.nvim" ]; then \
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim; \
fi
@if [ ! -d "deps/toggleterm.nvim" ]; then \
git clone --depth 1 https://github.com/akinsho/toggleterm.nvim deps/toggleterm.nvim; \
fi
@echo "Test environment ready!"

test: prepare
@echo "Running tests..."
nvim --headless -u tests/minimal_init.lua -c "luafile tests/run.lua"

clean:
@echo "Cleaning test dependencies..."
@rm -rf deps
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
![License](https://img.shields.io/badge/License-MIT-brightgreen?style=flat-square)
![Status](https://img.shields.io/badge/Status-Stable-informational?style=flat-square)
![Neovim](https://img.shields.io/badge/Neovim-0.9+-green.svg?style=flat-square&logo=Neovim&logoColor=white)
[![Tests](https://github.com/mgierada/lazydocker.nvim/workflows/Tests/badge.svg)](https://github.com/mgierada/lazydocker.nvim/actions/workflows/test.yml)
[![Default keymaps](https://img.shields.io/badge/Default%20keymaps-Documentation-blue.svg)](https://github.com/jesseduffield/lazydocker/blob/master/docs/keybindings/Keybindings_en.md)

</div>
Expand Down Expand Up @@ -165,6 +166,36 @@ require("lazydocker").setup({
```

**Note**: If you don't specify `width` or `height`, the plugin will use the default values (0.9), ensuring backward compatibility.
## 🧪 Development

### Running Tests

This project includes a comprehensive test suite using [plenary.nvim](https://github.com/nvim-lua/plenary.nvim).

To run tests locally:

```bash
make test
```

This will:
1. Clone `plenary.nvim` into `deps/` directory
2. Run all tests using Neovim in headless mode

To clean test dependencies:

```bash
make clean
```

### CI/CD

The project uses GitHub Actions to automatically run tests on:
- Every push to `main` branch
- OS platforms (Ubuntu, macOS)
- Neovim versions (stable, nightly)

See `.github/workflows/test.yml` for the full CI configuration.

## Star History

Expand Down
9 changes: 9 additions & 0 deletions tests/lazydocker/actions/open_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local open = require("lazydocker.actions.open")

describe("actions.open", function()
describe("run", function()
it("should be a function", function()
assert.is_function(open.run)
end)
end)
end)
72 changes: 72 additions & 0 deletions tests/lazydocker/config_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
local config = require("lazydocker.config")

describe("config", function()
describe("__DEFAULT_OPTIONS", function()
it("should have default options", function()
assert.is_table(config.__DEFAULT_OPTIONS)
end)

it("should have border option with default value", function()
assert.equals("double", config.__DEFAULT_OPTIONS.border)
end)
end)

describe("options", function()
it("should be initialized with default options", function()
assert.is_table(config.options)
assert.equals("double", config.options.border)
end)
end)

describe("__register_namespace", function()
it("should be a function", function()
assert.is_function(config.__register_namespace)
end)
end)

describe("__register_user_options", function()
it("should be a function", function()
assert.is_function(config.__register_user_options)
end)

it("should merge user options with defaults", function()
local user_options = { border = "single" }
config.__register_user_options(user_options)
assert.equals("single", config.options.border)
end)

it("should use defaults when user options are nil", function()
config.__register_user_options(nil)
assert.equals("double", config.options.border)
end)

it("should keep default values for missing user options", function()
config.__register_user_options({})
assert.equals("double", config.options.border)
end)
end)

describe("__prepare_augroup", function()
it("should be a function", function()
assert.is_function(config.__prepare_augroup)
end)
end)

describe("__register_commands", function()
it("should be a function", function()
assert.is_function(config.__register_commands)
end)
end)

describe("setup", function()
it("should be a function", function()
assert.is_function(config.setup)
end)

it("should setup config with user options", function()
local user_options = { border = "curved" }
config.setup(user_options)
assert.equals("curved", config.options.border)
end)
end)
end)
27 changes: 27 additions & 0 deletions tests/lazydocker/init_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local lazydocker = require("lazydocker")

describe("init", function()
describe("setup", function()
it("should be a function", function()
assert.is_function(lazydocker.setup)
end)

it("should setup without errors", function()
assert.has_no.errors(function()
lazydocker.setup()
end)
end)

it("should accept options", function()
assert.has_no.errors(function()
lazydocker.setup({ border = "single" })
end)
end)
end)

describe("open", function()
it("should be a function", function()
assert.is_function(lazydocker.open)
end)
end)
end)
19 changes: 19 additions & 0 deletions tests/lazydocker/state_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local state = require("lazydocker.state")

describe("state", function()
describe("namespace", function()
it("should exist", function()
assert.is_table(state.namespace)
end)

it("should have create function", function()
assert.is_function(state.namespace.create)
end)

it("should create namespace with valid id", function()
state.namespace.create()
assert.is_not_nil(state.namespace.id)
assert.is_number(state.namespace.id)
end)
end)
end)
15 changes: 15 additions & 0 deletions tests/lazydocker/utils/constants_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local constants = require("lazydocker.utils.constants")

describe("constants", function()
it("should have COMMANDS table", function()
assert.is_table(constants.COMMANDS)
end)

it("should have open command", function()
assert.equals("Lazydocker", constants.COMMANDS.open)
end)

it("should have AUTOGROUP constant", function()
assert.equals("LazydockerAutogroup", constants.AUTOGROUP)
end)
end)
27 changes: 27 additions & 0 deletions tests/lazydocker/utils/logger_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local logger = require("lazydocker.utils.logger")

describe("logger", function()
describe("__print", function()
it("should be a function", function()
assert.is_function(logger.__print)
end)
end)

describe("error", function()
it("should be a function", function()
assert.is_function(logger.error)
end)
end)

describe("warn", function()
it("should be a function", function()
assert.is_function(logger.warn)
end)
end)

describe("info", function()
it("should be a function", function()
assert.is_function(logger.info)
end)
end)
end)
15 changes: 15 additions & 0 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Minimal init file for running tests
-- This ensures the plugin can be loaded in test environment

-- Add the plugin directory to the runtime path
vim.cmd([[set runtimepath+=.]])

-- Add plenary to runtime path (will be cloned in CI)
vim.cmd([[set runtimepath+=deps/plenary.nvim]])

-- Add toggleterm to runtime path (will be cloned in CI)
vim.cmd([[set runtimepath+=deps/toggleterm.nvim]])

-- Disable swapfile and backup for tests
vim.opt.swapfile = false
vim.opt.backup = false
7 changes: 7 additions & 0 deletions tests/run.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Test runner script for plenary.nvim

-- Run tests - plenary handles exit codes internally via vim.cmd "0cq"/"1cq"
require("plenary.test_harness").test_directory("tests", {
minimal_init = "tests/minimal_init.lua",
sequential = true,
})