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'
4
4
import { getColors , getSafeTimers } from '@vitest/utils'
5
5
import { RealDate } from '../integrations/mock/date'
6
6
import { getWorkerState } from '../utils'
7
+ import type { WorkerGlobalState } from '../types'
7
8
8
9
export const UNKNOWN_TEST_ID = '__vitest__unknown_test__'
9
10
@@ -27,14 +28,14 @@ function getTaskIdByStack(root: string) {
27
28
return UNKNOWN_TEST_ID
28
29
}
29
30
30
- export function createCustomConsole ( ) {
31
+ export function createCustomConsole ( defaultState ?: WorkerGlobalState ) {
31
32
const stdoutBuffer = new Map < string , any [ ] > ( )
32
33
const stderrBuffer = new Map < string , any [ ] > ( )
33
34
const timers = new Map < string , { stdoutTime : number ; stderrTime : number ; timer : any } > ( )
34
35
35
36
const { setTimeout, clearTimeout } = getSafeTimers ( )
36
37
37
- const state = ( ) => getWorkerState ( )
38
+ const state = ( ) => defaultState || getWorkerState ( )
38
39
39
40
// group sync console.log calls with macro task
40
41
function schedule ( taskId : string ) {
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ export async function runVmTests(state: WorkerGlobalState) {
48
48
// because browser doesn't provide these globals
49
49
context . process = process
50
50
context . global = context
51
- context . console = state . config . disableConsoleIntercept ? console : createCustomConsole ( )
51
+ context . console = state . config . disableConsoleIntercept ? console : createCustomConsole ( state )
52
52
// TODO: don't hardcode setImmediate in fake timers defaults
53
53
context . setImmediate = setImmediate
54
54
context . clearImmediate = clearImmediate
Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ import { promises as fs } from 'node:fs'
2
2
import { describe , expect , it , test } from 'vitest'
3
3
import { editFile , runVitest } from '../../test-utils'
4
4
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 ) => {
6
6
const { stdout, stderr } = await runVitest ( {
7
7
root : 'fixtures/setup-files' ,
8
8
include : [ 'empty.test.ts' ] ,
9
9
setupFiles : [ './console-setup.ts' ] ,
10
+ pool,
10
11
} )
11
12
12
13
const filepath = 'console-setup.ts'
You can’t perform that action at this time.
0 commit comments