-
Notifications
You must be signed in to change notification settings - Fork 50
chore: upgrade jest to support new node #2067
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const fs = require('fs'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const path = require('path'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function resolveJestEnvironmentJsdom26() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pnpmDir = path.resolve(__dirname, '../../common/temp/node_modules/.pnpm'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pnpmDir = path.resolve(__dirname, '../../common/temp/node_modules/.pnpm'); | |
| const pnpmDir = path.resolve(__dirname, '../../common/temp/node_modules/.pnpm'); | |
| if (!fs.existsSync(pnpmDir)) { | |
| throw new Error( | |
| 'Unable to locate PNPM directory at "common/temp/node_modules/.pnpm". ' + | |
| 'Ensure that dependencies have been installed (for example, by running "rush install" in the repo root).' | |
| ); | |
| } |
Copilot
AI
Apr 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This environment resolver relies on pnpm’s internal virtual store layout (common/temp/node_modules/.pnpm) and directory naming to locate jest-environment-jsdom@26.6.2. This is brittle and makes the test environment sensitive to pnpm implementation details. A more robust approach is to use require.resolve('jest-environment-jsdom/build/index.js', { paths: [path.resolve(__dirname, '../../common/temp/node_modules')] }) (or similar) so Node’s resolver finds the correct installed copy without scanning .pnpm.
| const fs = require('fs'); | |
| const path = require('path'); | |
| function resolveJestEnvironmentJsdom26() { | |
| const pnpmDir = path.resolve(__dirname, '../../common/temp/node_modules/.pnpm'); | |
| const entry = fs | |
| .readdirSync(pnpmDir) | |
| .find(name => name.startsWith('jest-environment-jsdom@26.6.2')); | |
| if (!entry) { | |
| throw new Error('Unable to resolve jest-environment-jsdom@26.6.2 from common/temp/node_modules/.pnpm'); | |
| } | |
| return path.join(pnpmDir, entry, 'node_modules/jest-environment-jsdom/build/index.js'); | |
| const path = require('path'); | |
| function resolveJestEnvironmentJsdom26() { | |
| const baseNodeModulesDir = path.resolve(__dirname, '../../common/temp/node_modules'); | |
| try { | |
| return require.resolve('jest-environment-jsdom/build/index.js', { | |
| paths: [baseNodeModulesDir], | |
| }); | |
| } catch (error) { | |
| throw new Error( | |
| 'Unable to resolve jest-environment-jsdom@26.6.2 from ' + baseNodeModulesDir | |
| ); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this config,
testEnvironment/setupFilesare specified as relative paths (e.g.../../share/...) whereas other package configs usepath.resolve(__dirname, ...). Using absolute paths here avoids surprises ifrootDiris customized or Jest is invoked from a different working directory, and keeps the configs consistent across packages.