Skip to content

[Bug]: Jest doesn't copy env variables to child processes when parallel execution in Linux environments but works in Windows. Resulting in "fetch is not defined" #15499

@iwaduarte

Description

@iwaduarte

Version

29.7.0

Steps to reproduce

Node: 22.13.1 (LTS)

Create a brand-new tiny project:

  1. npm init -y
  2. npm install --save-dev jest@latest
  3. npm install jest-environment-jsdom
  4. echo "module.exports = { testEnvironment: 'jsdom', globals: { fetch: globalThis.fetch } };" > jest.config.js
  5. make two files fetch1.test.js and fetch2.test.js with exactly same code:
// fetch.test.js
beforeAll(() => {
  console.log(`PID: ${process.pid}, typeof globalThis.fetch = ${typeof globalThis.fetch}`);
});

test('fetch presence', () => {
  expect(typeof fetch).toBe('function');
});

  1. add "test: jest" to package.json

  2. npm run test

  • Running in Windows (it works just fine) ✅
  • Running in Linux: Ubuntu (it fails) ❌
  1. npm run test -- --runInBand
  • Running in Windows (it works just fine) ✅
  • Running in Linux: Ubuntu (it works just fine) ✅

Expected behavior

It should run independently of the OS or parallelization. It appears that the child process does not get the full parent context when running in Linux.

Actual behavior

  1. npm run test
  • Running in Windows (it works just fine) ✅

Image

  • Running in Linux: Ubuntu (it fails) ❌

Image

  1. npm run test -- --runInBand
  • Running in Windows (it works just fine) ✅

Image

  • Running in Linux: Ubuntu (it works just fine) ✅

Image

Additional context

No response

Environment

System: 
Windows 11 and Linux Ubuntu (22.04.3)

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