avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

More control over snapshot file locations at runtime #1587

Closed Droogans closed 4 years ago

Droogans commented 6 years ago

Description

I would like to be able to control where my snapshots end up during run time.

Here, I have a for loop that iterates over some items of interest at runtime, and generates DOM snapshots based on what it finds.

However, this creates one giant file and personally I'd rather be able to pass in the desired file name for each individual call of t.snapshot in my project.

(On a side-note, if anyone here is able to figure out why my project's snapshotLocation isn't being honored, I'd be grateful. So far I've had no luck creating any solid reproduction case other than pointing to the entire project linked above)

novemberborn commented 6 years ago

I would like to be able to control where my snapshots end up during run time.

Here, I have a for loop that iterates over some items of interest at runtime, and generates DOM snapshots based on what it finds.

However, this creates one giant file and personally I'd rather be able to pass in the desired file name for each individual call of t.snapshot in my project.

I considered this. It's tricky though since it means multiple test files could be using the same snapshot file. Since we run test files concurrently this makes it hard to reliably update the snapshot file.

I'm open to this if we can figure out graceful solutions to those race conditions.

(On a side-note, if anyone here is able to figure out why my project's snapshotLocation isn't being honored, I'd be grateful. So far I've had no luck creating any solid reproduction case other than pointing to the entire project linked above)

It's because the documentation was wrong, Use snapshotDir instead, see https://github.com/avajs/ava/pull/1581.

Droogans commented 6 years ago

If ava keeps a cache, would it be possible to write to it and flag warnings/fail tests if a user attempts to write to the same file location twice?

novemberborn commented 6 years ago

We'd need to transmit the snapshot data to the main process and only write the file once all tests have run. But what happens if you run AVA with specific test files and update snapshots, thus removing the snapshots created by a different file?

Similarly there'd be collisions if tests in both files have the same title. All this gets pretty complicated!