Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would I go about saving a snapshot of a directory? #923

Open
jcbhmr opened this issue Nov 22, 2024 · 1 comment
Open

How would I go about saving a snapshot of a directory? #923

jcbhmr opened this issue Nov 22, 2024 · 1 comment
Labels

Comments

@jcbhmr
Copy link

jcbhmr commented Nov 22, 2024

What's your question?

I am testing a CLI application that operates on files. I am using pytest and pytest-datadir like this:

tests/test_entire_app.py
import subprocess
def test_scenario_one(datadir, snapshot):
    d = datadir / "test_scenario_one"
    p = subprocess.run(["myapp", d], capture_output=True, text=True)
    assert <somehow_load_directory_to_compare(d)> == snapshot # somehow snapshot should save that directory

What I'm doing right now is manually with open(f): data1 = f.read() for each expected output test file. Then all those go in a dict object { "app.ts": appts, "app.js": appjs, ... } which gets mashed into a huge .ambr file. I'd prefer a regular real directory structure if possible.

I want it to result in something like this:

.
└── tests/
    ├── __snapshots__/
    │   └── test_entire_app/
    │       └── test_scenario_one/
    │           ├── app.ts
    │           ├── app.js
    │           ├── utils.ts
    │           └── utils.js
    ├── test_entire_app/
    │   └── test_scenario_one/
    │       ├── app.ts
    │       └── utils.ts
    └── test_entire_app.py

...but I'm not familiar with how to go about actually doing that. I would appreciate some guidance about how to do this. I see that there's some examples of how to use the syrupy.extensions.single_file which seems cool, but I don't know how to go about making an extension that creates a directory with multiple files.

@noahnu
Copy link
Collaborator

noahnu commented Nov 30, 2024

The "detect unused snapshot" files logic assumes a snapshot lives in one file I believe, but everything else should be possible at least with a custom extension.

I can take a look in a couple days and see if I can put together an example for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants