Skip to content

Commit

Permalink
fix: show console logs to "Test Output"
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Feb 16, 2024
1 parent a93b0f0 commit 8ba2f51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions samples/basic/test/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ describe('addition', () => {
describe('testing', () => {
it('run', () => {
const a = 10
console.log("foo", { a });
expect(a).toBe(10)
})

it('mul', () => {
console.log("hey1");
console.log("hey2");
console.log("hey3");
expect(5 * 5).toBe(25)
})
})
9 changes: 9 additions & 0 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ export function syncTestStatusToVsCode(
for (const task of vitest) {
const data = matchTask(task, set)
if (task.type === 'test' || task.type === 'custom') {
// for now, display logs after all tests are finished.
// ideally, it might be possible to append logs during test execution via `onUserConsoleLog` rpc.
if (finished) {
for (const log of task.logs ?? []) {
// LF to CRLF https://code.visualstudio.com/api/extension-guides/testing#test-output
const output = log.content.replace(/(?<!\r)\n/g, "\r\n");
run.appendOutput(output, undefined, data.item);
}
}
if (task.result == null) {
if (finished) {
finishedTest && finishedTest.add(data.item)
Expand Down

0 comments on commit 8ba2f51

Please sign in to comment.