forked from expo/expo-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
files-test.ts
65 lines (59 loc) · 1.84 KB
/
files-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { vol } from 'memfs';
import * as path from 'path';
import { downloadAppArchiveAsync, extractLocalArchiveAsync } from '../files';
jest.mock('fs');
const originalFs = jest.requireActual('fs');
jest.mock('got', () => {
return {
stream() {
return {
on() {
const fs = require('fs');
return fs.createReadStream('/apk-archive.tar.gz');
},
};
},
};
});
jest.mock('temp-dir', () => '/tmp');
jest.mock('../files', () => {
const filesModule = jest.requireActual('../files');
return {
...filesModule,
createDownloadStream() {
const fs = require('fs');
const path = require('path');
return fs.createReadStream(path.resolve('fixtures/apk-archive.tar.gz'));
},
};
});
beforeAll(async () => {
vol.mkdirpSync('/tmp');
vol.writeFileSync(
'/apk-archive.tar.gz',
originalFs.readFileSync(path.join(__dirname, 'fixtures/apk-archive.tar.gz'))
);
});
afterAll(() => {
vol.reset();
});
describe('downloadAppArchiveAsync', () => {
it(`downloads an apk to a file with the same name in a temporary directory`, async () => {
const path = await downloadAppArchiveAsync('http://fake.expo.io/app.apk');
expect(path).toMatch(/app.apk$/);
});
it(`downloads and extracts a tar to a file with the correct extension in a temporary directory`, async () => {
const path = await downloadAppArchiveAsync('http://fake.expo.io/app.tar.gz');
expect(path).toMatch(/app.tar.gz.apk$/);
});
});
describe('extractLocalArchiveAsync', () => {
it(`returns the input path if the file is not a tar`, async () => {
expect(await extractLocalArchiveAsync('/App.apk')).toBe('/App.apk');
});
it(`returns a temporary file from an extracted tar`, async () => {
expect(await extractLocalArchiveAsync('/apk-archive.tar.gz')).toMatch(
/apk-archive.tar.gz.apk$/
);
});
});