Skip to content

fix: jest globalSetup/globalTeardown without a preset, support <rootDir> - #68

Open
exo-nikita wants to merge 2 commits into
mainfrom
fix/jest-global-setup
Open

exo-nikita wants to merge 2 commits into
mainfrom
fix/jest-global-setup

Conversation

@exo-nikita

Copy link
Copy Markdown
Collaborator

Fixes two --jest config loading bugs for globalSetup / globalTeardown.

1. Crash on globalSetup/globalTeardown without a preset

Since 71c65f3 (first released in rc.97), loadJestConfig() enters the preset/globalSetup branch when either is set, but then unconditionally calls cleanFile(rawConfig.preset). With no preset, that throws:

TypeError: Cannot read properties of undefined (reading 'replace')
    at cleanFile (src/jest.config.js:139)

Consumers currently work around it with preset: '' in their jest config, which can be dropped after this is released.

2. <rootDir> in globalSetup/globalTeardown

Jest supports globalSetup: '<rootDir>/…', but we passed it to require.resolve() as is:

Error: Cannot find module '<rootDir>/global-setup.js'

Top-level globalSetup / globalTeardown now get the same <rootDir>/ → ./ treatment as preset (relative to rootDir, top level only, as before).

Tests

New test:global-setup script (added to test:all, same pattern as test:jsdom): no preset, globalSetup via <rootDir>/…, globalTeardown via ./…. The test asserts globalSetup ran before tests, and the teardown throws if it ran without setup.

  • Fails on main with the TypeError, and with Cannot find module '<rootDir>/…' with only the first commit
  • CI=1 pnpm test:all and pnpm lint pass locally (Node 24)

This branch has not been deployed

No deployments
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