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

Update #Preview macro generated test to use snapshotDevices. #73

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

markst
Copy link
Contributor

@markst markst commented Sep 3, 2024

Short description 📝

When using #Preview macro to generate snapshot tests in combination with test configuration with multiple snapshot_devices:

test_configuration:
  - target: ShowPage
  - simulator_device: "iPhone15,4"
  - required_os: 17
  - snapshot_devices:
      - iPhone 15
      - iPad
  - imports:
      - UIKit
      - Foundation

The appropriate snapshot function is not called.

Resolution

Updates the PreviewLoader extension to ensure compatibility with a template-generated function that loops through different devices for snapshot testing.

} else {
// Ensure we call on the test looping devices:
assertionStatement = """
assertSnapshots(matching: preview(), testName: "\(rawPreviewModel.displayName)")
Copy link
Contributor Author

@markst markst Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function defines as:

private func assertSnapshots(matching preview: _Preview, testName: String = #function) {

https://github.com/BarredEwe/Prefire/blob/main/Templates/PreviewTests.stencil#L60

@BarredEwe
Copy link
Owner

Hi, thanks for the fix and finding the problem)

To try this fix call the make binary command in the root of Prefire. And for the release of this version you need to call make update version=2.9.0 as well.

@markst
Copy link
Contributor Author

markst commented Sep 5, 2024

had to install 5.8.0 swift tools version:

swiftenv local 5.8.0

@markst markst marked this pull request as ready for review September 5, 2024 07:30
@markst markst marked this pull request as draft September 5, 2024 08:39
@markst
Copy link
Contributor Author

markst commented Sep 5, 2024

Think it's more complicated than this change.

Seems we may need to update the assertSnapshots to take a SwiftUI.View rather than _PreviewL

Cannot convert value of type '() -> some View' to expected argument type '_Preview'

@markst
Copy link
Contributor Author

markst commented Sep 10, 2024

Maybe we need to create a model in order to pass the the assertSnapshots rather than _Preview.
Then we can transpose the PreviewProvider _Preview and the pass the extracted #Preview macro data.

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