Skip to content

[Do not merge] Add fallback tests for plots#75

Open
vandenman wants to merge 2 commits intojasp-stats:masterfrom
vandenman:feature/ggplot2_fallback_test
Open

[Do not merge] Add fallback tests for plots#75
vandenman wants to merge 2 commits intojasp-stats:masterfrom
vandenman:feature/ggplot2_fallback_test

Conversation

@vandenman
Copy link
Contributor

Fixes https://github.com/jasp-stats/INTERNAL-jasp/issues/3161

[Do not merge] until we've tried this out in practice for a few modules.

Problem

The current plot tests are too fragile. They often fail due to minor differences between OSes that can be really hard to fix and are also notoriously time-consuming to debug.

Solution in this PR

  1. run the current SVG unit test as usual.
    1a. test passes? pass ✔️
    1b. test fails? go to 2.
  2. Does a reference object exist for this plot type?
    2a. yes? go to 3.
    2b. no? fail ❌
  3. run a reference check on the saved plot object.
    3a. test passes? pass ✔️
    3b. test fails? fail ❌

Some design details:

  • The reference objects are always created.
  • I don't know how big these can get (not yet tested).
  • The mechanism to create the reference objects is S3, see expect_doppelganger_fallback.
    • This means we can add custom support for other plot types in the future (e.g., qgraph, patchwork, etc.).
  • There are (relatively minimal) tests.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a more robust plot-testing strategy to jaspTools by introducing a ggplot2 structural snapshot fallback when the existing vdiffr SVG comparison fails, reducing OS-specific fragility in plot tests.

Changes:

  • Extend expect_equal_plots() to run vdiffr first and (for ggplot objects) fall back to a structural snapshot comparison.
  • Add unit tests and reference .rds snapshots for the fallback mechanism.
  • Minor documentation/example formatting updates in Rd files and roxygen examples.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/testthat/test-expect-equal-plots-fallback.R Adds test coverage for vdiffr-failure fallback behavior, update mode, and snapshot comparison.
tests/testthat/_snaps/expect-equal-plots-fallback/reference_plotobject/new-plot.rds Adds a structural reference snapshot used by the fallback mechanism.
tests/testthat/_snaps/expect-equal-plots-fallback/reference_plotobject/demo-plot.rds Adds a structural reference snapshot used by the fallback mechanism.
R/testthat-helper-plots.R Implements fallback orchestration, ggplot structural snapshot generation/compare, and snapshot path helpers.
NAMESPACE Registers S3 methods for expect_doppelganger_fallback.
DESCRIPTION Adds ggplot2 to Suggests for the structural fallback implementation/tests.
man/testAnalysis.Rd Minor reflow/cleanup of includeAll documentation.
man/expect_equal_tables.Rd Example formatting change (line breaks/indent).
man/analysisOptions.Rd Example formatting change (comment moved to its own line).
R/testthat-helper-tables.R Roxygen example formatting change to match Rd formatting.
R/options.R Roxygen example formatting + whitespace cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants