Skip to content

Instantly share code, notes, and snippets.

@DavidBrunow
DavidBrunow / ci_pre_xcodebuild.sh
Created November 30, 2023 13:05
ci_pre_xcodebuild.sh
#!/bin/sh
if [[ $CI_XCODEBUILD_ACTION == "test-without-building" ]]
then
# Setup the simulators so that they only have one preferred language.
# This works around an issue where the simulators on Sonoma have multiple
# preferred languages which include Arabic and therefore provide different
# results when running snapshot tests.
#
# This solution was inspired by: https://stackoverflow.com/a/74335552
import ComposableArchitecture
import SwiftUI
public struct FlowRunner {
public static func run<State: Equatable, Action: Equatable>(
type: String,
store: Store<State, Action>,
initialView: some View,
initializationAction: FlowRunner.NamedAction<Action>,
actions: [FlowRunner.NamedAction<Action>],
@DavidBrunow
DavidBrunow / UIDevice+ModelName.swift
Last active October 25, 2023 00:40
`UIDevice` helper to know which simulator a test is being run on.
import UIKit
/// https://stackoverflow.com/a/26962452
extension UIDevice {
static let modelName: String = {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
@DavidBrunow
DavidBrunow / XCTest+AssertStandardSnapshots.swift
Last active December 2, 2023 21:28
Helper Code for Snapshot Testing
import AccessibilitySnapshot
import SnapshotTesting
import SwiftUI
import XCTest
extension Snapshotting where Value == UIViewController, Format == UIImage {
fileprivate static func standardImage(
on viewImageConfig: ViewImageConfig,
perceptualPrecision: Float = 0.98,
precision: Float = 0.995
@DavidBrunow
DavidBrunow / SnapshotTesting+ImpreciseAccessibility.swift
Last active October 25, 2023 00:41
Shim to use `precision` and `perceptualPrecision` with Accessibility Snapshot testing
//
// Copyright 2023 Block Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software