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

[BUG] ShouldUpdateSnapshot does not respect SnapshotSettings #104

Closed
ptjhuang opened this issue Dec 12, 2023 · 1 comment
Closed

[BUG] ShouldUpdateSnapshot does not respect SnapshotSettings #104

ptjhuang opened this issue Dec 12, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ptjhuang
Copy link
Contributor

ptjhuang commented Dec 12, 2023

Describe the bug
When using ShouldMatchSnapshot passing in a SnapshotSetting in cases when the stack trace cannot be used to detect the test name, the SupportedTestMethodNotFoundException gets thrown.

To Reproduce

Snapper.dll!Snapper.Core.TestMethodResolver.TestMethodResolver.ResolveTestMethod() Line 55	C#
Snapper.dll!Snapper.Core.SnapshotUpdateDecider.ShouldUpdateSnapshotBasedOnAttribute() Line 46	C#
Snapper.dll!Snapper.Core.SnapshotUpdateDecider.ShouldUpdateSnapshot() Line 30	C#
Snapper.dll!Snapper.Core.SnapperCore.ShouldUpdateSnapshot(Snapper.Json.JsonSnapshot existingSnapshot, Snapper.Json.JsonSnapshot newSnapshot) Line 40	C#
Snapper.dll!Snapper.Core.SnapperCore.Snap(Snapper.Json.JsonSnapshot newSnapshot) Line 20	C#
Snapper.dll!Snapper.Snapper.MatchSnapshot(object rawSnapshot, string childSnapshotName) Line 21	C#
Snapper.dll!Snapper.SnapperExtensions.ShouldMatchChildSnapshot(object snapshot, string childSnapshotName, Snapper.SnapshotSettings snapshotSettings) Line 22	C#

Correction I can't work-around this using environment variable, because the logic checks if either attribute or environment variable specifies to update snapshot.

I suggest changing the ShouldUpdateSnapshot() logic to respect the environment variable if it is not null, and short-circuit the decision. i.e. if environment is not set, the check the attribute. If it is explicitly set to false, don't update the snapshots.

Is it worth considering accepting a MethodInfo property in SnapshotSetting of the property?

Additional context
Snapper Version: 2.4.0
Operation System: Windows 11
.Net Version: .net core 7

@ptjhuang ptjhuang added the bug Something isn't working label Dec 12, 2023
ptjhuang added a commit to ptjhuang/Snapper that referenced this issue Dec 21, 2023
ptjhuang added a commit to ptjhuang/Snapper that referenced this issue Dec 21, 2023
@theramis
Copy link
Owner

Fixed in v2.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants