Skip to content

Configure the snapshot directory #1623

@ghill-fusion

Description

@ghill-fusion

I'm working on a project that's using snapshot tests. For confidentiality reasons, we can't commit the snapshots to the main GitHub repository as the documentation recommends. Instead, we've set up another repo (testdata), hosted on an on-premises server. This repo should include test inputs and CSV-formatted test outputs in addition to the snapshot files themselves. I figured the easiest way to set this up would be to put the _snaps directory inside the local checkout of testdata. But I couldn't see a way to configure the snapshot directory; it seems to be hardcoded to tests/testthat/_snaps (at least in the publicly facing functions; the internals all seem to let you pass in a snapshot directory).

Is a configuration setting to change the snapshot directory something that can be added? Or is there a reasonable workaround for this use case that fits with the spirit of testthat?

Other options I've thought of/tried:

  • Just using tests/testthat/_snaps as the local checkout of testdata. Doesn't work because testthat clears out the snapshot directory after running the tests, obliterating all the test inputs and CSV-formatted outputs.
  • Making tests/testthat the local checkout of testdata. Doesn't work because now the tests themselves get caught up in the testdata repo, and I can't ignore them without also ignoring them in the main repo.
  • Automatically copying the files back and forth. This seems to have timing issues; I can't see how to automatically copy existing snapshots from testdata before they get locked in as the reference snapshots, and copying new snapshots back into testdata should really happen at the same time as snapshot_accept, so we'd have to use our own function instead of snapshot_accept.
  • Replacing _snaps with a symlink to testdata/_snaps. Unfortunately, we're stuck on Windows workstations that require administrator permission to make symlinks. I don't want to add "go find an administrator" as a step in the setup procedure, there are enough barriers to adopting a testing workflow as it is.

In any case, all of these seem unnecessarily convoluted compared to just letting me choose where _snaps goes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions