Skip to content

Commit

Permalink
Clear dir and support filters (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin authored Aug 5, 2023
1 parent 3c25033 commit 729003d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 1 addition & 4 deletions Sources/SnapshottingSwift/Initializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ private class CompletedViewController: UIViewController {
label.numberOfLines = 0
label.accessibilityIdentifier = "emg_finished_label"

let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
if let documentsDirectory = paths.first {
label.text = "\(documentsDirectory)"
}
label.text = "\(Snapshots.resultsDir.path())"

view.addSubview(label)

Expand Down
8 changes: 7 additions & 1 deletion Sources/SnapshottingSwift/Snapshots.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ class Snapshots {

var completion: (() -> Void)?

static let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
static let resultsDir = documentsURL.appendingPathComponent("EMGSnapshots")

func saveSnapshots(completion: @escaping () -> Void) {
try? FileManager.default.removeItem(at: Self.resultsDir)
try! FileManager.default.createDirectory(at: Self.resultsDir, withIntermediateDirectories: true)

self.completion = completion
let snapshotPreviews = ProcessInfo.processInfo.environment["SNAPSHOT_PREVIEWS"];
var previewsSet: Set<String>? = nil
Expand Down Expand Up @@ -60,7 +66,7 @@ class Snapshots {
view = AnyView(view.colorScheme(colorScheme))
}
let fileName = "\(typeName)-\(preview.previewId).png"
let file = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appending(path: fileName, directoryHint: .notDirectory)
let file = Self.resultsDir.appending(path: fileName, directoryHint: .notDirectory)
print(file)
view.snapshot(layout: preview.layout, window: window, async: false) { image in
if let pngData = image.pngData() {
Expand Down
5 changes: 3 additions & 2 deletions Sources/SnapshottingTests/PreviewTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ - (void)generateSnapshots {
} mutableCopy];
NSArray *previews = [self snapshotPreviews];
if (previews) {
launchEnvironment[@"SNAPSHOT_PREVIEWS"] = previews;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:previews options:nil error:nil];
launchEnvironment[@"SNAPSHOT_PREVIEWS"] = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
app.launchEnvironment = launchEnvironment;
[app launch];
Expand All @@ -82,7 +83,7 @@ - (void)generateSnapshots {

resultPath = label.label;

NSLog(@"Images can be found in %@", path);
NSLog(@"Images can be found in %@", resultPath);

NSError *error = nil;
NSArray<NSString *> *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resultPath error:&error];
Expand Down

0 comments on commit 729003d

Please sign in to comment.