Fix #33844: [Bug]: Storybook React Native Web - Issue with Testing addon#33898
Fix #33844: [Bug]: Storybook React Native Web - Issue with Testing addon#33898danielalanbates wants to merge 1 commit intostorybookjs:nextfrom
Conversation
When `useRemotePkg` is true, `Yarn2Proxy.runPackageCommand` now uses `yarn dlx` instead of `yarn exec`. `yarn exec` only runs locally installed binaries, causing exit code 127 when attempting to download and run a remote package (e.g. `storybook@10.2.7`) during addon postinstall on Yarn 2+. Fixes storybookjs#33844
📝 WalkthroughWalkthroughThe PR adds an optional Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
code/core/src/common/js-package-manager/Yarn2Proxy.ts (1)
97-114:⚠️ Potential issue | 🔴 Critical
getPackageCommanddisplays incorrect command whenuseRemotePkg: true
getPackageCommand(line 97–99) hardcodesyarn execand ignores theuseRemotePkgflag. This method is used inAddonVitestService.ts(lines 142, 162) to display the Playwright installation command to users in guidance and error messages. WhenuseRemotePkg: trueis passed torunPackageCommand(line 155), the actual execution usesyarn dlxbut the displayed string showsyarn exec, causing a mismatch between what users are told to run and what was actually executed.Update
getPackageCommandto accept theuseRemotePkgparameter and conditionally return the correct command, or refactor the usage to display the accurate command being executed.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/core/src/common/js-package-manager/Yarn2Proxy.ts` around lines 97 - 114, getPackageCommand currently always returns "yarn exec ..." which mismatches runPackageCommand when useRemotePkg is true; change getPackageCommand signature to accept a boolean useRemotePkg (default false) and return `yarn dlx ...` when true and `yarn exec ...` when false, then update callers (e.g., AddonVitestService usage) to pass the same useRemotePkg flag or refactor those callers to derive the display string from runPackageCommand's args so the displayed command matches the executed one.
🧹 Nitpick comments (1)
code/core/src/common/js-package-manager/Yarn2Proxy.test.ts (1)
71-87: Mock setup belongs inbeforeEachper project guidelinesThe
mockResolvedValueat lines 72–74 is set up inline inside the test case. Per the coding guidelines, mock behaviors should be implemented inbeforeEachblocks and not inline within test cases. This is also the pattern used by every existing test in this file, so a broader cleanup would be needed to fully align — consider addressing this holistically rather than just in the new test.♻️ Suggested pattern
describe('runScript', () => { + beforeEach(() => { + mockedExecuteCommand.mockResolvedValue({ stdout: '' } as any); + }); + it('should execute script `yarn compodoc -- -e json -d .`', async () => { - const executeCommandSpy = mockedExecuteCommand.mockResolvedValue({ - stdout: '7.1.0', - } as any); + const executeCommandSpy = mockedExecuteCommand; await yarn2Proxy.runPackageCommand({ args: ['compodoc', '-e', 'json', '-d', '.'] }); ... }); it('should use `yarn dlx` when useRemotePkg is true', async () => { - const executeCommandSpy = mockedExecuteCommand.mockResolvedValue({ - stdout: '', - } as any); + const executeCommandSpy = mockedExecuteCommand; await yarn2Proxy.runPackageCommand({ args: ['storybook@latest', 'automigrate'], useRemotePkg: true, }); ... }); });Based on learnings: "Implement mock behaviors in
beforeEachblocks in Vitest tests" and "Avoid inline mock implementations within test cases in Vitest tests."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/core/src/common/js-package-manager/Yarn2Proxy.test.ts` around lines 71 - 87, The inline mockResolvedValue call on mockedExecuteCommand inside the test "should use `yarn dlx` when useRemotePkg is true" should be moved into the test file's beforeEach setup to follow project guidelines; update the beforeEach that configures mocks to call mockedExecuteCommand.mockResolvedValue({ stdout: '' } as any) (or add a new beforeEach if none exists) and remove the inline mockedExecuteCommand.mockResolvedValue(...) from the test; leave the rest of the test intact (yarn2Proxy.runPackageCommand invocation and the expect on executeCommandSpy).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@code/core/src/common/js-package-manager/Yarn2Proxy.ts`:
- Around line 97-114: getPackageCommand currently always returns "yarn exec ..."
which mismatches runPackageCommand when useRemotePkg is true; change
getPackageCommand signature to accept a boolean useRemotePkg (default false) and
return `yarn dlx ...` when true and `yarn exec ...` when false, then update
callers (e.g., AddonVitestService usage) to pass the same useRemotePkg flag or
refactor those callers to derive the display string from runPackageCommand's
args so the displayed command matches the executed one.
---
Nitpick comments:
In `@code/core/src/common/js-package-manager/Yarn2Proxy.test.ts`:
- Around line 71-87: The inline mockResolvedValue call on mockedExecuteCommand
inside the test "should use `yarn dlx` when useRemotePkg is true" should be
moved into the test file's beforeEach setup to follow project guidelines; update
the beforeEach that configures mocks to call
mockedExecuteCommand.mockResolvedValue({ stdout: '' } as any) (or add a new
beforeEach if none exists) and remove the inline
mockedExecuteCommand.mockResolvedValue(...) from the test; leave the rest of the
test intact (yarn2Proxy.runPackageCommand invocation and the expect on
executeCommandSpy).
Fixes #33844
Summary
This PR fixes: [Bug]: Storybook React Native Web - Issue with Testing addons installation
Changes
Testing
Please review the changes carefully. The fix was verified against the existing test suite.
This PR was created with the assistance of Claude Sonnet 4.6 by Anthropic | effort: low. Happy to make any adjustments!
Summary by CodeRabbit
New Features
Tests