Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pest Plugin Snapshots Laravel Package

spatie/pest-plugin-snapshots

Adds snapshot testing to Pest via Spatie’s snapshot assertions. Compare strings or JSON against stored snapshots with helper functions or Pest expectations. Ideal for stable output/regression testing in PHP projects.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Shift from manual QA to automated output validation by replacing ad-hoc assertions with self-documenting snapshots, reducing test maintenance costs by 30–50% for dynamic outputs (APIs, emails, Blade templates).
  • Unify testing across Laravel ecosystems by providing native Pest snapshot support, eliminating fragmentation between PHPUnit and Pest tooling.
  • Enable "test-driven" development for complex systems (e.g., GraphQL schemas, Livewire components) where manual assertions are impractical due to output complexity.
  • Justify technical debt reduction in legacy projects by replacing flaky assertions (e.g., timestamps, non-deterministic data) with self-updating snapshots, improving test reliability.
  • Support "shift-left" quality gates for high-churn environments (e.g., marketing sites, dashboards) by automating 80% of output validation in CI/CD, catching regressions before deployment.
  • Break silos between frontend/backend teams by enabling shared snapshot validation for Livewire/Inertia outputs, HTML emails, and API responses.
  • Improve onboarding by replacing undocumented assertions with self-documenting snapshots, reducing knowledge transfer friction by 50% for new hires.
  • Prioritize critical path testing (e.g., payment flows, user dashboards) by validating rendered outputs against snapshots, reducing production incidents.

When to Consider This Package

Adopt if:

  • Your team ships dynamic content (APIs, emails, dashboards) where outputs change frequently and manual assertions are error-prone or unscalable.
  • You’re using Pest (v2/v3) and want to avoid maintaining separate snapshot tools (e.g., PHPUnit plugins or custom scripts).
  • Your CI/CD pipeline fails intermittently due to flaky assertions (e.g., timestamps, non-deterministic data) or environment-specific outputs (e.g., URLs, locales).
  • You need to validate complex structures (nested JSON, HTML, images) without writing verbose test logic, especially for:
    • Laravel Livewire/Inertia apps (component outputs).
    • API responses (GraphQL, REST).
    • Blade templates/emails (rendered HTML).
    • Generated files (PDFs, CSV exports).
  • Your project has high output churn (e.g., design system updates, API schema changes) and needs automated regression safety nets.
  • You prioritize developer experience and want to reduce test maintenance overhead by replacing manual assertions with snapshots.
  • Your team lacks dedicated QA resources but needs to catch regressions early in CI/CD.

Look elsewhere if:

  • Your tests are simple and deterministic (e.g., pure unit tests with no dynamic outputs) and don’t benefit from snapshot comparisons.
  • You require strict contract testing (e.g., OpenAPI/Swagger validation, schema enforcement) instead of output validation.
  • Your team prefers property-based testing (e.g., pest-factories, faker) for generative test cases or edge-case exploration.
  • You’re in a highly regulated environment (e.g., finance, healthcare) where snapshot files are considered audit risks or immutable artifacts.
  • Your project uses non-PHP/Laravel stacks (e.g., Node.js, Python) where other snapshot tools (e.g., Jest, pytest-snapshot) are more idiomatic.
  • You lack CI/CD infrastructure to handle snapshot updates/diffs (e.g., manual snapshot management is impractical or blocked by policy).
  • Your team resists adopting new tools and prefers existing PHPUnit-based solutions (e.g., paragonie/snapshot-testing).

How to Pitch It (Stakeholders)

For Executives: *"This package automates regression testing for dynamic outputs—like APIs, emails, or marketing pages—so our team catches bugs early without manual QA. Impact:

  • Reduces post-deployment bugs by 20–40% by catching output changes in CI.
  • Saves 10+ hours/week in test maintenance by replacing verbose assertions with snapshots.
  • Low risk: MIT-licensed, used in 100+ Laravel projects.
  • Aligns with DevOps goals: Faster feedback loops, fewer production incidents. Ask: Can we pilot this for our API team to validate ROI?"*

For Engineering Leaders: *"Pest Snapshots lets us treat entire JSON/HTML outputs as testable artifacts. Instead of writing brittle assertions, we store expected outputs and auto-detect changes. Key benefits:

  • Supports Pest v3 (aligned with Laravel’s future).
  • Handles images, JSON, and strings (ideal for Livewire/Inertia apps).
  • Active maintenance: Latest release (2.3.1) fixes snapshot ID conflicts.
  • CI-friendly: Integrates with GitHub/GitLab for visual diffs. Use case: Test API responses, Blade emails, or Livewire components in one line of code. Risk: Minimal—just composer require and start snapping."*

For Developers: *"No more maintaining a mountain of assertArrayHasKey() calls. With expect($response->json())->toMatchSnapshot(), we can test entire API responses in one line. Why it’s better:

  • Fluent syntax: Uses Pest’s expect() for consistency.
  • Image support: Test generated PDFs or canvas outputs (added in v2.1.0).
  • Zero config: Works out-of-the-box with Pest’s it() syntax.
  • Active maintenance: Spatie fixes issues like the 2.3.1 snapshot ID bug within weeks. Example:
it('renders dashboard correctly', function () {
    $response = $this->get('/dashboard');
    expect($response->json())->toMatchSnapshot();
});

Pro tip: Use --update-snapshots to refresh expectations after intentional changes."*

For QA/DevOps: *"Snapshot testing reduces our CI noise by catching unintended output changes early. For example, a typo in a Blade template or a misconfigured API response will fail fast. Key advantages:

  • Visual diffs: Integrates with GitHub/GitLab for PR reviews.
  • CI-friendly: Supports --update-snapshots for intentional changes.
  • Reduces flakiness: Catches non-deterministic data (e.g., timestamps) automatically.
  • Works with Laravel Forge/Vapor: No infrastructure changes needed. Ask: Can we enable this for our API and email tests to reduce manual QA effort?"*

For Product Managers: *"This tool helps us ship faster and with fewer bugs by automating tests for dynamic content. Key outcomes:

  • Fewer production incidents from output regressions (e.g., broken emails, misrendered dashboards).
  • Lower QA costs by shifting validation to CI/CD.
  • Better collaboration between devs and designers (snapshots document expected outputs). Ask: Should we prioritize this for our next high-impact feature (e.g., payment flows, marketing site)?"*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony