Skip to content

Commit 56bc128

Browse files
committed
test(ios): preserve prefix-imposter capture paths
1 parent ab7b7b3 commit 56bc128

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

example/ios/ViewShotExampleTests/RNViewShotReleaseCaptureTests.mm

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,11 @@ - (void)testReleaseCapture_isANoOpForMissingFile
117117
XCTAssertFalse([self.fm fileExistsAtPath:missing]);
118118
}
119119

120-
- (void)testReleaseCapture_currentlyDeletesPrefixOnlyImposterDirectories_KNOWN_LOOSE_GUARD
120+
- (void)testReleaseCapture_preservesFilesInPrefixOnlyImposterDirectories
121121
{
122-
// KNOWN LOOSE GUARD — this test documents EXISTING (buggy) behaviour, not the
123-
// desired one.
124-
//
125-
// A path that starts with `<tmp>/ReactNative` as a string prefix but is NOT
126-
// inside the directory (e.g. `<tmp>/ReactNativeImposter/foo`) is currently
127-
// deleted, because the implementation uses [hasPrefix:] without a path
128-
// component boundary check. This is a latent bug that should be tightened in
129-
// a future PR (e.g. require the prefix to end with "/" or compare path
130-
// components). When that fix lands, flip this test to assert the imposter
131-
// file is preserved and rename accordingly.
122+
// A path that starts with `<tmp>/ReactNative` as a string prefix but is not
123+
// inside the directory (e.g. `<tmp>/ReactNativeImposter/foo`) must be left
124+
// alone.
132125
NSString *imposterDir = [NSTemporaryDirectory()
133126
stringByAppendingPathComponent:@"ReactNativeImposter"];
134127
NSString *imposterPath = [imposterDir stringByAppendingPathComponent:@"file.png"];
@@ -137,14 +130,9 @@ - (void)testReleaseCapture_currentlyDeletesPrefixOnlyImposterDirectories_KNOWN_L
137130

138131
[self.module releaseCapture:imposterPath];
139132

140-
// With the current `hasPrefix:` check, the file IS deleted because
141-
// "<tmp>/ReactNativeImposter/file.png" starts with "<tmp>/ReactNative".
142-
// Asserting observed behaviour so a future hardening of the guard is caught
143-
// here as a failure (and prompts a rename of this test).
144-
XCTAssertFalse([self.fm fileExistsAtPath:imposterPath],
145-
@"current impl deletes prefix-matching paths; once the guard "
146-
@"is tightened to require a path-component boundary, flip this "
147-
@"assertion and rename the test");
133+
XCTAssertTrue([self.fm fileExistsAtPath:imposterPath],
134+
@"releaseCapture must not delete files outside %@",
135+
self.reactNativeTmpDir);
148136

149137
// Cleanup
150138
[self.fm removeItemAtPath:imposterDir error:NULL];

0 commit comments

Comments
 (0)