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

  • Standardize testing for dynamic outputs (APIs, emails, Blade templates) by replacing ad-hoc assertions with deterministic snapshot validation, reducing test maintenance costs by 30–50%.
  • Accelerate Laravel/Pest adoption as the primary testing framework by providing native snapshot support, eliminating the need for PHPUnit-specific tools and reducing tooling fragmentation.
  • Enable "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.
  • 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 "test-driven" development for complex systems (e.g., GraphQL schemas, dynamic reports) where manual assertions are impractical due to output complexity.
  • Unify frontend/backend testing by enabling shared snapshot validation for Livewire/Inertia components, HTML emails, and API responses, breaking silos between teams.
  • Improve onboarding for new hires by replacing undocumented assertions with self-documenting snapshots, reducing knowledge transfer friction by 50%.
  • Enable "canary" testing for critical paths (e.g., payment flows, user dashboards) by validating rendered outputs against snapshots, catching misconfigurations early.

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 features faster by automating regression testing for dynamic outputs. For example:

  • API changes: Validate responses without manual assertions.
  • Marketing pages: Catch broken HTML/JS after design updates.
  • Reports: Ensure CSV/PDF exports match expectations. Impact: Fewer production bugs, less QA overhead, and higher confidence in releases. Ask: Which outputs should we prioritize for snapshot testing?"*
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai