-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Insta 2.0 ideas? #456
Comments
This is purely internal, but along with updating the snapshot formats, if we could unify how inline & file snapshots are redacted, that makes some code simpler. Lines 228 to 229 in 2959d79
The difference would be we don't have diff --git a/tests/test_settings.rs b/tests/test_settings.rs
index db67e1d..da0c6ce 100644
--- a/tests/test_settings.rs
+++ b/tests/test_settings.rs
@@ -17,7 +17,6 @@ fn test_simple() {
settings.set_sort_maps(true);
settings.bind(|| {
assert_yaml_snapshot!(&map, @r###"
- ---
a: first value
b: second value
c: third value
@@ -40,7 +39,6 @@ fn test_bound_to_scope() {
settings.set_sort_maps(true);
let _guard = settings.bind_to_scope();
assert_yaml_snapshot!(&map, @r###"
- ---
a: first value
b: second value
c: third value
@@ -62,7 +60,6 @@ fn test_settings_macro() {
with_settings!({sort_maps => true}, {
insta::assert_yaml_snapshot!(&map, @r###"
- ---
a: first value
b: second value
c: third value |
This is the code for mitsuhiko#456 (comment), as mentioned in mitsuhiko#466. There's a very small change in yaml inline snapshots — shown here in the tests. In return, it makes the macros simpler & more maintainable.
I have been thinking about this a bit more and if we do a major move to a new version it might be a good idea to address some of the larger challenges of the library. For me the biggest is that the patching of inline snapshots is unreasonably complex and thus delegated to the There is also sometimes the desire to work with snapshot files directly. For example #475 wants to place a snapshot external to the metadata, to track schema changes. One way to go about it would be to move the actual management of the snapshot into a separate macro than the assertion. Inline snapshots: // old
assert_snapshot!("the value", @"the value");
// new
assert_snapshot!("the value", snap!("the value")); Named snapshots: // old
assert_snapshot!("name", "the value");
// new
assert_snapshot!("the value", snap!(named="name")); Implicitly named: assert_snapshot!("the value", snap!(named)); The benefit of this is that the macro ( This would also allow additional functionality to be placed on the snapshot for placing it somewhere. Hypothetically for binaries: assert_snapshot!(binary_stuff, snap!(binary, ext=".png", named="my-picture")); Or to interact with the snapshot directly: let snap = snap!("the-value");
assert_eq!(snap.text(), "the-value"); Another unrelated thing I wish could be cleaned up are the settings. I think they are just bad today. fn assert_foo() {
// s is a scope guard that drops. Until then the settings are reconfigured for this
// function
let mut s = insta::reconfigure();
s.add_filter(r"\d{4}-\d{2}-\d{2}", "[DATE"]);
assert_snapshot!("Today is 2024-05-15", snap!("Today is [DATE]"));
} |
I will think more but some initial thoughts: Can we replace inline snapshot values without I agree the settings seem too complicated. They're split between the But One option would be to move everything to the new snap!("the-value").assert_debug_matches("the_value"); let s = snap!(name=foo);
s.with_redactions(...).with_snapshot_suffix(...).assert_yaml_matches(...); FWIW I would find this confusing, where
An alternative could be One final comment — occasionally these big rewrites can be so big that they never happen, and it prevents a smaller release that would get done. You're obv the main author and the main bottleneck, so depends on your capacity. If you think we can't get something so ambitious done, possibly we could do a less ambitious change. But great if you think we can, am happy to contribute. |
Yes, but not without pulling in the rather complex syn based parsing logic which is a huge dependency. The benefit of a
I was thinking about this, but it turns the assertions into "reference value first", assertion later which in case of long macros makes them hard to understand. Potentially this would make more sense? debug!(value).matches(snap!(...)); But that's even more unwieldy. I need to think about this more, but I'm at least at the moment heavily leaning towards playing around if
I'm not too worried about that. |
OK — I know you value limiting dependencies a lot. Would putting it behind a feature help allay the concern? Or it's too crucial a feature to relegate to optional? |
I don't know. If the argument for |
Would be great to keep as much consistency as possible. But is there anything we want to change while we can?
A few ideas:
(value)
&(name, value)
&(name, value, debug_expr)
(+ redaction filters, inline, etc), which is arguably OK for experienced users, but less immediately obvious for new folks reading code.debug_expr
intowith_settings
.match ..
in redactions? This allowsrustfmt
to work. Plausibly it also delineates the redaction expression for easier reading.rustfmt
, but don't think there's a way — if the inline snapshot is a normal expression without special syntax (such as@
), it's not possible to discriminate between(name, value)
and(value, snapshot)
The text was updated successfully, but these errors were encountered: