thenbe / neotest-playwright

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

Unable to run tests without 'firefox' and 'webkit' projects defined in playwright config #29

Closed catgoose closed 4 months ago

catgoose commented 4 months ago

Using Neovim 0.10.

If I use a playwright config without firefox or webkit, running tests complains about those projects not being found.

I select 'chromium' using NeotestPlaywrightProject then try to run playwright tests:

image

My lazy.nvim config:

return {
  "nvim-neotest/neotest",
  dependencies = {
    "nvim-neotest/nvim-nio",
    "nvim-lua/plenary.nvim",
    "antoinemadec/FixCursorHold.nvim",
    "nvim-treesitter/nvim-treesitter",
    "marilari88/neotest-vitest",
    "thenbe/neotest-playwright",
  },
  config = function()
    require("neotest").setup({
      adapters = {
        require("neotest-vitest")({
          filter_dir = function(name)
            return name ~= "node_modules" and name ~= "e2e"
          end,
        }),
        require("neotest-playwright").adapter({
          options = {
            persist_project_selection = true,
            enable_dynamic_test_discovery = true,
            is_test_file = function(file_path)
              return string.match(file_path, "e2e/tests")
            end,
          },
        }),
      },
      consumers = {
        playwright = require("neotest-playwright.consumers").consumers,
      },
    })
  end,
  cmd = {
    "Neotest",
    "NeotestPlaywrightProject",
    "NeotestPlaywrightPreset",
    "NeotestPlaywrightRefresh",
  },
  keys = {
    m("<leader>m", "Neotest summary"),
    m("<leader>n", "Neotest run file"),
  },
}

playwright config:

...
  projects: [
    {
      name: 'setup',
      testMatch: msalEnabled ? /.*\.setup\.ts/ : undefined,
    },
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        storageState: 'e2e/.auth/user.json',
      },
      dependencies,
    },
  ],
catgoose commented 4 months ago

I see this is because of https://github.com/thenbe/neotest-playwright/issues/20

Would it be possible to add a config option with project name as key to define the playwright projects since vim.ui.select wrappers don't allow selecting properly?

thenbe commented 4 months ago

Harcoding the project names would get messy when using this plugin on multiple projects. Instead, I've added an experimental telescope picker in #31 that attempts to solve this.

catgoose commented 4 months ago

The issue here occurs if:

  1. select multiple projects using NeotestPlaywrightProject
  2. remove projects from playwright.config.ts

Since they were removed from playwright.config.ts, they are unavailable for deselection. I guess they are still "active" in whatever state file neotest-playwright uses to save the projects.

You have to add the projects back to the config then deselect them again. Then it is safe to remove them using NeotestPlaywrightProject

thenbe commented 4 months ago

Ah yes.

p.s. You can run this command to see where the file is stored. Then you can delete it if you encounter lingering phantom projects.

:lua =vim.fn.stdpath('data') .. '/neotest-playwright.json'`
thenbe commented 4 months ago

See e35465a43729dbf9f790c56c9c6e3402ba27a2c0 for how to quickly recover from phantom project issue.