bug: Stencil can resolve incorrect jest-runner dependency when using pnpm
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- testing-qa, tooling
Research direction
Reproduce the failure from packages/stencil with pnpm install followed by pnpm test.spec, then trace the runner resolution from @stencil/core/testing/index.js using the provided stack trace. Done means the Jest v29 runner is selected for the Stencil project despite another workspace package using Jest v26, and the tests complete successfully.
Written by the indexing model from the issue text.
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
v4.9.0
Current Behavior
In a mono-repo using pnpm where you have mixed dependency versions of Jest, specifically the jest-runner package, Stencil will incorrectly use an older version of the jest-runner package, even though the Stencil project may be configured with a newer version.
For example, in a project that has Jest v29 for the Stencil project, but another package with Jest v26, Stencil will use the test facade for Jest v29, but use the jest-runner@26 instance when executing the test runner.
This results in an exception:
TypeError: Cannot read properties of undefined (reading 'serial')
I've modified the bundle to provide the entire stack trace:
TypeError: Cannot read properties of undefined (reading 'serial')
at e.runTests (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/jest-runner@26.6.3/node_modules/jest-runner/build/index.js:108:27)
at e.runTests (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@stencil+core@4.9.0/node_modules/@stencil/core/testing/index.js:926:19)
at TestScheduler.scheduleTests (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@jest+core@29.7.0/node_modules/@jest/core/build/TestScheduler.js:283:32)
at async runJest (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@jest+core@29.7.0/node_modules/@jest/core/build/runJest.js:367:19)
at async _run10000 (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@jest+core@29.7.0/node_modules/@jest/core/build/cli/index.js:343:7)
at async runCLI (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@jest+core@29.7.0/node_modules/@jest/core/build/cli/index.js:198:3)
at async runJest (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@stencil+core@4.9.0/node_modules/@stencil/core/testing/index.js:900:10)
at async Object.run (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@stencil+core@4.9.0/node_modules/@stencil/core/testing/index.js:12865:10)
at async taskTest (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@stencil+core@4.9.0/node_modules/@stencil/core/cli/index.cjs:2395:24)
at async runTask (/Users/sean/Documents/ionic/issues/ionic-framework/node_modules/.pnpm/@stencil+core@4.9.0/node_modules/@stencil/core/cli/index.cjs:2514:13)
This behavior is likely driven from pnpm hoisting the dependency, changing the execution location from which Stencil uses to grab the jest-runner instance and invoke it. I suspect we will need to make stricter assumption around where this instance lives, such as from the rootDir of the project, instead of from the executing node_modules.
Expected Behavior
Stencil should resolve its own dependency of the jest-runner, regardless of if the workspace is using another dependency for another project in the mono-repo.
System Info
`npx stencil info` fails with:
> npm ERR! could not determine executable to run
Steps to Reproduce
- Clone the repository - it is a mono-repo.
- Install pnpm, if not already installed: https://pnpm.io/installation
- Install project dependencies:
pnpm install - Run unit tests for the Stencil project:
cd packages/stencil && pnpm test.spec - Observe: Exception is thrown, tests do not run successfully.
- Expected: Tests run successfully.
Code Reproduction URL
https://github.com/sean-perkins/stencil-pnpm-issue
Additional Information
Workarounds:
- Downgrade to the lowest version of Jest that is compatible with Stencil, for example with the reproduction downgrading the Stencil project to Jest v26.
- Upgrade all packages in the mono-repo to the same version of Jest as the Stencil project.
- Use npm or a package manager that does not hoist dependencies.
- Dominant language
- TypeScript
- Stars
- 13.1k
- Forks
- 855
- Avg merge
- 4h 7m
- Merged PRs (30d)
- 44
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stenciljs/core
-
Stencil v5
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Bug: Validated Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Feature: Want this? Upvote it!
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Feature: Want this? Upvote it!
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·