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

fix: run golden tests with test optimization enabled #388

Merged
merged 7 commits into from Jun 2, 2022

Conversation

Giuspepe
Copy link
Contributor

Description

This fixes #363.

Currently, golden tests fail when running them with very_good test with test optimization enabled. This is because goldenFileComparator 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 file test/a/foo_test.dart uses the relative path goldens/foo.png to refer to the golden image at test/a/goldens/foo.png
  • test file test/b/foo_test.dart uses the same relative path goldens/foo.png to refer to the golden image at test/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

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@felangel felangel assigned felangel and Giuspepe and unassigned felangel May 10, 2022
@felangel felangel added the bug Something isn't working as expected label May 10, 2022
@Giuspepe
Copy link
Contributor Author

@felangel would you mind reviewing this? Thanks!

@wolfenrain
Copy link
Member

Thank you for your contribution!

Our bundles come from an internal brick repository currently, so we normally supply the change there and then do a PR here. But I will merge this as-is so we don't lose your contribution, as soon as the CI succeeds!

Just for your information, I'll supply some extra changes from our internal bricks in a separate PR to keep it up to date with that repo. In case you see another PR today that changes your code ;-), it wont change any of the functionality that your provided.

Once again thanks for this PR!

@felangel felangel merged commit 9bfb159 into VeryGoodOpenSource:main Jun 2, 2022
@felangel felangel mentioned this pull request Jun 6, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: golden tests don't work with test optimisation flag
3 participants