Skip to content

Issue with Snapshot.parse regex - ERROR: Found orphan snapshots#177

Merged
jackmatt2 merged 5 commits into
codedabble-dev:masterfrom
rogervinas:snapshot-regex-fix
Dec 16, 2024
Merged

Issue with Snapshot.parse regex - ERROR: Found orphan snapshots#177
jackmatt2 merged 5 commits into
codedabble-dev:masterfrom
rogervinas:snapshot-regex-fix

Conversation

@rogervinas

@rogervinas rogervinas commented Nov 29, 2024

Copy link
Copy Markdown
Contributor

Having a snapshot with a scenario and a body that contains something similar to [xxx]=yyy makes the Snapshot.parse regex fail, resulting in tests failing due to ERROR: Found orphan snapshots

Issue #178

Test shouldParseSnapshotWithScenarioAndBodyWithSomethingSimilarToAnScenarioToConfuseRegex will fail, one possible solution is to change the regex in Snapshot.parse:

from:

String regex = "^(?<name>.*?)(\\[(?<scenario>.*)\\])?=(?<header>\\{.*?\\})?(?<snapshot>(.*)$)";

to:

String regex = "^(?<name>.*?)(\\[(?<scenario>[^]]*)])?=(?<header>\\{[^}]*?})?(?<snapshot>(.*)$)";

See commit Improve regex and note the [^]]* in scenario group and [^}]* in header group, instead of just .*

@jackmatt2

Copy link
Copy Markdown
Collaborator

Can you run the following command and then push the files again?

./gradlew :java-snapshot-testing-core:spotlessApply

@rogervinas

Copy link
Copy Markdown
Contributor Author

@jackmatt2 done!

@jackmatt2

Copy link
Copy Markdown
Collaborator

Thanks, I actually want to encode the body of the snapshot ... eventually which would make this PR unnecessary. However as a stopgap this is fine.

@jackmatt2 jackmatt2 merged commit 2e2087b into codedabble-dev:master Dec 16, 2024
@rogervinas rogervinas deleted the snapshot-regex-fix branch December 20, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants