fix(macos): avoid health polling in tests
parent
dbd3865e3b
commit
3b35b762cb
|
|
@ -67,7 +67,10 @@ final class HealthStore: ObservableObject {
|
||||||
private let refreshInterval: TimeInterval = 60
|
private let refreshInterval: TimeInterval = 60
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
self.start()
|
// Avoid background health polling in SwiftUI previews and tests.
|
||||||
|
if !ProcessInfo.processInfo.isPreview, !ProcessInfo.processInfo.isRunningTests {
|
||||||
|
self.start()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func start() {
|
func start() {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,15 @@ extension ProcessInfo {
|
||||||
var isPreview: Bool {
|
var isPreview: Bool {
|
||||||
self.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
|
self.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isRunningTests: Bool {
|
||||||
|
// SwiftPM test bundles are typically loaded from a `.xctest` bundle.
|
||||||
|
// We also check common XCTest env vars because some runners still set them.
|
||||||
|
if Bundle.main.bundleURL.pathExtension == "xctest" { return true }
|
||||||
|
return self.environment["XCTestConfigurationFilePath"] != nil
|
||||||
|
|| self.environment["XCTestBundlePath"] != nil
|
||||||
|
|| self.environment["XCTestSessionIdentifier"] != nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum LaunchdManager {
|
enum LaunchdManager {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue