Skip to content

Commit b49dfd0

Browse files
docs(readme): give JSON sidecar schema its own linkable section (#270)
* docs(readme): give JSON sidecar schema its own linkable section Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> * docs(readme): move env vars and JSON schema sections after upload steps Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
1 parent 38ce5db commit b49dfd0

1 file changed

Lines changed: 46 additions & 42 deletions

File tree

README.md

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -77,54 +77,15 @@ xcodebuild test \
7777
-destination 'platform=iOS Simulator,name=iPhone 15 Pro'
7878
```
7979

80-
### Environment variables
81-
82-
SnapshotPreviews supports these test-runner environment variables:
83-
84-
| Variable | Description |
85-
| --- | --- |
86-
| `TEST_RUNNER_SNAPSHOTS_EXPORT_DIR` | Writes rendered snapshot PNGs and JSON sidecars to the given directory instead of attaching PNGs to the `.xcresult` bundle. |
87-
| `TEST_RUNNER_SNAPSHOTS_ALL_IMAGE_NAMES_FILE` | Writes all discovered logical `.png` image names to the given file, then returns without rendering previews. Used to support selective testing workflows. |
88-
89-
These modes are mutually exclusive. If `TEST_RUNNER_SNAPSHOTS_ALL_IMAGE_NAMES_FILE` is set, SnapshotPreviews writes image names only and does not render or export snapshot images.
90-
91-
> [!NOTE]
92-
> The `TEST_RUNNER_` prefix is how Xcode forwards an environment variable from `xcodebuild` into the test runner process. Inside the runner, SnapshotPreviews reads the variable without that prefix.
93-
9480
For every rendered preview, two files are written:
9581

9682
- **`<name>.png`** — the rendered preview image.
97-
- **`<name>.json`** — metadata sidecar used by Sentry Snapshots.
98-
99-
The sidecar includes:
100-
101-
| Field | Description |
102-
| --- | --- |
103-
| `display_name` | Snapshot name shown in Sentry. Generated from the preview name, file path, and module so exported filenames stay stable and unambiguous. |
104-
| `group` | Grouping key Sentry uses to organize related snapshots. Generated from the preview name, file path, and module. |
105-
| `diff_threshold` | Allowed visual difference for this snapshot. See details below. |
106-
| `tags` | Optional key-value pairs used to filter and group snapshots in Sentry. |
107-
| `context` | Supporting metadata such as test name, simulator info, orientation, color scheme, source line, preview attributes, and any custom context you add. These fields are surfaced on the snapshot detail page in Sentry's UI. |
108-
109-
SnapshotPreviews adds these `context` keys by default when values are available: `test_name`, `accessibility_enabled`, `simulator.device_name`, `simulator.model_identifier`, `preview.index`, `preview.display_name`, `preview.container_type_name`, `preview.container_display_name`, `preview.preferred_color_scheme`, `preview.orientation`, and `preview.line`.
110-
111-
Use `.snapshotAdditionalContext(...)` to add custom fields to `context`. Custom context is shallow-merged into the generated context, so a custom key such as `"test_name"` replaces the generated value. Supported custom values are strings, numbers, booleans, and nested objects.
112-
113-
Use the `.snapshotDiffThreshold(...)` view modifier from the `SnapshotPreferences` product to customize the allowed visual difference for a specific preview. For example, `.snapshotDiffThreshold(0.05)` allows up to a 5% difference for that snapshot.
114-
115-
```swift
116-
import SnapshotPreferences
117-
118-
#Preview("Map") {
119-
MapPreview()
120-
.snapshotTags(["screen": "map"])
121-
.snapshotAdditionalContext(["fixture": "city-route"])
122-
.snapshotDiffThreshold(0.05)
123-
}
124-
```
83+
- **`<name>.json`** — metadata sidecar used by Sentry Snapshots. See [JSON sidecar schema](#json-sidecar-schema) for field details.
12584

12685
No Xcode code-coverage data (`.profraw` / `.profdata`) is written by the exporter — only the PNGs and sidecars. If you need code coverage from the same test run, enable it on the scheme as usual; coverage output goes to the `.xcresult` bundle independently.
12786

87+
See [Environment variables](#environment-variables) for all supported test-runner variables.
88+
12889
### 2. Upload to Sentry
12990

13091
Choose one of the upload options below.
@@ -167,6 +128,49 @@ Use Sentry's Fastlane integration if your CI already uploads Apple artifacts thr
167128
168129
See Sentry's [CI integration docs](https://docs.sentry.io/product/snapshots/integrating-into-ci/) for sharding across simulators and base/head SHA pinning.
169130
131+
### Environment variables
132+
133+
SnapshotPreviews supports these test-runner environment variables:
134+
135+
| Variable | Description |
136+
| --- | --- |
137+
| `TEST_RUNNER_SNAPSHOTS_EXPORT_DIR` | Writes rendered snapshot PNGs and JSON sidecars to the given directory instead of attaching PNGs to the `.xcresult` bundle. |
138+
| `TEST_RUNNER_SNAPSHOTS_ALL_IMAGE_NAMES_FILE` | Writes all discovered logical `.png` image names to the given file, then returns without rendering previews. Used to support selective testing workflows. |
139+
140+
These modes are mutually exclusive. If `TEST_RUNNER_SNAPSHOTS_ALL_IMAGE_NAMES_FILE` is set, SnapshotPreviews writes image names only and does not render or export snapshot images.
141+
142+
> [!NOTE]
143+
> The `TEST_RUNNER_` prefix is how Xcode forwards an environment variable from `xcodebuild` into the test runner process. Inside the runner, SnapshotPreviews reads the variable without that prefix.
144+
145+
### JSON sidecar schema
146+
147+
Each `.json` sidecar contains the following fields:
148+
149+
| Field | Description |
150+
| --- | --- |
151+
| `display_name` | Snapshot name shown in Sentry. Generated from the preview name, file path, and module so exported filenames stay stable and unambiguous. |
152+
| `group` | Grouping key Sentry uses to organize related snapshots. Generated from the preview name, file path, and module. |
153+
| `diff_threshold` | Allowed visual difference for this snapshot. See details below. |
154+
| `tags` | Optional key-value pairs used to filter and group snapshots in Sentry. |
155+
| `context` | Supporting metadata such as test name, simulator info, orientation, color scheme, source line, preview attributes, and any custom context you add. These fields are surfaced on the snapshot detail page in Sentry's UI. |
156+
157+
SnapshotPreviews adds these `context` keys by default when values are available: `test_name`, `accessibility_enabled`, `simulator.device_name`, `simulator.model_identifier`, `preview.index`, `preview.display_name`, `preview.container_type_name`, `preview.container_display_name`, `preview.preferred_color_scheme`, `preview.orientation`, and `preview.line`.
158+
159+
Use `.snapshotAdditionalContext(...)` to add custom fields to `context`. Custom context is shallow-merged into the generated context, so a custom key such as `"test_name"` replaces the generated value. Supported custom values are strings, numbers, booleans, and nested objects.
160+
161+
Use the `.snapshotDiffThreshold(...)` view modifier from the `SnapshotPreferences` product to customize the allowed visual difference for a specific preview. For example, `.snapshotDiffThreshold(0.05)` allows up to a 5% difference for that snapshot.
162+
163+
```swift
164+
import SnapshotPreferences
165+
166+
#Preview("Map") {
167+
MapPreview()
168+
.snapshotTags(["screen": "map"])
169+
.snapshotAdditionalContext(["fixture": "city-route"])
170+
.snapshotDiffThreshold(0.05)
171+
}
172+
```
173+
170174
## Tips
171175

172176
### Unique display names

0 commit comments

Comments
 (0)