From 3e65ff5a13afdae8783456a0407d6fe33eca670d Mon Sep 17 00:00:00 2001 From: V13Axel Date: Mon, 19 Feb 2024 09:38:50 -0500 Subject: [PATCH] Update readme to include new config options --- README.md | 93 ++++++++++++++++++++++++++++--------- lua/neotest-pest/config.lua | 5 +- lua/neotest-pest/init.lua | 4 +- 3 files changed, 74 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index cd653d4..e0df067 100644 --- a/README.md +++ b/README.md @@ -3,45 +3,91 @@ This plugin provides a [Pest](https://pestphp.com) adapter for the [Neotest](https://github.com/nvim-neotest/neotest) framework. This is a fork of `neotest-pest` originally by [@theutz](https://github.com/theutz/neotest-pest), with some fixes and updates: + - Updated to work with [Pest](https://pestphp.com) 2.0 - Support for (and automatic detection of) Laravel Sail - Note: This also moves junit output files into `storage/app/` +- Parallel testing support :warning: _Ive only focused on making this work for me. Please test against your Pest tests_ :warning: ## :package: Installation -Install the plugin using packer: +Install the plugin using your favorite package manager. + +Here's an example using lazy.nvim: ```lua -use({ - 'nvim-neotest/neotest', - requires = { - ..., - 'V13Axel/neotest-pest', - }, - config = function() - require('neotest').setup({ - ..., - adapters = { - require('neotest-pest'), - } - }) - end -}) +{ + 'nvim-neotest/neotest', + dependencies = { + ..., + 'V13Axel/neotest-pest', + }, + config = function() + require('neotest').setup({ + ..., + adapters = { + require('neotest-pest'), + } + }) + end +} ``` ## :wrench: Configuration -The plugin may be configured as below: +> [!TIP] +> Any of these options can be set to a lua function that returns the desired result. For example, wanna run tests in parallel, one for each CPU core? +> `parallel = function() #vim.loop.cpu_info() end` ```lua adapters = { - require('neotest-pest')({ - pest_cmd = function() - return "vendor/bin/pest" - end - }), + require('neotest-pest')({ + -- Ignore these directories when looking for tests + -- -- Default: { "vendor", "node_modules" } + ignore_dirs = { "vendor", "node_modules" } + + -- Ignore any projects containing "phpunit-only.tests" + -- -- Default: {} + root_ignore_files = { "phpunit-only.tests" }, + + -- Specify suffixes for files that should be considered tests + -- -- Default: { "Test.php" } + test_file_suffixes = { "Test.php", "_test.php", "PestTest.php" }, + + -- Sail not properly detected? Explicitly enable it. + -- -- Default: function() that checks for sail presence + sail_enabled = false, + + -- Custom sail executable. Not running in Sail, but running bare Docker? + -- Set `sail_enabled` = true and `sail_executable` to { "docker", "exec", "[somecontainer]" } + -- -- Default: "vendor/bin/sail" + sail_executable = "vendor/bin/sail", + + -- Custom pest binary. + -- -- Default: function that checks for sail presence + pest_cmd = "vendor/bin/pest", + + -- Run N tests in parallel, <=1 doesn't pass --parallel to pest at all + -- -- Default: 0 + parallel = 16 + + -- Enable ["compact" output printer](https://pestphp.com/docs/optimizing-tests#content-compact-printer) + -- -- Default: false + compact = false, + + -- Set a custom path for the results XML file, parsed by this adapter + -- + ------------------------------------------------------------------------------------ + -- NOTE: This must be a path accessible by both your test runner AND your editor! -- + ------------------------------------------------------------------------------------ + -- + -- -- Default: function that checks for sail presence. + -- -- - If no sail: Numbered file in randomized /tmp/ directory (using async.fn.tempname()) + -- -- - If sail: "storage/app/" .. os.date("junit-%Y%m%d-%H%M%S") + results_path = function() "/some/accessible/path" end, + }), } ``` @@ -62,6 +108,7 @@ vim.keymap.set('n', 'tn', function() require('neotest').run.run() end) To test a file run `lua require('neotest').run.run(vim.fn.expand('%'))` Example - t(est)f(ile): + ```lua vim.keymap.set('n', 'tf', function() require('neotest').run.run(vim.fn.expand('%')) end) ``` @@ -76,7 +123,7 @@ To test the full test suite run `lua require('neotest').run.run({ suite = true } ## :gift: Contributing -This fork is maintained by one guy, in my spare time and when I can get to it. Please raise a PR if you are interested in adding new functionality or fixing any bugs. When submitting a bug, please include an example test that I can test against. +I'm just one guy, maintaining this in my spare time and when I can get to it. Please raise a PR if you are interested in adding new functionality or fixing any bugs. When submitting a bug, please include an example test that I can test against. To trigger the tests for the adapter, run: diff --git a/lua/neotest-pest/config.lua b/lua/neotest-pest/config.lua index caa9d78..9e33d2e 100644 --- a/lua/neotest-pest/config.lua +++ b/lua/neotest-pest/config.lua @@ -12,10 +12,9 @@ local M = { env = { root_ignore_files = {}, root_files = { "tests/Pest.php" }, - filter_dirs = { "vendor" }, - test_file_suffix = { "Test.php" }, + ignore_dirs = { "vendor", "node_modules" }, + test_file_suffixes = { "Test.php" }, sail_executable = "vendor/bin/sail", - pest_cmd = "vendor/bin/pest", parallel = 0, compact = false, }, diff --git a/lua/neotest-pest/init.lua b/lua/neotest-pest/init.lua index ad323be..1aac6d7 100644 --- a/lua/neotest-pest/init.lua +++ b/lua/neotest-pest/init.lua @@ -67,7 +67,7 @@ end ---@param root string Root directory of project ---@return boolean True when matching function NeotestAdapter.filter_dir(name, rel_path, root) - for _, filter_dir in ipairs(config("filter_dirs")) do + for _, filter_dir in ipairs(config("ignore_dirs")) do if name == filter_dir then return false end end @@ -78,7 +78,7 @@ end ---@param file_path string ---@return boolean function NeotestAdapter.is_test_file(file_path) - for _, suffix in ipairs(config("test_file_suffix")) do + for _, suffix in ipairs(config("test_file_suffixes")) do if vim.endswith(file_path, suffix) then return true end end