thenbe / neotest-playwright

A playwright adapter for neotest.
MIT License
39 stars 5 forks source link

NeotestPlaywrightPreset seems to have no effect #19

Closed piersolenski closed 9 months ago

piersolenski commented 9 months ago

When I run NeotestPlaywrightPreset and select "headed", it still uses my preset of preset = "debug".

My config:

return {
    "nvim-neotest/neotest",
    dependencies = {
        "nvim-lua/plenary.nvim",
        "antoinemadec/FixCursorHold.nvim",
        {
            "thenbe/neotest-playwright",
            keys = {
                {
                    "<leader>ta",
                    function()
                        require("neotest").playwright.attachment()
                    end,
                    desc = "Launch test attachment",
                },
                {
                    "<leader>tm",
                    ":NeotestPlaywrightPreset<cr>",
                    desc = "Debug mode",
                    silent = true,
                },
            },
        },
    },
    event = "VeryLazy",
    keys = {
        {
            "<leader>tr",
            function()
                require("neotest").run.run()
            end,
            desc = "Run test",
        },
        {
            "<leader>tR",
            function()
                require("neotest").run.run(vim.fn.expand("%"))
            end,
            desc = "Run tests in file",
        },
        {
            "<leader>ts",
            function()
                require("neotest").run.stop()
            end,
            desc = "Stop test",
        },
        {
            "<leader>tk",
            function()
                require("neotest").output.open({ enter = true })
            end,
            desc = "Open test output",
        },
        {
            "<leader>tt",
            function()
                require("neotest.consumers.summary").toggle()
            end,
            desc = "Toggle test tree",
        },
        {
            "<leader>to",
            function()
                require("neotest.consumers.output_panel").toggle()
            end,
            desc = "Toggle test output panel",
        },
        {
            "<leader>t.",
            ":NeotestPlaywrightRefresh<cr>",
            desc = "Refresh buffer",
        },
    },
    opts = function()
        return {
            adapters = {
                require("neotest-playwright").adapter({
                    options = {
                        preset = "debug",
                        persist_project_selection = true,
                        enable_dynamic_test_discovery = true,
                    },
                }),
            },
            consumers = {
                playwright = require("neotest-playwright.consumers").consumers,
            },
        }
    end,
}
thenbe commented 9 months ago

Are you by any chance using a wrapper around vim.ui.select (like dressing.nvim)? If so, does the issue persist if you disable that wrapper?

Also, what version of nvim are you on?

thenbe commented 9 months ago

Can you try the latest version? https://github.com/thenbe/neotest-playwright/commit/ea972015695704846ffaeffb364a898c6f2be847 may have fixed this.

piersolenski commented 9 months ago

Hmm If I switch from headed (as my default) to debug, it works, but then when switching back to headed it seems to keep using the debug mode 🤔

thenbe commented 9 months ago

Hmm If I switch from headed (as my default) to debug, it works, but then when switching back to headed it seems to keep using the debug mode 🤔

I can't reproduce this one. When you turn up the log level, is the preset name getting logged successfully every time you use NeotestPlaywrightPreset?

  opts = function()
    return {
+     log_level = vim.log.levels.DEBUG,
      adapters = {
        -- ...
      },
      consumers = {
        -- ...
      },
    }
  end,
tail -F ~/.local/state/nvim/neotest.log
DEBUG | 2023-12-02T21:37:31Z+0300 | ...ts/neotest-playwright/lua/neotest-playwright/logging.lua:7 | [neotest-playwright] preset headed
DEBUG | 2023-12-02T21:37:41Z+0300 | ...ts/neotest-playwright/lua/neotest-playwright/logging.lua:7 | [neotest-playwright] preset debug
DEBUG | 2023-12-02T21:37:45Z+0300 | ...ts/neotest-playwright/lua/neotest-playwright/logging.lua:7 | [neotest-playwright] preset headed
DEBUG | 2023-12-02T21:37:48Z+0300 | ...ts/neotest-playwright/lua/neotest-playwright/logging.lua:7 | [neotest-playwright] preset none
thenbe commented 9 months ago

The current preset value can also be printed like so:

:lua =require('neotest-playwright').adapter.options.preset
piersolenski commented 9 months ago

Hmm it seems to be working now, might have been my config at fault! Thanks so much for the fix!