fix: run golden tests with test optimization enabled #388
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This fixes #363.
Currently, golden tests fail when running them with
very_good test
with test optimization enabled. This is becausegoldenFileComparator
searches for the golden files relative from the currently running test file. With optimization enabled, the golden files are searched from the.test_runner.dart
file instead of from the original test files.The solution I suggest is to use a custom implementation for
goldenFileComparator
which knows about the implications of the test optimization. It finds the correct absolute path of the golden file by searching for a single file ending with the given relative path from the test base directory. For further details, see my comment here: #363 (comment)This approach fails in the following situation:
test/a/foo_test.dart
uses the relative pathgoldens/foo.png
to refer to the golden image attest/a/goldens/foo.png
test/b/foo_test.dart
uses the same relative pathgoldens/foo.png
to refer to the golden image attest/b/goldens/foo.png
In that case, searching for files ending with the path
goldens/foo.png
does not return a single result but two possible results. An exception will be thrown in that case. I think this is ok because it is a rather theoretical edge case and this approach solves all realistic cases.Type of Change