diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..47b609b --- /dev/null +++ b/.github/workflows/test.yml @@ -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" diff --git a/.gitignore b/.gitignore index 6fd0a37..217f020 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ luac.out *.x86_64 *.hex +# Test dependencies +deps/ + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2a1e753 --- /dev/null +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index d229424..af97947 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/tests/lazydocker/actions/open_spec.lua b/tests/lazydocker/actions/open_spec.lua new file mode 100644 index 0000000..dfa7f18 --- /dev/null +++ b/tests/lazydocker/actions/open_spec.lua @@ -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) diff --git a/tests/lazydocker/config_spec.lua b/tests/lazydocker/config_spec.lua new file mode 100644 index 0000000..e457258 --- /dev/null +++ b/tests/lazydocker/config_spec.lua @@ -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) diff --git a/tests/lazydocker/init_spec.lua b/tests/lazydocker/init_spec.lua new file mode 100644 index 0000000..ad107ad --- /dev/null +++ b/tests/lazydocker/init_spec.lua @@ -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) diff --git a/tests/lazydocker/state_spec.lua b/tests/lazydocker/state_spec.lua new file mode 100644 index 0000000..f423e3f --- /dev/null +++ b/tests/lazydocker/state_spec.lua @@ -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) diff --git a/tests/lazydocker/utils/constants_spec.lua b/tests/lazydocker/utils/constants_spec.lua new file mode 100644 index 0000000..a3240ee --- /dev/null +++ b/tests/lazydocker/utils/constants_spec.lua @@ -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) diff --git a/tests/lazydocker/utils/logger_spec.lua b/tests/lazydocker/utils/logger_spec.lua new file mode 100644 index 0000000..3623286 --- /dev/null +++ b/tests/lazydocker/utils/logger_spec.lua @@ -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) diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua new file mode 100644 index 0000000..1f3734e --- /dev/null +++ b/tests/minimal_init.lua @@ -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 diff --git a/tests/run.lua b/tests/run.lua new file mode 100644 index 0000000..94afec5 --- /dev/null +++ b/tests/run.lua @@ -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, +})