jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.12k stars 6.44k forks source link

[Bug]: setupFiles exported function not called #15105

Closed flchaux closed 2 months ago

flchaux commented 3 months ago

I initialize a project with jest 29, I set a setupFiles within an default export function, this function is never called. The setup file is executed, but not the function.

Version

29.7.0

Steps to reproduce

  1. Clone my repo https://github.com/flchaux/jest-setup-files.git
  2. npm i
  3. npm run test

There is one setup file, with an exported function. There is a log in the exported function body and in the file body to ensure the file is executed.

Expected behavior

The test should pass because global.foo is defined to "bar" into setupFiles file. The log called in the exported function should be called.

Actual behavior

The test doesn't pass and only the log in the setupFiles file is displayed. The global variable is not set and the log in the exported function is not displayed.

Additional context

No response

Environment

System:
    OS: Linux 5.15 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    pnpm: 9.1.4 - /usr/local/bin/pnpm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
github-actions[bot] commented 2 months ago

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.

SimenB commented 2 months ago

This was fixed in #14749

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.