From d0e145794067763fb957ec85bb21e6496426622b Mon Sep 17 00:00:00 2001 From: Itay Brenner Date: Wed, 20 Nov 2024 17:51:22 -0300 Subject: [PATCH] Update readme (#209) * Update readme * Update readme and script to upload PreviewGallery --- .github/workflows/release.yaml | 5 ++++- Package.swift | 1 + README.md | 18 ++++++++++-------- build.sh | 8 ++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 04567fe..0549022 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,8 +16,10 @@ jobs: run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer' - name: Build xcframework run: sh build.sh - - name: Zip xcframework + - name: Zip SnapshottingTests xcframework run: zip -r SnapshottingTests.xcframework.zip SnapshottingTests.xcframework + - name: Zip PreviewGallery xcframework + run: zip -r PreviewGallery.xcframework.zip PreviewGallery.xcframework - name: Zip preivews support run: (cd PreviewsSupport && zip -r PreviewsSupport.xcframework.zip PreviewsSupport.xcframework) - name: Upload Artifact @@ -25,6 +27,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') with: files: | + PreviewGallery.xcframework.zip SnapshottingTests.xcframework.zip PreviewsSupport/PreviewsSupport.xcframework.zip body: diff --git a/Package.swift b/Package.swift index a0509b2..26f5cbb 100644 --- a/Package.swift +++ b/Package.swift @@ -10,6 +10,7 @@ let package = Package( // Products define the executables and libraries a package produces, making them visible to other packages. .library( name: "PreviewGallery", + type: .static, // Replace this to build dynamic targets: ["PreviewGallery"]), // Test library to import in your XCTest target. // This is the only library that depends on XCTest.framework diff --git a/README.md b/README.md index 03b6905..22b094e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # 📸 SnapshotPreviews -[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FEmergeTools%2FSnapshotPreviews-iOS%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/EmergeTools/SnapshotPreviews-iOS) -[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FEmergeTools%2FSnapshotPreviews-iOS%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/EmergeTools/SnapshotPreviews-iOS) +[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FEmergeTools%2FSnapshotPreviews%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/EmergeTools/SnapshotPreviews) +[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FEmergeTools%2FSnapshotPreviews%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/EmergeTools/SnapshotPreviews) +[![](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fwww.emergetools.com%2Fapi%2Fv2%2Fpublic_new_build%3FexampleId%3Dsnapshotpreviews-ios.PreviewGallery%26platform%3Dios%26badgeOption%3Dversion_and_max_install_size%26buildType%3Drelease&query=$.badgeMetadata&label=PreviewGallery&logo=apple)](https://www.emergetools.com/app/example/ios/snapshotpreviews-ios.PreviewGallery/release?utm_campaign=badge-data) +[![](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fwww.emergetools.com%2Fapi%2Fv2%2Fpublic_new_build%3FexampleId%3Dsnapshotpreviews-ios.SnapshottingTests%26platform%3Dios%26badgeOption%3Dversion_and_max_install_size%26buildType%3Drelease&query=$.badgeMetadata&label=SnapshottingTests&logo=apple)](https://www.emergetools.com/app/example/ios/snapshotpreviews-ios.SnapshottingTests/release?utm_campaign=badge-data) An all-in-one snapshot testing solution built on Xcode previews. Automatic browsable gallery of previews, and no-code snapshot generation with XCTest. Supports SwiftUI and UIKit previews using `PreviewProvider` or `#Preview` and works on all Apple platforms (iOS/macOS/watchOS/tvOS/visionOS). @@ -16,7 +18,7 @@ An all-in-one snapshot testing solution built on Xcode previews. Automatic brows `PreviewGallery` is an interactive UI built on top of snapshot extraction. It turns your Xcode previews into a gallery of components and features you can access from your application, for example in an internal settings screen. **Xcode is not required to view the previews.** You can use it to preview individual components (buttons/rows/icons/etc) or even entire interactive features.

- +

The public API of PreviewGallery is a single SwiftUI `View` named `PreviewGallery`. Displaying this view gives you access to the full gallery. For example, you could add a button to open the gallery like this: @@ -65,7 +67,7 @@ Note that there are no test functions; they are automatically added at runtime b > [!NOTE] > When you use Preview macros (`#Preview("Display Name")`) the name of the snapshot uses the file path and the name, for example: "MyModule/MyFile.swift:Display Name" -![Screenshot of Xcode test output](https://raw.githubusercontent.com/EmergeTools/SnapshotPreviews-iOS/master/images/testOutput.png) +![Screenshot of Xcode test output](https://raw.githubusercontent.com/EmergeTools/SnapshotPreviews/master/images/testOutput.png) The [EmergeTools snapshot testing service](https://docs.emergetools.com/docs/snapshot-testing) generates snapshots and diffs them in the cloud to control for sources of flakiness, store images outside of git, and optimize test performance. `SnapshotTest` is for locally debugging these snapshot tests. You can also use `PreviewTest` to get code coverage of all previews in your unit test without generating PNGs. This will validate that previews do not crash (such as a missing @EnvironmentObject) but runs faster because it does not render the views to images. @@ -101,10 +103,10 @@ See the demo app for a full example. # Installation -Add the package dependency to your Xcode project using the URL of this repository (https://github.com/EmergeTools/SnapshotPreviews-iOS). +Add the package dependency to your Xcode project using the URL of this repository (https://github.com/EmergeTools/SnapshotPreviews).

- +

Link your app to `PreviewGallery` and (optionally) to `SnapshotPreferences` to customize the behavior of snapshot generation. @@ -150,7 +152,7 @@ Check `ProcessInfo.isRunningPeviews` to disable behavior you don’t want in pre > [!TIP] > Using PreviewVariants greatly simplifies snapshot testing, by ensuring a consistent set of variants and that every view is provided a name. -Using multiple variants of the same view can ensure test coverage of all the ways users interact with your UI. Most are provided by SwiftUI, eg: `.dynamicTypeSize(.xxxLarge)`. There is one built into the package: `.emergeAccessibility(true)`. This function adds a visualization of voice over elements to your snapshot. You can automatically add variants using the [`PreviewVariants` View](https://github.com/EmergeTools/SnapshotPreviews-iOS/blob/main/DemoApp/DemoApp/TestViews/PreviewVariants.swift) that is demonstrated in the example app. It adds RTL, landscape, accessibility, dark mode and large text variants. You can use it like this: +Using multiple variants of the same view can ensure test coverage of all the ways users interact with your UI. Most are provided by SwiftUI, eg: `.dynamicTypeSize(.xxxLarge)`. There is one built into the package: `.emergeAccessibility(true)`. This function adds a visualization of voice over elements to your snapshot. You can automatically add variants using the [`PreviewVariants` View](https://github.com/EmergeTools/SnapshotPreviews/blob/main/DemoApp/DemoApp/TestViews/PreviewVariants.swift) that is demonstrated in the example app. It adds RTL, landscape, accessibility, dark mode and large text variants. You can use it like this: ```swift struct MyView_Previews: PreviewProvider { @@ -172,7 +174,7 @@ struct MyView_Previews: PreviewProvider { # Star History -[![Star History Chart](https://api.star-history.com/svg?repos=EmergeTools/SnapshotPreviews-iOS&type=Date)](https://star-history.com/#EmergeTools/SnapshotPreviews-iOS&Date) +[![Star History Chart](https://api.star-history.com/svg?repos=EmergeTools/SnapshotPreviews&type=Date)](https://star-history.com/#EmergeTools/SnapshotPreviews&Date) # Related Reading - [How to use VariadicView, SwiftUI's Private View API](https://www.emergetools.com/blog/posts/how-to-use-variadic-view): VariadicView is a core part of how multiple images are rendered for one PreviewProvider. diff --git a/build.sh b/build.sh index b4adb90..a657ac8 100755 --- a/build.sh +++ b/build.sh @@ -45,10 +45,18 @@ build_framework() { # Update the Package.swift to build the library as dynamic instead of static sed -i '' '/Replace this/ s/.*/type: .dynamic,/' Package.swift +# Build SnapshottingTests build_framework "iphonesimulator" "generic/platform=iOS Simulator" "SnapshottingTests" build_framework "iphoneos" "generic/platform=iOS" "SnapshottingTests" +# Build PreviewGallery +build_framework "iphonesimulator" "generic/platform=iOS Simulator" "PreviewGallery" +build_framework "iphoneos" "generic/platform=iOS" "PreviewGallery" + echo "Builds completed successfully." rm -rf "SnapshottingTests.xcframework" xcodebuild -create-xcframework -framework SnapshottingTests-iphonesimulator.xcarchive/Products/Library/Frameworks/SnapshottingTests.framework -framework SnapshottingTests-iphoneos.xcarchive/Products/Library/Frameworks/SnapshottingTests.framework -output SnapshottingTests.xcframework + +rm -rf "PreviewGallery.xcframework" +xcodebuild -create-xcframework -framework PreviewGallery-iphonesimulator.xcarchive/Products/Library/Frameworks/PreviewGallery.framework -framework PreviewGallery-iphoneos.xcarchive/Products/Library/Frameworks/PreviewGallery.framework -output PreviewGallery.xcframework \ No newline at end of file