thenbe / neotest-playwright

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

Potential crash from not having env in get_config #11

Closed bjornsnoen closed 1 year ago

bjornsnoen commented 1 year ago

The env setting defined in adapter settings is not used when running the get_config function in playwright.ts. This means that if any env vars are required inside the detected playwright conf file, there's a potential for a crash. Minimal reproduction would be the following, using tiny-invariant in the project.

-- neotest.lua
local neotest = require('neotest')
neotest.setup({
    require('neotest-playwright').adapter({
        options = {
            persist_project_selection = true,
            enable_dynamic_test_discovery = true,
            cwd = function(_)
               return vim.fn.getcwd()
            end,
            env = {
                NEXT_PUBLIC_SITE_URL = 'http://somesite.localhost',
            },
        },
    })
})
// playwright.config.ts
import invariant from 'tiny-invariant'

invariant(process.env.NEXT_PUBLIC_SITE_URL != null, "Oop big error")

Try to run a test

thenbe commented 1 year ago

Thank you for the report. Can you confirm whether this is fixed for you in #12?

-   "thenbe/neotest-playwright",
+   {
+       "thenbe/neotest-playwright",
+       branch = "env-in-config",
+   },
bjornsnoen commented 1 year ago

Yep, that fixes it for me