-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
installer-specs.js
59 lines (55 loc) · 2.11 KB
/
installer-specs.js
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
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { fs } from 'appium-support';
import { withMocks } from 'appium-test-support';
import { serverExists, UI2_SERVER_APK_PATH, UI2_TEST_APK_PATH, setupUiAutomator2 } from '../../lib/installer';
import log from '../../lib/logger';
import B from 'bluebird';
chai.should();
chai.use(chaiAsPromised);
describe('appium-uiautomator2-installer', () => {
describe.skip('setupUiAutomator2', withMocks({log}, (mocks) => {
// TODO: this is NOT a UNIT TEST. Figure out if we need it, and if so,
// how to fix it so it doesn't actually download the apks
it('should download the server APKs', async () => {
mocks.log.expects("error").never();
await setupUiAutomator2();
mocks.log.verify();
});
}));
describe('serverExists', withMocks({fs}, (mocks) => {
it('should return true if both server apk and test apk exist', async () => {
mocks.fs.expects("exists").once()
.withExactArgs(UI2_SERVER_APK_PATH)
.returns(B.resolve(true));
mocks.fs.expects("exists").once()
.withExactArgs(UI2_TEST_APK_PATH)
.returns(B.resolve(true));
(await serverExists()).should.be.true;
mocks.fs.verify();
});
it('should return false if apk does not exist', async () => {
mocks.fs.expects("exists").once()
.withExactArgs(UI2_SERVER_APK_PATH)
.returns(B.resolve(false));
(await serverExists()).should.be.false;
mocks.fs.verify();
});
it('should return false if fs.exists throws a ENOENT error', async () => {
mocks.fs.expects("exists").once()
.withExactArgs(UI2_SERVER_APK_PATH)
.throws({code:'ENOENT'});
(await serverExists()).should.be.false;
mocks.fs.verify();
});
it('should throw an error if fs.exists throws a non-ENOENT error', async () => {
let error = new Error();
error.code = 'EACCES';
mocks.fs.expects("exists").once()
.withExactArgs(UI2_SERVER_APK_PATH)
.throws(error);
await serverExists().should.eventually.be.rejectedWith(error);
mocks.fs.verify();
});
}));
});