Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 46a82f6

Browse files
committed
Fix mutable request, cache hit followed by download not emitting path
1 parent a156987 commit 46a82f6

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/FileSystem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ export class FileSystem {
300300
}).promise,
301301
).pipe(
302302
// Only need to emit or throw errors if the file has changed or this is the first download
303-
filter(() => stat === null),
303+
filter((downloadResult) => stat === null || downloadResult.statusCode === 200),
304304
map((downloadResult) => {
305-
if (downloadResult.statusCode !== 200) {
305+
if (stat === null && downloadResult.statusCode !== 200) {
306306
throw new Error('Request failed ' + downloadResult.statusCode)
307307
}
308308

tests/FileSystem.test.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,31 @@ describe('FileSystem', function () {
280280
it('When a mutable request is made with an existing cached file and the remote file has changed, the file path should be emitted twice', (done) => {
281281
const fileSystem = FileSystemFactory()
282282

283-
MockedRNFS.stat.mockResolvedValueOnce({
284-
name: '',
285-
path: '',
286-
size: '',
287-
mode: 777,
288-
mtime: 0,
289-
ctime: 0,
290-
originalFilepath: '',
291-
isFile: () => true,
292-
isDirectory: () => false,
293-
})
283+
MockedRNFS.stat
284+
// observable
285+
.mockResolvedValueOnce({
286+
name: '',
287+
path: '',
288+
size: '',
289+
mode: 777,
290+
mtime: 0,
291+
ctime: 0,
292+
originalFilepath: '',
293+
isFile: () => true,
294+
isDirectory: () => false,
295+
})
296+
// fetchFile
297+
.mockResolvedValueOnce({
298+
name: '',
299+
path: '',
300+
size: '',
301+
mode: 777,
302+
mtime: 0,
303+
ctime: 0,
304+
originalFilepath: '',
305+
isFile: () => true,
306+
isDirectory: () => false,
307+
})
294308

295309
const url =
296310
'https://img.wennermedia.com/5333a62d-07db-432a-92e2-198cafa38a14-326adb1a-d8ed-4a5d-b37e-5c88883e1989.png'

0 commit comments

Comments
 (0)