Skip to content

Vitest addon: Handle Playwright installation errors gracefully#32329

Merged
ndelangen merged 3 commits into
nextfrom
norbert/proceed-if-playwrightinstall-fails
Sep 2, 2025
Merged

Vitest addon: Handle Playwright installation errors gracefully#32329
ndelangen merged 3 commits into
nextfrom
norbert/proceed-if-playwrightinstall-fails

Conversation

@ndelangen
Copy link
Copy Markdown
Member

@ndelangen ndelangen commented Aug 26, 2025

Closes #32117

What I did

I changed the postinstall to continue (with a warning) when the install of playwright failed

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Greptile Summary

This PR adds graceful error handling to the Playwright installation step in the @storybook/addon-vitest postinstall process. The change wraps the npx playwright install chromium --with-deps command in a try-catch block, allowing the addon installation to continue even when Playwright installation fails.

The modification is minimal and targeted - it only affects the Playwright configuration section of the postInstall function in code/addons/vitest/src/postinstall.ts. When Playwright installation fails (which commonly occurs in restricted environments like StackBlitz or Bolt.new), the error is caught and a user-friendly message is displayed advising manual installation, but the rest of the addon setup process continues normally.

This change fits well within the broader postinstall architecture, which already handles various installation scenarios and user prompts. The postinstall function is responsible for setting up multiple components including Vitest dependencies, configuration files, and optional features like the accessibility addon. By making Playwright installation non-blocking, the PR ensures that users can still benefit from the core Vitest addon functionality even in environments where Playwright cannot be automatically installed.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it only adds error handling without changing core functionality
  • Score reflects the simple, targeted nature of the change that improves user experience in edge cases
  • Pay close attention to the error handling implementation to ensure proper logging occurs

@ndelangen ndelangen changed the title Fix postinstall script to handle Playwright installation errors gracefully AddonVitest: Handle Playwright installation errors gracefully Aug 26, 2025
@ndelangen ndelangen requested a review from yannbf August 26, 2025 10:11
@ndelangen ndelangen self-assigned this Aug 26, 2025
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Aug 26, 2025

View your CI Pipeline Execution ↗ for commit 8fd4a16

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 48s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-02 09:14:59 UTC

@ndelangen ndelangen marked this pull request as ready for review August 26, 2025 14:50
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

args: ['playwright', 'install', 'chromium', '--with-deps'],
});
} catch (e) {
console.error('Failed to install Playwright. Please install it manually');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using the existing logger utilities (printError or printWarning) instead of console.error for consistency with the rest of the codebase's logging approach

Suggested change
console.error('Failed to install Playwright. Please install it manually');
printError('Failed to install Playwright. Please install it manually');

@ndelangen ndelangen merged commit bc6faab into next Sep 2, 2025
55 checks passed
@ndelangen ndelangen deleted the norbert/proceed-if-playwrightinstall-fails branch September 2, 2025 13:21
@github-actions github-actions Bot mentioned this pull request Sep 2, 2025
8 tasks
@shilman shilman changed the title AddonVitest: Handle Playwright installation errors gracefully Vitest addon: Handle Playwright installation errors gracefully Sep 2, 2025
args: ['playwright', 'install', 'chromium', '--with-deps'],
});
} catch (e) {
console.error('Failed to install Playwright. Please install it manually');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have guidelines for how to log errors now (so that we can swap in clack)? cc @yannbf

Copy link
Copy Markdown
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndelangen do we want to patch this back?

@shilman shilman added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Sep 3, 2025
@github-actions github-actions Bot mentioned this pull request Sep 3, 2025
5 tasks
shilman pushed a commit that referenced this pull request Sep 6, 2025
…ghtinstall-fails

AddonVitest: Handle Playwright installation errors gracefully
(cherry picked from commit bc6faab)
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Sep 6, 2025
@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addon: vitest bug ci:normal compatibility with other tools patch:done Patch/release PRs already cherry-picked to main/release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Storybook cannot be installed in a Stackblitz or Bolt.new environment

2 participants