Skip to content

Per-worker setup/teardown #15710

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

eyalroth
Copy link
Contributor

@eyalroth eyalroth commented Jun 28, 2025

Summary

Implements #8708, and also brings us closer to implement #7184.

Instead of modifying anything with the current globalSetup/Teardown, the PR adds new options globalSetupPerWorker and globalTeardownPerWorker.

If both setup configurations are defined (i.e globalSetup and globalSetupPerWorker) then both will be executed (the former only once, the latter once per worker).

The changes can be largely divided into:

  • Additional e2e test files (most of the changes)
  • Addition of the new configuration options
  • Moving of runGlobalHook.ts from jest-core to jest-runner
  • Actual implementation in jest-runner and jest-worker

I recommend reviewing the PR by going commit by commit.

Test plan

Added multiple e2e tests.

The e2e tests for "per worker" are fairly similar to the "global" ones.

There are also e2e tests for combination of "per worker" and "global" .

Copy link

netlify bot commented Jun 28, 2025

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 228d7b6
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/686043154e10400008c13479
😎 Deploy Preview https://deploy-preview-15710--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

pkg-pr-new bot commented Jun 28, 2025

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15710

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15710

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15710

create-jest

npm i https://pkg.pr.new/create-jest@15710

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15710

expect

npm i https://pkg.pr.new/expect@15710

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15710

jest

npm i https://pkg.pr.new/jest@15710

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15710

jest-circus

npm i https://pkg.pr.new/jest-circus@15710

jest-cli

npm i https://pkg.pr.new/jest-cli@15710

jest-config

npm i https://pkg.pr.new/jest-config@15710

@jest/console

npm i https://pkg.pr.new/@jest/console@15710

@jest/core

npm i https://pkg.pr.new/@jest/core@15710

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15710

jest-diff

npm i https://pkg.pr.new/jest-diff@15710

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15710

jest-each

npm i https://pkg.pr.new/jest-each@15710

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15710

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15710

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15710

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15710

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15710

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15710

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15710

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15710

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15710

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15710

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15710

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15710

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15710

jest-mock

npm i https://pkg.pr.new/jest-mock@15710

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15710

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15710

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15710

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15710

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15710

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15710

jest-runner

npm i https://pkg.pr.new/jest-runner@15710

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15710

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15710

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15710

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15710

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15710

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15710

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15710

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15710

@jest/types

npm i https://pkg.pr.new/@jest/types@15710

jest-util

npm i https://pkg.pr.new/jest-util@15710

jest-validate

npm i https://pkg.pr.new/jest-validate@15710

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15710

jest-worker

npm i https://pkg.pr.new/jest-worker@15710

pretty-format

npm i https://pkg.pr.new/pretty-format@15710

commit: 228d7b6

@eyalroth eyalroth force-pushed the 8708-perworker-globalhooks branch from cc17aed to 8415123 Compare June 28, 2025 19:11
@eyalroth eyalroth force-pushed the 8708-perworker-globalhooks branch from 8415123 to 228d7b6 Compare June 28, 2025 19:31
@eyalroth eyalroth marked this pull request as ready for review June 28, 2025 19:53
@eyalroth
Copy link
Contributor Author

@cpojer mind taking a look?

It's still missing release notes and full documentation. I will add that later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant