Skip to content

do not include json reporter by default #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use({
-- end,

-- env = {
-- PW_NVIM = "1",
-- HELLO = "world",
-- },

Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions lua/neotest-playwright/build-command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion lua/neotest-playwright/playwright.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
5 changes: 2 additions & 3 deletions src/build-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ export type CommandOptionsPreset = Omit<CommandOptions, 'bin'>;
/** 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}`);
Expand Down
1 change: 0 additions & 1 deletion src/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down