xref: /expo/apps/test-suite/tests/FileSystem.js (revision 67f55e2b)
1740b3867SJames Ide'use strict';
2740b3867SJames Ide
32bd74c95SEvan Baconimport { FileSystem as FS, Asset } from 'expo';
4*67f55e2bSStanisław Chmiela
5*67f55e2bSStanisł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
62*67f55e2bSStanisław Chmiela      for (let startingPosition = 0; startingPosition < 3; startingPosition++) {
632bd74c95SEvan Bacon        const options = {
642bd74c95SEvan Bacon          encoding: FS.EncodingTypes.Base64,
65*67f55e2bSStanisław Chmiela          position: startingPosition,
66*67f55e2bSStanisł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');
72*67f55e2bSStanisław Chmiela        t.expect(b64.length % 4).toBe(0);
732bd74c95SEvan Bacon
742bd74c95SEvan Bacon        const localUri = FS.documentDirectory + 'b64.png';
752bd74c95SEvan Bacon
76*67f55e2bSStanisław Chmiela        await FS.writeAsStringAsync(localUri, b64, { encoding: FS.EncodingTypes.Base64 });
772bd74c95SEvan Bacon
78*67f55e2bSStanisław Chmiela        t.expect(await FS.readAsStringAsync(localUri, { encoding: FS.EncodingTypes.Base64 })).toBe(
79*67f55e2bSStanisław Chmiela          b64
80*67f55e2bSStanisł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
254740b3867SJames Ide        await FS.writeAsStringAsync(path, contents);
255740b3867SJames Ide
256740b3867SJames Ide        t.expect(await FS.readAsStringAsync(path)).toBe(contents);
257740b3867SJames Ide      }
258740b3867SJames Ide    );
259740b3867SJames Ide
260740b3867SJames Ide    t.it(
261740b3867SJames Ide      'delete(dir, idempotent) -> make tree -> check contents ' +
262740b3867SJames Ide        '-> check directory listings' +
263740b3867SJames Ide        '-> move -> check directory listings' +
264740b3867SJames Ide        '-> copy -> check directory listings',
265740b3867SJames Ide      async () => {
266740b3867SJames Ide        let error;
267740b3867SJames Ide        const dir = FS.documentDirectory + 'dir';
268740b3867SJames Ide
269740b3867SJames Ide        await FS.deleteAsync(dir, { idempotent: true });
270740b3867SJames Ide
271740b3867SJames Ide        await FS.makeDirectoryAsync(dir + '/child1', {
272740b3867SJames Ide          intermediates: true,
273740b3867SJames Ide        });
274740b3867SJames Ide        await FS.makeDirectoryAsync(dir + '/child2', {
275740b3867SJames Ide          intermediates: true,
276740b3867SJames Ide        });
277740b3867SJames Ide
278740b3867SJames Ide        await FS.writeAsStringAsync(dir + '/file1', 'contents1');
279740b3867SJames Ide        await FS.writeAsStringAsync(dir + '/file2', 'contents2');
280740b3867SJames Ide
281740b3867SJames Ide        await FS.writeAsStringAsync(dir + '/child1/file3', 'contents3');
282740b3867SJames Ide
283740b3867SJames Ide        await FS.writeAsStringAsync(dir + '/child2/file4', 'contents4');
284740b3867SJames Ide        await FS.writeAsStringAsync(dir + '/child2/file5', 'contents5');
285740b3867SJames Ide
286740b3867SJames Ide        const checkContents = async (path, contents) =>
287740b3867SJames Ide          t.expect(await FS.readAsStringAsync(path)).toBe(contents);
288740b3867SJames Ide
289740b3867SJames Ide        await checkContents(dir + '/file1', 'contents1');
290740b3867SJames Ide        await checkContents(dir + '/file2', 'contents2');
291740b3867SJames Ide        await checkContents(dir + '/child1/file3', 'contents3');
292740b3867SJames Ide        await checkContents(dir + '/child2/file4', 'contents4');
293740b3867SJames Ide        await checkContents(dir + '/child2/file5', 'contents5');
294740b3867SJames Ide
295740b3867SJames Ide        const checkDirectory = async (path, expected) => {
296740b3867SJames Ide          const list = await FS.readDirectoryAsync(path);
297740b3867SJames Ide          t.expect(list.sort()).toEqual(expected.sort());
298740b3867SJames Ide        };
299740b3867SJames Ide
300740b3867SJames Ide        const checkRoot = async root => {
301740b3867SJames Ide          await checkDirectory(root, ['file1', 'file2', 'child1', 'child2']);
302740b3867SJames Ide          await checkDirectory(root + '/child1', ['file3']);
303740b3867SJames Ide          await checkDirectory(root + '/child2', ['file4', 'file5']);
304740b3867SJames Ide
305740b3867SJames Ide          error = null;
306740b3867SJames Ide          try {
307740b3867SJames Ide            await checkDirectory(root + '/file1', ['nope']);
308740b3867SJames Ide          } catch (e) {
309740b3867SJames Ide            error = e;
310740b3867SJames Ide          }
311740b3867SJames Ide          t.expect(error).toBeTruthy();
312740b3867SJames Ide        };
313740b3867SJames Ide
314740b3867SJames Ide        await checkRoot(dir);
315740b3867SJames Ide
316740b3867SJames Ide        await FS.deleteAsync(FS.documentDirectory + 'moved', {
317740b3867SJames Ide          idempotent: true,
318740b3867SJames Ide        });
319740b3867SJames Ide        await FS.moveAsync({ from: dir, to: FS.documentDirectory + 'moved' });
320740b3867SJames Ide        await checkRoot(FS.documentDirectory + 'moved');
321740b3867SJames Ide        await FS.copyAsync({
322740b3867SJames Ide          from: FS.documentDirectory + 'moved',
323740b3867SJames Ide          to: FS.documentDirectory + 'copied',
324740b3867SJames Ide        });
325740b3867SJames Ide        await checkRoot(FS.documentDirectory + 'copied');
326740b3867SJames Ide      }
327740b3867SJames Ide    );
328740b3867SJames Ide
329740b3867SJames Ide    t.it(
330740b3867SJames Ide      'delete(idempotent) -> download(md5) -> getInfo(size)',
331740b3867SJames Ide      async () => {
332740b3867SJames Ide        const localUri = FS.documentDirectory + 'download1.png';
333740b3867SJames Ide
334740b3867SJames Ide        await FS.deleteAsync(localUri, { idempotent: true });
335740b3867SJames Ide
336*67f55e2bSStanisław Chmiela        const { md5 } = await FS.downloadAsync(
337740b3867SJames Ide          'https://s3-us-west-1.amazonaws.com/test-suite-data/avatar2.png',
338740b3867SJames Ide          localUri,
339740b3867SJames Ide          { md5: true }
340740b3867SJames Ide        );
341740b3867SJames Ide        t.expect(md5).toBe('1e02045c10b8f1145edc7c8375998f87');
342740b3867SJames Ide
343740b3867SJames Ide        const { size, modificationTime } = await FS.getInfoAsync(localUri);
344740b3867SJames Ide        t.expect(size).toBe(3230);
345740b3867SJames Ide        const nowTime = 0.001 * new Date().getTime();
346740b3867SJames Ide        t.expect(nowTime - modificationTime).toBeLessThan(3600);
347740b3867SJames Ide
348740b3867SJames Ide        await FS.deleteAsync(localUri);
349740b3867SJames Ide      },
350*67f55e2bSStanisław Chmiela      30000
351740b3867SJames Ide    );
352740b3867SJames Ide
353740b3867SJames Ide    t.it('throws out-of-scope exceptions', async () => {
354740b3867SJames Ide      const p = FS.documentDirectory;
355740b3867SJames Ide
356740b3867SJames Ide      await throws(() => FS.getInfoAsync(p + '../hello/world'));
357740b3867SJames Ide      await throws(() => FS.readAsStringAsync(p + '../hello/world'));
358740b3867SJames Ide      await throws(() => FS.writeAsStringAsync(p + '../hello/world', ''));
359740b3867SJames Ide      await throws(() => FS.deleteAsync(p + '../hello/world'));
360740b3867SJames Ide      await throws(() => FS.deleteAsync(p));
361740b3867SJames Ide      await throws(() => FS.deleteAsync(FS.cacheDirectory));
362740b3867SJames Ide      await throws(() => FS.moveAsync({ from: p + '../a/b', to: 'c' }));
363740b3867SJames Ide      await throws(() => FS.moveAsync({ from: 'c', to: p + '../a/b' }));
364740b3867SJames Ide      await throws(() => FS.copyAsync({ from: p + '../a/b', to: 'c' }));
365740b3867SJames Ide      await throws(() => FS.copyAsync({ from: 'c', to: p + '../a/b' }));
366740b3867SJames Ide      await throws(() => FS.makeDirectoryAsync(p + '../hello/world'));
367740b3867SJames Ide      await throws(() => FS.readDirectoryAsync(p + '../hello/world'));
368740b3867SJames Ide      await throws(() => FS.downloadAsync('http://www.google.com', p + '../hello/world'));
369740b3867SJames Ide      await throws(() => FS.readDirectoryAsync(p + '../'));
370740b3867SJames Ide      await throws(() => FS.downloadAsync('http://www.google.com', p + '../hello/world'));
371740b3867SJames Ide    });
372740b3867SJames Ide
373740b3867SJames Ide    t.it('missing parameters', async () => {
374740b3867SJames Ide      const p = FS.documentDirectory + 'test';
375740b3867SJames Ide
376740b3867SJames Ide      await throws(() => FS.moveAsync({ from: p }));
377740b3867SJames Ide      await throws(() => FS.moveAsync({ to: p }));
378740b3867SJames Ide      await throws(() => FS.copyAsync({ from: p }));
379740b3867SJames Ide      await throws(() => FS.copyAsync({ to: p }));
380740b3867SJames Ide    });
381740b3867SJames Ide
382740b3867SJames Ide    t.it('can read root directories', async () => {
383740b3867SJames Ide      await FS.readDirectoryAsync(FS.documentDirectory);
384740b3867SJames Ide      await FS.readDirectoryAsync(FS.cacheDirectory);
385740b3867SJames Ide    });
386740b3867SJames Ide
387740b3867SJames Ide    /*t.it('can copy from `CameraRoll`, verify hash, other methods restricted', async () => {
388740b3867SJames Ide      await Promise.all(
389740b3867SJames Ide        (await CameraRoll.getPhotos({
390740b3867SJames Ide          first: 1,
391740b3867SJames Ide        })).edges.map(async ({ node: { image: { uri: cameraRollUri } } }) => {
392740b3867SJames Ide          const destinationUri = FS.documentDirectory + 'photo.jpg';
393740b3867SJames Ide
394740b3867SJames Ide          await throws(() => FS.readAsStringAsync(cameraRollUri));
395740b3867SJames Ide          await throws(() => FS.writeAsStringAsync(cameraRollUri));
396740b3867SJames Ide          await throws(() => FS.deleteAsync(cameraRollUri));
397740b3867SJames Ide          await throws(() => FS.moveAsync({ from: cameraRollUri, to: destinationUri }));
398740b3867SJames Ide          await throws(() => FS.copyAsync({ from: destinationUri, to: cameraRollUri }));
399740b3867SJames Ide          await throws(() => FS.makeDirectoryAsync(cameraRollUri));
400740b3867SJames Ide          await throws(() => FS.readDirectoryAsync(cameraRollUri));
401740b3867SJames Ide          await throws(() => FS.downloadAsync('http://www.google.com', cameraRollUri));
402740b3867SJames Ide
403740b3867SJames Ide          await FS.copyAsync({ from: cameraRollUri, to: destinationUri });
404740b3867SJames Ide
405740b3867SJames Ide          const origInfo = await FS.getInfoAsync(cameraRollUri, {
406740b3867SJames Ide            size: true,
407740b3867SJames Ide            md5: true,
408740b3867SJames Ide          });
409740b3867SJames Ide          const copyInfo = await FS.getInfoAsync(destinationUri, {
410740b3867SJames Ide            size: true,
411740b3867SJames Ide            md5: true,
412740b3867SJames Ide          });
413740b3867SJames Ide
414740b3867SJames Ide          t.expect(origInfo.md5).toEqual(copyInfo.md5);
415740b3867SJames Ide          t.expect(origInfo.size).toEqual(copyInfo.size);
416740b3867SJames Ide        })
417740b3867SJames Ide      );
418740b3867SJames Ide    });*/
419740b3867SJames Ide
420740b3867SJames Ide    t.it(
421740b3867SJames Ide      'download(network failure)',
422740b3867SJames Ide      async () => {
423740b3867SJames Ide        const localUri = FS.documentDirectory + 'download1.png';
424740b3867SJames Ide
425740b3867SJames Ide        const assertExists = async expectedToExist => {
426740b3867SJames Ide          let { exists } = await FS.getInfoAsync(localUri);
427740b3867SJames Ide          if (expectedToExist) {
428740b3867SJames Ide            t.expect(exists).toBeTruthy();
429740b3867SJames Ide          } else {
430740b3867SJames Ide            t.expect(exists).not.toBeTruthy();
431740b3867SJames Ide          }
432740b3867SJames Ide        };
433740b3867SJames Ide
434740b3867SJames Ide        await FS.deleteAsync(localUri, { idempotent: true });
435740b3867SJames Ide        await assertExists(false);
436740b3867SJames Ide
437740b3867SJames Ide        let error;
438740b3867SJames Ide        try {
439740b3867SJames Ide          const { md5, uri } = await FS.downloadAsync(
440740b3867SJames Ide            'https://nonexistent-subdomain.expo.io',
441740b3867SJames Ide            localUri,
442740b3867SJames Ide            { md5: true }
443740b3867SJames Ide          );
444740b3867SJames Ide        } catch (e) {
445740b3867SJames Ide          error = e;
446740b3867SJames Ide        }
447740b3867SJames Ide        t.expect(error).toBeTruthy();
448740b3867SJames Ide        await assertExists(false);
449740b3867SJames Ide        await FS.deleteAsync(localUri, { idempotent: true });
450740b3867SJames Ide      },
451*67f55e2bSStanisław Chmiela      30000
452740b3867SJames Ide    );
453740b3867SJames Ide
454740b3867SJames Ide    t.it(
455740b3867SJames Ide      'download(404)',
456740b3867SJames Ide      async () => {
457740b3867SJames Ide        const localUri = FS.documentDirectory + 'download1.png';
458740b3867SJames Ide
459740b3867SJames Ide        const assertExists = async expectedToExist => {
460740b3867SJames Ide          let { exists } = await FS.getInfoAsync(localUri);
461740b3867SJames Ide          if (expectedToExist) {
462740b3867SJames Ide            t.expect(exists).toBeTruthy();
463740b3867SJames Ide          } else {
464740b3867SJames Ide            t.expect(exists).not.toBeTruthy();
465740b3867SJames Ide          }
466740b3867SJames Ide        };
467740b3867SJames Ide
468740b3867SJames Ide        await FS.deleteAsync(localUri, { idempotent: true });
469740b3867SJames Ide        await assertExists(false);
470740b3867SJames Ide
471740b3867SJames Ide        const { md5, uri, status } = await FS.downloadAsync('https://expo.io/404', localUri, {
472740b3867SJames Ide          md5: true,
473740b3867SJames Ide        });
474740b3867SJames Ide        await assertExists(true);
475740b3867SJames Ide        t.expect(status).toBe(404);
476740b3867SJames Ide
477740b3867SJames Ide        await FS.deleteAsync(localUri);
478740b3867SJames Ide        await assertExists(false);
479740b3867SJames Ide      },
480*67f55e2bSStanisław Chmiela      30000
481740b3867SJames Ide    );
482740b3867SJames Ide  });
483740b3867SJames Ide}
484