You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
-
94
80
For every rendered preview, two files are written:
95
81
96
82
-**`<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.
-**`<name>.json`** — metadata sidecar used by Sentry Snapshots. See [JSON sidecar schema](#json-sidecar-schema) for field details.
125
84
126
85
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.
127
86
87
+
See [Environment variables](#environment-variables) for all supported test-runner variables.
88
+
128
89
### 2. Upload to Sentry
129
90
130
91
Choose one of the upload options below.
@@ -167,6 +128,49 @@ Use Sentry's Fastlane integration if your CI already uploads Apple artifacts thr
167
128
168
129
See Sentry's [CI integration docs](https://docs.sentry.io/product/snapshots/integrating-into-ci/) for sharding across simulators and base/head SHA pinning.
169
130
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.
0 commit comments