1740b3867SJames Ide'use strict'; 2740b3867SJames Ide 32bd74c95SEvan Baconimport { FileSystem as FS, Asset } from 'expo'; 467f55e2bSStanisław Chmiela 567f55e2bSStanisław Chmielaexport const name = 'FileSystem'; 6740b3867SJames Ide 7740b3867SJames Ideexport function test(t) { 8740b3867SJames Ide t.describe('FileSystem', () => { 9740b3867SJames Ide const throws = async run => { 10740b3867SJames Ide let error = null; 11740b3867SJames Ide try { 12740b3867SJames Ide await run(); 13740b3867SJames Ide } catch (e) { 14740b3867SJames Ide // Uncomment to log error message. 15740b3867SJames Ide // const func = run.toString().match(/[A-Za-z]+\(/)[0].slice(0, -1); 16740b3867SJames Ide // console.log(`${func}: ${e.message}`); 17740b3867SJames Ide error = e; 18740b3867SJames Ide } 19740b3867SJames Ide t.expect(error).toBeTruthy(); 20740b3867SJames Ide }; 21740b3867SJames Ide 22740b3867SJames Ide /*t.it( 23740b3867SJames Ide 'delete(idempotent) -> !exists -> download(md5, uri) -> exists ' + '-> delete -> !exists', 24740b3867SJames Ide async () => { 25740b3867SJames Ide const localUri = FS.documentDirectory + 'download1.png'; 26740b3867SJames Ide 27740b3867SJames Ide const assertExists = async expectedToExist => { 28740b3867SJames Ide let { exists } = await FS.getInfoAsync(localUri); 29740b3867SJames Ide if (expectedToExist) { 30740b3867SJames Ide t.expect(exists).toBeTruthy(); 31740b3867SJames Ide } else { 32740b3867SJames Ide t.expect(exists).not.toBeTruthy(); 33740b3867SJames Ide } 34740b3867SJames Ide }; 35740b3867SJames Ide 36740b3867SJames Ide await FS.deleteAsync(localUri, { idempotent: true }); 37740b3867SJames Ide await assertExists(false); 38740b3867SJames Ide 39740b3867SJames Ide const { 40740b3867SJames Ide md5, 41740b3867SJames Ide uri, 42740b3867SJames Ide headers, 43740b3867SJames Ide } = await FS.downloadAsync( 44740b3867SJames Ide 'https://s3-us-west-1.amazonaws.com/test-suite-data/avatar2.png', 45740b3867SJames Ide localUri, 46740b3867SJames Ide { md5: true } 47740b3867SJames Ide ); 48740b3867SJames Ide t.expect(md5).toBe('1e02045c10b8f1145edc7c8375998f87'); 49740b3867SJames Ide await assertExists(true); 50740b3867SJames Ide t.expect(headers['Content-Type']).toBe('image/png'); 51740b3867SJames Ide 52740b3867SJames Ide await FS.deleteAsync(localUri); 53740b3867SJames Ide await assertExists(false); 54740b3867SJames Ide }, 55740b3867SJames Ide 9000 56740b3867SJames Ide );*/ 57740b3867SJames Ide 582bd74c95SEvan Bacon t.it('Can read/write Base64', async () => { 592bd74c95SEvan Bacon const asset = await Asset.fromModule(require('../assets/icons/app.png')); 602bd74c95SEvan Bacon await asset.downloadAsync(); 612bd74c95SEvan Bacon 6267f55e2bSStanisław Chmiela for (let startingPosition = 0; startingPosition < 3; startingPosition++) { 632bd74c95SEvan Bacon const options = { 642bd74c95SEvan Bacon encoding: FS.EncodingTypes.Base64, 6567f55e2bSStanisław Chmiela position: startingPosition, 6667f55e2bSStanisław Chmiela length: startingPosition + 1, 672bd74c95SEvan Bacon }; 682bd74c95SEvan Bacon 692bd74c95SEvan Bacon const b64 = await FS.readAsStringAsync(asset.localUri, options); 702bd74c95SEvan Bacon t.expect(b64).toBeDefined(); 712bd74c95SEvan Bacon t.expect(typeof b64).toBe('string'); 7267f55e2bSStanisław Chmiela t.expect(b64.length % 4).toBe(0); 732bd74c95SEvan Bacon 742bd74c95SEvan Bacon const localUri = FS.documentDirectory + 'b64.png'; 752bd74c95SEvan Bacon 7667f55e2bSStanisław Chmiela await FS.writeAsStringAsync(localUri, b64, { encoding: FS.EncodingTypes.Base64 }); 772bd74c95SEvan Bacon 7867f55e2bSStanisław Chmiela t.expect(await FS.readAsStringAsync(localUri, { encoding: FS.EncodingTypes.Base64 })).toBe( 7967f55e2bSStanisław Chmiela b64 8067f55e2bSStanisław Chmiela ); 812bd74c95SEvan Bacon } 822bd74c95SEvan Bacon }); 832bd74c95SEvan Bacon 84740b3867SJames Ide t.it('delete(idempotent) -> delete[error]', async () => { 85740b3867SJames Ide const localUri = FS.documentDirectory + 'willDelete.png'; 86740b3867SJames Ide 87740b3867SJames Ide await FS.deleteAsync(localUri, { idempotent: true }); 88740b3867SJames Ide 89740b3867SJames Ide let error; 90740b3867SJames Ide try { 91740b3867SJames Ide await FS.deleteAsync(localUri); 92740b3867SJames Ide } catch (e) { 93740b3867SJames Ide error = e; 94740b3867SJames Ide } 95740b3867SJames Ide t.expect(error.message).toMatch(/not.*found/); 96740b3867SJames Ide }); 97740b3867SJames Ide 98740b3867SJames Ide /*t.it( 99740b3867SJames Ide 'download(md5, uri) -> read -> delete -> !exists -> read[error]', 100740b3867SJames Ide async () => { 101740b3867SJames Ide const localUri = FS.documentDirectory + 'download1.txt'; 102740b3867SJames Ide 103740b3867SJames Ide const { 104740b3867SJames Ide md5, 105740b3867SJames Ide uri, 106740b3867SJames Ide } = await FS.downloadAsync( 107740b3867SJames Ide 'https://s3-us-west-1.amazonaws.com/test-suite-data/text-file.txt', 108740b3867SJames Ide localUri, 109740b3867SJames Ide { md5: true } 110740b3867SJames Ide ); 111740b3867SJames Ide t.expect(md5).toBe('86d73d2f11e507365f7ea8e7ec3cc4cb'); 112740b3867SJames Ide 113740b3867SJames Ide const string = await FS.readAsStringAsync(localUri); 114740b3867SJames Ide t.expect(string).toBe('hello, world\nthis is a test file\n'); 115740b3867SJames Ide 116740b3867SJames Ide await FS.deleteAsync(localUri, { idempotent: true }); 117740b3867SJames Ide 118740b3867SJames Ide let error; 119740b3867SJames Ide try { 120740b3867SJames Ide await FS.readAsStringAsync(localUri); 121740b3867SJames Ide } catch (e) { 122740b3867SJames Ide error = e; 123740b3867SJames Ide } 124740b3867SJames Ide t.expect(error).toBeTruthy(); 125740b3867SJames Ide }, 126740b3867SJames Ide 9000 127740b3867SJames Ide );*/ 128740b3867SJames Ide 129740b3867SJames Ide t.it('delete(idempotent) -> !exists -> write -> read -> write -> read', async () => { 130740b3867SJames Ide const localUri = FS.documentDirectory + 'write1.txt'; 131740b3867SJames Ide 132740b3867SJames Ide await FS.deleteAsync(localUri, { idempotent: true }); 133740b3867SJames Ide 134740b3867SJames Ide const { exists } = await FS.getInfoAsync(localUri); 135740b3867SJames Ide t.expect(exists).not.toBeTruthy(); 136740b3867SJames Ide 137740b3867SJames Ide const writeAndVerify = async expected => { 138740b3867SJames Ide await FS.writeAsStringAsync(localUri, expected); 139740b3867SJames Ide const string = await FS.readAsStringAsync(localUri); 140740b3867SJames Ide t.expect(string).toBe(expected); 141740b3867SJames Ide }; 142740b3867SJames Ide 143740b3867SJames Ide await writeAndVerify('hello, world'); 144740b3867SJames Ide await writeAndVerify('hello, world!!!!!!'); 145740b3867SJames Ide }); 146740b3867SJames Ide 147740b3867SJames Ide t.it('delete(new) -> 2 * [write -> move -> !exists(orig) -> read(new)]', async () => { 148740b3867SJames Ide const from = FS.documentDirectory + 'from.txt'; 149740b3867SJames Ide const to = FS.documentDirectory + 'to.txt'; 150740b3867SJames Ide const contents = ['contents 1', 'contents 2']; 151740b3867SJames Ide 152740b3867SJames Ide await FS.deleteAsync(to, { idempotent: true }); 153740b3867SJames Ide 154740b3867SJames Ide // Move twice to make sure we can overwrite 155740b3867SJames Ide for (let i = 0; i < 2; ++i) { 156740b3867SJames Ide await FS.writeAsStringAsync(from, contents[i]); 157740b3867SJames Ide 158740b3867SJames Ide await FS.moveAsync({ from, to }); 159740b3867SJames Ide 160740b3867SJames Ide const { exists } = await FS.getInfoAsync(from); 161740b3867SJames Ide t.expect(exists).not.toBeTruthy(); 162740b3867SJames Ide 163740b3867SJames Ide t.expect(await FS.readAsStringAsync(to)).toBe(contents[i]); 164740b3867SJames Ide } 165740b3867SJames Ide }); 166740b3867SJames Ide 167740b3867SJames Ide t.it('delete(new) -> 2 * [write -> copy -> exists(orig) -> read(new)]', async () => { 168740b3867SJames Ide const from = FS.documentDirectory + 'from.txt'; 169740b3867SJames Ide const to = FS.documentDirectory + 'to.txt'; 170740b3867SJames Ide const contents = ['contents 1', 'contents 2']; 171740b3867SJames Ide 172740b3867SJames Ide await FS.deleteAsync(to, { idempotent: true }); 173740b3867SJames Ide 174740b3867SJames Ide // Copy twice to make sure we can overwrite 175740b3867SJames Ide for (let i = 0; i < 2; ++i) { 176740b3867SJames Ide await FS.writeAsStringAsync(from, contents[i]); 177740b3867SJames Ide 178740b3867SJames Ide await FS.copyAsync({ from, to }); 179740b3867SJames Ide 180740b3867SJames Ide const { exists } = await FS.getInfoAsync(from); 181740b3867SJames Ide t.expect(exists).toBeTruthy(); 182740b3867SJames Ide 183740b3867SJames Ide t.expect(await FS.readAsStringAsync(to)).toBe(contents[i]); 184740b3867SJames Ide } 185740b3867SJames Ide }); 186740b3867SJames Ide 187740b3867SJames Ide t.it( 188740b3867SJames Ide 'delete(dir) -> write(dir/file)[error] -> mkdir(dir) ->' + 189740b3867SJames Ide 'mkdir(dir)[error] -> write(dir/file) -> read', 190740b3867SJames Ide async () => { 191740b3867SJames Ide let error; 192740b3867SJames Ide const path = FS.documentDirectory + 'dir/file'; 193740b3867SJames Ide const dir = FS.documentDirectory + 'dir'; 194740b3867SJames Ide const contents = 'hello, world'; 195740b3867SJames Ide 196740b3867SJames Ide await FS.deleteAsync(dir, { idempotent: true }); 197740b3867SJames Ide 198740b3867SJames Ide error = null; 199740b3867SJames Ide try { 200740b3867SJames Ide await FS.writeAsStringAsync(path, contents); 201740b3867SJames Ide } catch (e) { 202740b3867SJames Ide error = e; 203740b3867SJames Ide } 204740b3867SJames Ide t.expect(error).toBeTruthy(); 205740b3867SJames Ide 206740b3867SJames Ide await FS.makeDirectoryAsync(dir); 207740b3867SJames Ide 208740b3867SJames Ide error = null; 209740b3867SJames Ide try { 210740b3867SJames Ide await FS.makeDirectoryAsync(dir); 211740b3867SJames Ide } catch (e) { 212740b3867SJames Ide error = e; 213740b3867SJames Ide } 214740b3867SJames Ide t.expect(error).toBeTruthy(); 215740b3867SJames Ide 216740b3867SJames Ide await FS.writeAsStringAsync(path, contents); 217740b3867SJames Ide 218740b3867SJames Ide t.expect(await FS.readAsStringAsync(path)).toBe(contents); 219740b3867SJames Ide } 220740b3867SJames Ide ); 221740b3867SJames Ide 222740b3867SJames Ide t.it( 223740b3867SJames Ide 'delete(dir) -> write(dir/dir2/file)[error] -> ' + 224740b3867SJames Ide 'mkdir(dir/dir2, intermediates) -> ' + 225740b3867SJames Ide 'mkdir(dir/dir2, intermediates) -> write(dir/dir2/file) -> read', 226740b3867SJames Ide async () => { 227740b3867SJames Ide let error; 228740b3867SJames Ide const path = FS.documentDirectory + 'dir/dir2/file'; 229740b3867SJames Ide const dir = FS.documentDirectory + 'dir/dir2'; 230740b3867SJames Ide const contents = 'hello, world'; 231740b3867SJames Ide 232740b3867SJames Ide await FS.deleteAsync(dir, { idempotent: true }); 233740b3867SJames Ide 234740b3867SJames Ide error = null; 235740b3867SJames Ide try { 236740b3867SJames Ide await FS.writeAsStringAsync(path, contents); 237740b3867SJames Ide } catch (e) { 238740b3867SJames Ide error = e; 239740b3867SJames Ide } 240740b3867SJames Ide t.expect(error).toBeTruthy(); 241740b3867SJames Ide 242740b3867SJames Ide await FS.makeDirectoryAsync(dir, { 243740b3867SJames Ide intermediates: true, 244740b3867SJames Ide }); 245740b3867SJames Ide 246740b3867SJames Ide error = null; 247740b3867SJames Ide try { 248740b3867SJames Ide await FS.makeDirectoryAsync(dir); 249740b3867SJames Ide } catch (e) { 250740b3867SJames Ide error = e; 251740b3867SJames Ide } 252740b3867SJames Ide t.expect(error).toBeTruthy(); 253740b3867SJames Ide 254*6cfa9c5fSSergei Chestakov error = null; 255*6cfa9c5fSSergei Chestakov try { 256*6cfa9c5fSSergei Chestakov await FS.makeDirectoryAsync(dir, { 257*6cfa9c5fSSergei Chestakov intermediates: true, 258*6cfa9c5fSSergei Chestakov }); 259*6cfa9c5fSSergei Chestakov } catch (e) { 260*6cfa9c5fSSergei Chestakov error = e; 261*6cfa9c5fSSergei Chestakov } 262*6cfa9c5fSSergei Chestakov t.expect(error).toBe(null); 263*6cfa9c5fSSergei Chestakov 264740b3867SJames Ide await FS.writeAsStringAsync(path, contents); 265740b3867SJames Ide 266740b3867SJames Ide t.expect(await FS.readAsStringAsync(path)).toBe(contents); 267740b3867SJames Ide } 268740b3867SJames Ide ); 269740b3867SJames Ide 270740b3867SJames Ide t.it( 271740b3867SJames Ide 'delete(dir, idempotent) -> make tree -> check contents ' + 272740b3867SJames Ide '-> check directory listings' + 273740b3867SJames Ide '-> move -> check directory listings' + 274740b3867SJames Ide '-> copy -> check directory listings', 275740b3867SJames Ide async () => { 276740b3867SJames Ide let error; 277740b3867SJames Ide const dir = FS.documentDirectory + 'dir'; 278740b3867SJames Ide 279740b3867SJames Ide await FS.deleteAsync(dir, { idempotent: true }); 280740b3867SJames Ide 281740b3867SJames Ide await FS.makeDirectoryAsync(dir + '/child1', { 282740b3867SJames Ide intermediates: true, 283740b3867SJames Ide }); 284740b3867SJames Ide await FS.makeDirectoryAsync(dir + '/child2', { 285740b3867SJames Ide intermediates: true, 286740b3867SJames Ide }); 287740b3867SJames Ide 288740b3867SJames Ide await FS.writeAsStringAsync(dir + '/file1', 'contents1'); 289740b3867SJames Ide await FS.writeAsStringAsync(dir + '/file2', 'contents2'); 290740b3867SJames Ide 291740b3867SJames Ide await FS.writeAsStringAsync(dir + '/child1/file3', 'contents3'); 292740b3867SJames Ide 293740b3867SJames Ide await FS.writeAsStringAsync(dir + '/child2/file4', 'contents4'); 294740b3867SJames Ide await FS.writeAsStringAsync(dir + '/child2/file5', 'contents5'); 295740b3867SJames Ide 296740b3867SJames Ide const checkContents = async (path, contents) => 297740b3867SJames Ide t.expect(await FS.readAsStringAsync(path)).toBe(contents); 298740b3867SJames Ide 299740b3867SJames Ide await checkContents(dir + '/file1', 'contents1'); 300740b3867SJames Ide await checkContents(dir + '/file2', 'contents2'); 301740b3867SJames Ide await checkContents(dir + '/child1/file3', 'contents3'); 302740b3867SJames Ide await checkContents(dir + '/child2/file4', 'contents4'); 303740b3867SJames Ide await checkContents(dir + '/child2/file5', 'contents5'); 304740b3867SJames Ide 305740b3867SJames Ide const checkDirectory = async (path, expected) => { 306740b3867SJames Ide const list = await FS.readDirectoryAsync(path); 307740b3867SJames Ide t.expect(list.sort()).toEqual(expected.sort()); 308740b3867SJames Ide }; 309740b3867SJames Ide 310740b3867SJames Ide const checkRoot = async root => { 311740b3867SJames Ide await checkDirectory(root, ['file1', 'file2', 'child1', 'child2']); 312740b3867SJames Ide await checkDirectory(root + '/child1', ['file3']); 313740b3867SJames Ide await checkDirectory(root + '/child2', ['file4', 'file5']); 314740b3867SJames Ide 315740b3867SJames Ide error = null; 316740b3867SJames Ide try { 317740b3867SJames Ide await checkDirectory(root + '/file1', ['nope']); 318740b3867SJames Ide } catch (e) { 319740b3867SJames Ide error = e; 320740b3867SJames Ide } 321740b3867SJames Ide t.expect(error).toBeTruthy(); 322740b3867SJames Ide }; 323740b3867SJames Ide 324740b3867SJames Ide await checkRoot(dir); 325740b3867SJames Ide 326740b3867SJames Ide await FS.deleteAsync(FS.documentDirectory + 'moved', { 327740b3867SJames Ide idempotent: true, 328740b3867SJames Ide }); 329740b3867SJames Ide await FS.moveAsync({ from: dir, to: FS.documentDirectory + 'moved' }); 330740b3867SJames Ide await checkRoot(FS.documentDirectory + 'moved'); 331740b3867SJames Ide await FS.copyAsync({ 332740b3867SJames Ide from: FS.documentDirectory + 'moved', 333740b3867SJames Ide to: FS.documentDirectory + 'copied', 334740b3867SJames Ide }); 335740b3867SJames Ide await checkRoot(FS.documentDirectory + 'copied'); 336740b3867SJames Ide } 337740b3867SJames Ide ); 338740b3867SJames Ide 339740b3867SJames Ide t.it( 340740b3867SJames Ide 'delete(idempotent) -> download(md5) -> getInfo(size)', 341740b3867SJames Ide async () => { 342740b3867SJames Ide const localUri = FS.documentDirectory + 'download1.png'; 343740b3867SJames Ide 344740b3867SJames Ide await FS.deleteAsync(localUri, { idempotent: true }); 345740b3867SJames Ide 34667f55e2bSStanisław Chmiela const { md5 } = await FS.downloadAsync( 347740b3867SJames Ide 'https://s3-us-west-1.amazonaws.com/test-suite-data/avatar2.png', 348740b3867SJames Ide localUri, 349740b3867SJames Ide { md5: true } 350740b3867SJames Ide ); 351740b3867SJames Ide t.expect(md5).toBe('1e02045c10b8f1145edc7c8375998f87'); 352740b3867SJames Ide 353740b3867SJames Ide const { size, modificationTime } = await FS.getInfoAsync(localUri); 354740b3867SJames Ide t.expect(size).toBe(3230); 355740b3867SJames Ide const nowTime = 0.001 * new Date().getTime(); 356740b3867SJames Ide t.expect(nowTime - modificationTime).toBeLessThan(3600); 357740b3867SJames Ide 358740b3867SJames Ide await FS.deleteAsync(localUri); 359740b3867SJames Ide }, 36067f55e2bSStanisław Chmiela 30000 361740b3867SJames Ide ); 362740b3867SJames Ide 363740b3867SJames Ide t.it('throws out-of-scope exceptions', async () => { 364740b3867SJames Ide const p = FS.documentDirectory; 365740b3867SJames Ide 366740b3867SJames Ide await throws(() => FS.getInfoAsync(p + '../hello/world')); 367740b3867SJames Ide await throws(() => FS.readAsStringAsync(p + '../hello/world')); 368740b3867SJames Ide await throws(() => FS.writeAsStringAsync(p + '../hello/world', '')); 369740b3867SJames Ide await throws(() => FS.deleteAsync(p + '../hello/world')); 370740b3867SJames Ide await throws(() => FS.deleteAsync(p)); 371740b3867SJames Ide await throws(() => FS.deleteAsync(FS.cacheDirectory)); 372740b3867SJames Ide await throws(() => FS.moveAsync({ from: p + '../a/b', to: 'c' })); 373740b3867SJames Ide await throws(() => FS.moveAsync({ from: 'c', to: p + '../a/b' })); 374740b3867SJames Ide await throws(() => FS.copyAsync({ from: p + '../a/b', to: 'c' })); 375740b3867SJames Ide await throws(() => FS.copyAsync({ from: 'c', to: p + '../a/b' })); 376740b3867SJames Ide await throws(() => FS.makeDirectoryAsync(p + '../hello/world')); 377740b3867SJames Ide await throws(() => FS.readDirectoryAsync(p + '../hello/world')); 378740b3867SJames Ide await throws(() => FS.downloadAsync('http://www.google.com', p + '../hello/world')); 379740b3867SJames Ide await throws(() => FS.readDirectoryAsync(p + '../')); 380740b3867SJames Ide await throws(() => FS.downloadAsync('http://www.google.com', p + '../hello/world')); 381740b3867SJames Ide }); 382740b3867SJames Ide 383740b3867SJames Ide t.it('missing parameters', async () => { 384740b3867SJames Ide const p = FS.documentDirectory + 'test'; 385740b3867SJames Ide 386740b3867SJames Ide await throws(() => FS.moveAsync({ from: p })); 387740b3867SJames Ide await throws(() => FS.moveAsync({ to: p })); 388740b3867SJames Ide await throws(() => FS.copyAsync({ from: p })); 389740b3867SJames Ide await throws(() => FS.copyAsync({ to: p })); 390740b3867SJames Ide }); 391740b3867SJames Ide 392740b3867SJames Ide t.it('can read root directories', async () => { 393740b3867SJames Ide await FS.readDirectoryAsync(FS.documentDirectory); 394740b3867SJames Ide await FS.readDirectoryAsync(FS.cacheDirectory); 395740b3867SJames Ide }); 396740b3867SJames Ide 397740b3867SJames Ide /*t.it('can copy from `CameraRoll`, verify hash, other methods restricted', async () => { 398740b3867SJames Ide await Promise.all( 399740b3867SJames Ide (await CameraRoll.getPhotos({ 400740b3867SJames Ide first: 1, 401740b3867SJames Ide })).edges.map(async ({ node: { image: { uri: cameraRollUri } } }) => { 402740b3867SJames Ide const destinationUri = FS.documentDirectory + 'photo.jpg'; 403740b3867SJames Ide 404740b3867SJames Ide await throws(() => FS.readAsStringAsync(cameraRollUri)); 405740b3867SJames Ide await throws(() => FS.writeAsStringAsync(cameraRollUri)); 406740b3867SJames Ide await throws(() => FS.deleteAsync(cameraRollUri)); 407740b3867SJames Ide await throws(() => FS.moveAsync({ from: cameraRollUri, to: destinationUri })); 408740b3867SJames Ide await throws(() => FS.copyAsync({ from: destinationUri, to: cameraRollUri })); 409740b3867SJames Ide await throws(() => FS.makeDirectoryAsync(cameraRollUri)); 410740b3867SJames Ide await throws(() => FS.readDirectoryAsync(cameraRollUri)); 411740b3867SJames Ide await throws(() => FS.downloadAsync('http://www.google.com', cameraRollUri)); 412740b3867SJames Ide 413740b3867SJames Ide await FS.copyAsync({ from: cameraRollUri, to: destinationUri }); 414740b3867SJames Ide 415740b3867SJames Ide const origInfo = await FS.getInfoAsync(cameraRollUri, { 416740b3867SJames Ide size: true, 417740b3867SJames Ide md5: true, 418740b3867SJames Ide }); 419740b3867SJames Ide const copyInfo = await FS.getInfoAsync(destinationUri, { 420740b3867SJames Ide size: true, 421740b3867SJames Ide md5: true, 422740b3867SJames Ide }); 423740b3867SJames Ide 424740b3867SJames Ide t.expect(origInfo.md5).toEqual(copyInfo.md5); 425740b3867SJames Ide t.expect(origInfo.size).toEqual(copyInfo.size); 426740b3867SJames Ide }) 427740b3867SJames Ide ); 428740b3867SJames Ide });*/ 429740b3867SJames Ide 430740b3867SJames Ide t.it( 431740b3867SJames Ide 'download(network failure)', 432740b3867SJames Ide async () => { 433740b3867SJames Ide const localUri = FS.documentDirectory + 'download1.png'; 434740b3867SJames Ide 435740b3867SJames Ide const assertExists = async expectedToExist => { 436740b3867SJames Ide let { exists } = await FS.getInfoAsync(localUri); 437740b3867SJames Ide if (expectedToExist) { 438740b3867SJames Ide t.expect(exists).toBeTruthy(); 439740b3867SJames Ide } else { 440740b3867SJames Ide t.expect(exists).not.toBeTruthy(); 441740b3867SJames Ide } 442740b3867SJames Ide }; 443740b3867SJames Ide 444740b3867SJames Ide await FS.deleteAsync(localUri, { idempotent: true }); 445740b3867SJames Ide await assertExists(false); 446740b3867SJames Ide 447740b3867SJames Ide let error; 448740b3867SJames Ide try { 449740b3867SJames Ide const { md5, uri } = await FS.downloadAsync( 450740b3867SJames Ide 'https://nonexistent-subdomain.expo.io', 451740b3867SJames Ide localUri, 452740b3867SJames Ide { md5: true } 453740b3867SJames Ide ); 454740b3867SJames Ide } catch (e) { 455740b3867SJames Ide error = e; 456740b3867SJames Ide } 457740b3867SJames Ide t.expect(error).toBeTruthy(); 458740b3867SJames Ide await assertExists(false); 459740b3867SJames Ide await FS.deleteAsync(localUri, { idempotent: true }); 460740b3867SJames Ide }, 46167f55e2bSStanisław Chmiela 30000 462740b3867SJames Ide ); 463740b3867SJames Ide 464740b3867SJames Ide t.it( 465740b3867SJames Ide 'download(404)', 466740b3867SJames Ide async () => { 467740b3867SJames Ide const localUri = FS.documentDirectory + 'download1.png'; 468740b3867SJames Ide 469740b3867SJames Ide const assertExists = async expectedToExist => { 470740b3867SJames Ide let { exists } = await FS.getInfoAsync(localUri); 471740b3867SJames Ide if (expectedToExist) { 472740b3867SJames Ide t.expect(exists).toBeTruthy(); 473740b3867SJames Ide } else { 474740b3867SJames Ide t.expect(exists).not.toBeTruthy(); 475740b3867SJames Ide } 476740b3867SJames Ide }; 477740b3867SJames Ide 478740b3867SJames Ide await FS.deleteAsync(localUri, { idempotent: true }); 479740b3867SJames Ide await assertExists(false); 480740b3867SJames Ide 481740b3867SJames Ide const { md5, uri, status } = await FS.downloadAsync('https://expo.io/404', localUri, { 482740b3867SJames Ide md5: true, 483740b3867SJames Ide }); 484740b3867SJames Ide await assertExists(true); 485740b3867SJames Ide t.expect(status).toBe(404); 486740b3867SJames Ide 487740b3867SJames Ide await FS.deleteAsync(localUri); 488740b3867SJames Ide await assertExists(false); 489740b3867SJames Ide }, 49067f55e2bSStanisław Chmiela 30000 491740b3867SJames Ide ); 492740b3867SJames Ide }); 493740b3867SJames Ide} 494