swift-snapshot-testing: File Save Permissions Error
Hi đ
First off just wanted to say thanks for the project, itâs been a breeze to setup and super refreshing! â Good work!
My question is currently whether or not this library is suppose to support physical devices or if the intended use is limited to Simulators?
When running on a physical device I get the below error when fileManager.createDirectory is called. The same is not true when ran from a simulator (which works as expected, without errors).
Error Domain=NSCocoaErrorDomain Code=513 "You donât have permission to save the file âCaseNameTestsâ in the folder â__Snapshots__â." UserInfo={NSFilePath=/Users/name/path/to/repo/ModuleTests/__Snapshots__/CaseNameTests, NSUnderlyingError=0x1c28585d0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
This appears to be the same issue referenced here
Thanks in advance đ
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 20 (6 by maintainers)
Commits related to this issue
- Removes sandboxing on macOS test app Required to save snapshot screenshots in the project directory. See: https://github.com/pointfreeco/swift-snapshot-testing/issues/193 — committed to kyle-n/HighlightedTextEditor by kyle-n 6 years ago
- replaces snapshotDirectory to be URL? instead of String? as suggested in https://github.com/pointfreeco/swift-snapshot-testing/issues/193 — committed to AndreyAnt/swift-snapshot-testing by deleted user 2 years ago
I am having same issue as others described for iOS device. I wanted to check real device, because for some reason code coverage is not gathered on simulator. It is gathered just fine for physical device, but I am getting
failed - You donât have permission to save the file âCalendarLargeWidgetViewSnapshotTestsâ in the folder â__Snapshots__â.failure in tests đHi @BenoitCaron and @fabstu , I ran into the same issue on macOS. What solved it for me was to convert the URL to string with
.path()instead of..absoluteString()in my custommyAssertSnapshot, like soI fixed this by selecting
Expand Variables Based Onand selecting the based Target. It fixed for me.Hi @stephencelis,
I tried writing my own
assertSnapshotin order to change the output directory, and my error is similar, but not exactly the same:failed - You canât save the file âMyTestsâ because the volume is read only.I tried replicating the default behaviour, but the error still occurs.
This is the default code, in
AssertSnapshot.swift:It seems
snapshotDirectory.map { URL(fileURLWithPath: $0, isDirectory: true) }andfileUrl.deletingLastPathComponent().appendingPathComponent("__Snapshots__").appendingPathComponent(fileName)donât output the exact same thing:snapshotDirectory.map { URL(fileURLWithPath: $0, isDirectory: true) }outputsfile:/Users/benoit/myApp/myApp-iOSTests/__Snapshots__/MyTests/ -- file:///fileUrl.deletingLastPathComponent().appendingPathComponent("__Snapshots__").appendingPathComponent(fileName)outputsfile:///Users/benoit/myApp/myApp-iOSTests/__Snapshots__/MyTests/Why is there a difference? Am I missing something?
Edit: I forked the library and replaced the
String? snapshotDirectoryparameter with aURL? snapshotDirectoryparameter, and it does work as intended. Should I create a PR?No problem! More than happy to try and explain our use case a bit more,
Internally we have a CI platform that supports a large number of physical devices ranging from phones through tablets of varying sizes and configurations. We take advantage of Hive CI to run our integration tests on and were hoping to also take advantage of it for our snapshot tests too.
In general this comes down to a bit of reassurance from our testing department as we have seen various little differences in the past when it comes to Simulator vs Physical Device and was hoping to do the comparison on the closest thing to real world as possible
Hope that makes sense?
I wanted to share how I worked around this issue for myself. I donât run tests against a real host app, so removing the sandboxing isnât an option (and I wouldnât really want this anyways).
Instead, I wrote a custom version of
assertSnapshot(as recommended above). To access files, my version reads from the targetâs resource bundle (fixture images are part of the test target) usingbundle.urlForImageResource, and writes to the applicationâs temporary directory. Logging shows me where everything is, so I just have to manually copy the written file back to my source directory.The code is a little messy since it needs to duplicate a lot of this packageâs code, and Iâve adjusted a bit for
swift-testing, but it works pretty well for me.Iâm running into this error while trying to see snapshots to disk in a macOS test environment. Is there an extra set of config for Mac testing?