Skip to content
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

fix: show console logs in "Test Output" #228

Merged
merged 4 commits into from
Feb 18, 2024

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Feb 16, 2024

Currently this extension uses TestRun.appendOutput only to surface Vitest server logging:

vscode/src/runHandler.ts

Lines 309 to 314 in d8c8908

info: (msg: string) => {
if (items.length === 1)
run.appendOutput(msg, undefined, items[0])
else
run.appendOutput(msg)
},

This approach might work in some cases, but it seems inconsistent (for example, when running multiple tests at once).

I think the better way to surface logs for each test run is to use either:

  • Task.logs: UserConsoleLog[] or
  • Reporter.onUserConsoleLog: (log: UserConsoleLog) => Awaitable<void>

Ideally, we probably want to go with the 2nd approach onUserConsoleLog where we match Vitest's log.taskId against Vscode's TestRun to call specific TestRun.appendOutput in real time. But for this, it requires some more refactoring around vscode/vitest task matching utility, so for now I went with 1st approach where Task.logs are reliably available after the test is finished.

todo

  • check "Continuous Run" mode
Show demo
2024-02-16.12-11-59.webm

@hi-ogawa hi-ogawa force-pushed the fix-console-log-to-test-output branch 2 times, most recently from 8ba2f51 to 982ffa0 Compare February 18, 2024 05:42
@hi-ogawa hi-ogawa changed the title fix: show console logs to "Test Output" fix: show console logs in "Test Output" Feb 18, 2024
@hi-ogawa hi-ogawa marked this pull request as ready for review February 18, 2024 06:26
@sheremet-va sheremet-va merged commit 1506fe1 into vitest-dev:main Feb 18, 2024
@seaders seaders mentioned this pull request Jun 28, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No test output
2 participants