-
-
Notifications
You must be signed in to change notification settings - Fork 112
feat: use reporters in the test results panel #707
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
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| // Show the equivalent CLI command for debugging/reproducibility | ||
| const fileList = files.map(f => this.relative(f)).join(' ') | ||
| const pattern = formatTestPattern(request.include || []) | ||
| let vitestCmd = 'vitest' | ||
| if (fileList) { | ||
| vitestCmd += ` ${fileList}` | ||
| } | ||
| if (pattern) { | ||
| vitestCmd += ` -t "${pattern}"` | ||
| } | ||
| run.appendOutput(`\x1B[36m\x1B[1m[command]\x1B[0m ${vitestCmd}\r\n\r\n`) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how the extension works, we don't create a new process for every test run. Even more, I am planning to change to the new project.createSpecification API that supports test ids, making this line useless
|
|
||
| function formatTestOutput(output: string) { | ||
| return stripVTControlCharacters(output.replace(/(?<!\r)\n/g, '\r\n')) | ||
| return output.replace(/(?<!\r)\n/g, '\r\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test results panel in VSCode / Cursor supports colors. No need to remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colors are not supported in inline view, at least
sheremet-va
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes seems to break things rather than fix them. Please open an issue with the desired functionality, it needs to be discussed first
| // run the next test when this one finished, or cancell or test runs if they were cancelled | ||
| this.testRunDefer.promise = this.testRunDefer.promise.finally(() => { | ||
| run.end() | ||
| this.testRun = undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
| clearListeners() { | ||
| for (const name in handlers) | ||
| handlers[name as 'onCollected']?.clear() | ||
| // Clear all handlers except onProcessLog, which needs to persist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do this? the handlers are not cleaned after the test run, they are cleaned when the fork is destroyed, onProcessLog needs to be cleaned
| stdoutCallbacks.clear() | ||
| } | ||
|
|
||
| // Forward RPC process logs to the same stdout callbacks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
| }) | ||
|
|
||
| // Skip individual console logs since DefaultReporter already includes them | ||
| // api.onConsoleLog((consoleLog) => { ... } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
| stderr, | ||
| stdout, | ||
| }, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? This makes it so unhandled errors outside of tests are not reporter (failed global setup, for example)
| ['json', { ...jsonReporterOptions, file: meta.finalCoverageFileName }], | ||
| ] | ||
|
|
||
| const rawReporters = testConfig.reporters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We intentionally don't show the report since vscode already has the UI to show everything. It is a waste of resources to duplicate it
The extension also doesn't support the same hooks order, so custom reporters might break
If the intention is to help AI, then it is better to have a custom reporter designed for that (to reduce the amount of tokens, at least) or something like this: #676
|
|
||
| testRun.appendOutput( | ||
| formatTestOutput(consoleLog.content) + (consoleLog.browser ? '\r\n' : ''), | ||
| location, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change logs are no longer attributed to tests and are not shown inline in UI
| // Signal that the test run is complete, but DON'T set this.testRun to undefined yet | ||
| // The testRun will be properly ended in the finally block of startTestRun | ||
| if (!collecting) { | ||
| this.testRunDefer?.resolve() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why replace this.endTestRun with an incomplete promise resolution?
Thanks for the thorough review! You're right, I rushed the PR, and there might be things I'm not addressing correctly. I've opened this issue hoping we can agree on the "why" before moving on to the "how." Thank you so much for your time! |

Problem
Prior to this pull request, the test results panel only displayed the
console.logsthat occurred during the test.Clicking on the test instance in the right panel displays the expected and actual values in separate boxes, along with a series of traces. However, this format is divided into different terminals, making it difficult to copy and paste, or even to read (for both humans and AI).
Solution
With this PR, two things are displayed:
reporters.Before:
After:
Changes
1.
runner.ts- Preserve ANSI colors & clean outputstripVTControlCharacters(): VS Code's Test Results panel supports ANSI escape codes for colors2.
rpc.ts- Add persistentonProcessLoghandler3.
child_process.ts- Connect RPC to stdout callbacksonProcessLogto callbacks: The worker sends output via WebSocket/RPC, not Node's native stdout. This bridges RPC events to the stdout callback system4.
worker/index.ts- Enable DefaultReporterDefaultReporteralongsideVSCodeReporterto get CLI-style outputreporters: ['verbose']), those are used instead of 'default'Minor Formatting Differences
Due to the way Vitest's detects terminal environments, there are small formatting differences compared to CLI output:
❯ addition (9)not shown)