-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Problem
Scenario: Playwright config command produces warnings as part of output
GIVEN the following command produces output that is not just JSON.
playwright test --list --reporter=jsonWarning: Cannot polyfill `DOMMatrix`, rendering may be broken.
Warning: Cannot polyfill `Path2D`, rendering may be broken.
{
"config": {
...many more lines
}
}WHEN discovery is performed
THEN no tests are found.
Logs
WARN | 2025-01-23T22:51:17Z-0600 | ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:164 | CHILD | Error in remote call Vim:E474: Unidentified byte: Warning: Cannot polyfill `DOMMatrix`, rendering may be broken.
Warning: Cannot polyfill `Path2D`, rendering may be broken.
{
"config": {
"configFile": "C:\\Users\\sfree\\software_projects\\OnspringEnd2EndTests\\playwright.config.ts",
"rootDir": "C:/Users/sfree/software_projects/OnspringEnd2EndTests/tests",
"forbidOnly": false,
"fullyParallel": true,
"globalSetup": null,
"globalTeardown": null,
"globalTimeout": 0,
"grep": {},
"grepInvert": null,
"maxFailures": 0,
"metadata": {
"environment": "QA"
},
"preserveOutput": "always",
"reporter": [
[
"json"
]
],
"reportSlowTests": null,
"quiet": false,
"projects": [
{
"outputDir": "C:/Users/sfree/software_projects/OnspringEnd2EndTests/test-results",
"repeatEach": 1,
"retries": 0,
"metadata": {
"environment": "QA"
},
"id": "setup",
"name": "setup",
"testDir": "C:/User
stack traceback:
[C]: in function 'json_decode'
...neotest-playwright/lua/neotest-playwright/playwright.lua:225: in function 'run'
...neotest-playwright/lua/neotest-playwright/playwright.lua:196: in function 'get_config'
...y/neotest-playwright/lua/neotest-playwright/discover.lua:254: in function 'refresh_data'
...y/neotest-playwright/lua/neotest-playwright/discover.lua:248: in function 'func'
...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:156: in function <...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:155>
[C]: in function 'xpcall'
...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:155: in function <...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:154>Proposed Solution
Obviously a fix can be achieved for this by addressing the warnings or additional output being produced I believe my just making sure to parse the beginning and ending of the JSON here we can handle this more gracefully
neotest-playwright/src/playwright.ts
Lines 34 to 62 in 6266945
| const run = (cmd: string) => { | |
| const [handle, errmsg] = io.popen(cmd); | |
| if (typeof errmsg === 'string') { | |
| logger('error', errmsg); | |
| } | |
| if (!handle) { | |
| emitError(`Failed to execute command: ${cmd}`); | |
| return; | |
| } | |
| const output = handle.read('*a'); | |
| handle.close(); | |
| if (typeof output !== 'string') { | |
| emitError(`Failed to read output from command: ${cmd}`); | |
| return; | |
| } | |
| if (output === '') { | |
| emitError(`No output from command: ${cmd}`); | |
| return; | |
| } | |
| const decoded = vim.fn.json_decode(output) as P.JSONReport; | |
| return decoded; | |
| }; |
I'm thinking something like this will do the trick:
const jsonMatch = string.match(output, "%b{}");
if (!jsonMatch) {
emitError(`Failed to parse JSON output: ${output}`);
return;
}
const jsonString = jsonMatch[0];
try {
const decoded = vim.fn.json_decode(jsonString) as P.JSONReport;
return decoded;
} catch (err) {
if (err instanceof Error) {
emitError(`Failed to decode JSON: ${err.message}`);
}
return;
}Metadata
Metadata
Assignees
Labels
No labels