diff --git a/README.md b/README.md index 94d0eef..40d6604 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ use({ -- end, -- env = { + -- PW_NVIM = "1", -- HELLO = "world", -- }, @@ -66,6 +67,36 @@ use({ }) ``` +## Configuration + +The only reporter required by `neotest-playwright` is the `json` reporter, which you need to set either in your `playwright.config.ts` or by using `extra_args`. Make sure _not_ to declare the json reporter's `outputFile` property in your config as this will be set by `neotest-playwright`. + +One way you can do this is by using environment variables. + +```lua +-- init.lua + +require("neotest-playwright").adapter({ + options = { + env = { + PW_NVIM = "1", + }, + }, +}) +``` + +```typescript +// playwright.config.ts + +const config: PlaywrightTestConfig = { + reporter: process.env.PW_NVIM + ? [['json'], ['list'], ['html', { open: 'never' }]] // only json is required. The rest are optional. + : [['list'], ['html', { open: 'never' }]], // Your default reporters. +}; +``` + +> Until `playwright` provides us a way to pass the `--reporters` flag without overwriting the `reporters` set in the user's config, we have to rely on the user handling this. + --- ## Projects diff --git a/lua/neotest-playwright/build-command.lua b/lua/neotest-playwright/build-command.lua index 059627a..ff480bb 100644 --- a/lua/neotest-playwright/build-command.lua +++ b/lua/neotest-playwright/build-command.lua @@ -15,13 +15,18 @@ local logger = require("neotest.logging") --- A function that takes in CommandOptions and returns a string. ____exports.buildCommand = function(options, extraArgs) local o = options - local reporters = o.reporters or ({"list", "json"}) - local reportersArg = buildReporters(reporters) + local ____o_reporters_0 + if o.reporters then + ____o_reporters_0 = buildReporters(o.reporters) + else + ____o_reporters_0 = nil + end + local reporters = ____o_reporters_0 local command = {} command[#command + 1] = o.bin command[#command + 1] = "test" - if reportersArg ~= nil then - command[#command + 1] = reportersArg + if reporters ~= nil then + command[#command + 1] = reporters end if o.debug == true then command[#command + 1] = "--debug" diff --git a/lua/neotest-playwright/playwright.lua b/lua/neotest-playwright/playwright.lua index b3f975e..04a8ef4 100644 --- a/lua/neotest-playwright/playwright.lua +++ b/lua/neotest-playwright/playwright.lua @@ -15,7 +15,6 @@ ____exports.get_projects = function() { bin = options.get_playwright_command(path), config = options.get_playwright_config(path), - reporters = {"json"}, testFilter = "./does-not-exist" }, {"--list"} diff --git a/src/build-command.ts b/src/build-command.ts index 8106de4..b063a02 100644 --- a/src/build-command.ts +++ b/src/build-command.ts @@ -19,14 +19,13 @@ export type CommandOptionsPreset = Omit; /** A function that takes in CommandOptions and returns a string. */ export const buildCommand = (options: CommandOptions, extraArgs: string[]) => { const o = options; - const reporters = o.reporters ?? ['list', 'json']; - const reportersArg = buildReporters(reporters); + const reporters = o.reporters ? buildReporters(o.reporters) : null; const command: string[] = []; command.push(o.bin); command.push('test'); - if (reportersArg !== null) command.push(reportersArg); + if (reporters !== null) command.push(reporters); if (o.debug === true) command.push('--debug'); if (o.headed === true) command.push('--headed'); if (o.retries !== undefined) command.push(`--retries=${o.retries}`); diff --git a/src/playwright.ts b/src/playwright.ts index 18f961b..cd1826e 100644 --- a/src/playwright.ts +++ b/src/playwright.ts @@ -17,7 +17,6 @@ export const get_projects = () => { { bin: options.get_playwright_command(path), config: options.get_playwright_config(path), - reporters: ['json'], testFilter: './does-not-exist', }, ['--list'],