-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: batch console logs by microtask #7183
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
Changes from 4 commits
6d7fca3
c38327b
b110c3d
b46c9b5
7f82a78
1bb01f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { afterAll, afterEach, beforeAll, beforeEach, describe, test } from 'vitest' | ||
|
|
||
| beforeAll(() => { | ||
| console.log('[beforeAll 1]') | ||
| }) | ||
| beforeAll(() => { | ||
| console.log('[beforeAll 2]') | ||
| }) | ||
|
|
||
| afterAll(() => { | ||
| console.log('[afterAll 1]') | ||
| }) | ||
| afterAll(() => { | ||
| console.log('[afterAll 2]') | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| console.log('[beforeEach 1]') | ||
| }) | ||
| beforeEach(() => { | ||
| console.log('[beforeEach 2]') | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| console.log('[afterEach 1]') | ||
| }) | ||
| afterEach(() => { | ||
| console.log('[afterEach 2]') | ||
| }) | ||
|
|
||
| test('test', async () => { | ||
| console.log('[test 1]') | ||
| console.log('[test 2]') | ||
| await Promise.resolve() | ||
| console.log('[test 3]') | ||
| console.log('[test 4]') | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import type { UserConsoleLog } from 'vitest' | ||
| import { expect, test, vi } from 'vitest' | ||
| import { runVitest } from '../../test-utils' | ||
|
|
||
|
|
@@ -21,3 +22,44 @@ test.each(['threads', 'vmThreads'] as const)(`disable intercept pool=%s`, async | |
| const call = spy.mock.lastCall![0] | ||
| expect(call.toString()).toBe('__test_console__\n') | ||
| }) | ||
|
|
||
| test('group synchronous console logs', async () => { | ||
| const logs: UserConsoleLog[] = [] | ||
| await runVitest({ | ||
| root: './fixtures/console-batch', | ||
| reporters: [ | ||
| 'default', | ||
| { | ||
| onUserConsoleLog(log) { | ||
| logs.push(log) | ||
| }, | ||
|
||
| }, | ||
| ], | ||
| }) | ||
| expect(logs.map(log => log.content)).toMatchInlineSnapshot(` | ||
| [ | ||
| "[beforeAll 1] | ||
| ", | ||
| "[beforeAll 2] | ||
| ", | ||
| "[beforeEach 1] | ||
| ", | ||
| "[beforeEach 2] | ||
| ", | ||
| "[test 1] | ||
| [test 2] | ||
| ", | ||
| "[test 3] | ||
| [test 4] | ||
| ", | ||
| "[afterEach 2] | ||
| ", | ||
| "[afterEach 1] | ||
| ", | ||
| "[afterAll 2] | ||
| ", | ||
| "[afterAll 1] | ||
| ", | ||
| ] | ||
| `) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.
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 this PR changes is only to split these 4 logs into 2-2.
before
after