Skip to content
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

[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

Open
iwaduarte opened this issue Feb 10, 2025 · 1 comment

Comments

@iwaduarte
Copy link

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)
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant