Skip to content

[Bug]: Mocking process.stdout does not work #15641

Open
@albertodiazdorado

Description

@albertodiazdorado

Version

29.7.0

Steps to reproduce

TL;DR: Spying on process.stdout.write works if there is a single file in the test suite, and fails if there is more than one.

I have prepared a small reproducer: https://github.com/albertodiazdorado/jest-stdout-bug-reproducer

The instructions to reproduce the bug are written in the README. In short:

git clone https://github.com/albertodiazdorado/jest-stdout-bug-reproducer.git
cd jest-stdout-bug-reproducer
npm install --no-save
npm run test:single-file # green
npm run test:multiple-file #red

This issue was already raised (#9984). However, the reproducer was of low quality and thus the issue was closed without a proper answer.

Expected behavior

I can mock process.stdout.write if my test suite has more than one file.

Actual behavior

I cannot mock process.stdout.write if my test suite has more than one file.

Additional context

No response

Environment

System:
    OS: Linux 6.8 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
  Binaries:
    Node: 22.14.0 - /run/user/1000/fnm_multishells/132949_1748593052414/bin/node
    npm: 10.9.2 - /run/user/1000/fnm_multishells/132949_1748593052414/bin/npm
    pnpm: 9.15.1 - /run/user/1000/fnm_multishells/132949_1748593052414/bin/pnpm
  npmPackages:
    jest: ^29.7.0 => 29.7.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions