File tree Expand file tree Collapse file tree 3 files changed +6
-4
lines changed
packages/vitest/src/runtime Expand file tree Collapse file tree 3 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { relative } from 'node:path'
44import { getColors , getSafeTimers } from '@vitest/utils'
55import { RealDate } from '../integrations/mock/date'
66import { getWorkerState } from '../utils'
7+ import type { WorkerGlobalState } from '../types'
78
89export const UNKNOWN_TEST_ID = '__vitest__unknown_test__'
910
@@ -27,14 +28,14 @@ function getTaskIdByStack(root: string) {
2728 return UNKNOWN_TEST_ID
2829}
2930
30- export function createCustomConsole ( ) {
31+ export function createCustomConsole ( defaultState ?: WorkerGlobalState ) {
3132 const stdoutBuffer = new Map < string , any [ ] > ( )
3233 const stderrBuffer = new Map < string , any [ ] > ( )
3334 const timers = new Map < string , { stdoutTime : number ; stderrTime : number ; timer : any } > ( )
3435
3536 const { setTimeout, clearTimeout } = getSafeTimers ( )
3637
37- const state = ( ) => getWorkerState ( )
38+ const state = ( ) => defaultState || getWorkerState ( )
3839
3940 // group sync console.log calls with macro task
4041 function schedule ( taskId : string ) {
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ export async function runVmTests(state: WorkerGlobalState) {
4848 // because browser doesn't provide these globals
4949 context . process = process
5050 context . global = context
51- context . console = state . config . disableConsoleIntercept ? console : createCustomConsole ( )
51+ context . console = state . config . disableConsoleIntercept ? console : createCustomConsole ( state )
5252 // TODO: don't hardcode setImmediate in fake timers defaults
5353 context . setImmediate = setImmediate
5454 context . clearImmediate = clearImmediate
Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ import { promises as fs } from 'node:fs'
22import { describe , expect , it , test } from 'vitest'
33import { editFile , runVitest } from '../../test-utils'
44
5- test ( ' print stdout and stderr correctly when called in the setup file', async ( ) => {
5+ test . each ( [ 'threads' , 'vmThreads' ] ) ( '%s: print stdout and stderr correctly when called in the setup file', async ( pool ) => {
66 const { stdout, stderr } = await runVitest ( {
77 root : 'fixtures/setup-files' ,
88 include : [ 'empty.test.ts' ] ,
99 setupFiles : [ './console-setup.ts' ] ,
10+ pool,
1011 } )
1112
1213 const filepath = 'console-setup.ts'
You can’t perform that action at this time.
0 commit comments