/
utils-specs.js
107 lines (97 loc) · 4.75 KB
/
utils-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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { getXctestrunFilePath } from '../../../lib/wda/utils';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { withMocks } from 'appium-test-support';
import { fs } from 'appium-support';
import path from 'path';
import { fail } from 'assert';
chai.should();
chai.use(chaiAsPromised);
describe('utils', function () {
describe('#getXctestrunFilePath', withMocks({fs}, function (mocks) {
const platformVersion = '12.0';
const sdkVersion = '12.2';
const udid = 'xxxxxyyyyyyzzzzzz';
const bootstrapPath = 'path/to/data';
afterEach(function () {
mocks.verify();
});
it('should return sdk based path with udid', async function () {
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
.returns(true);
mocks.fs.expects('copyFile')
.never();
const deviceInfo = {isRealDevice: true, udid, platformVersion};
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
.should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`));
});
it('should return sdk based path without udid, copy them', async function () {
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
.returns(false);
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`))
.returns(true);
mocks.fs.expects('copyFile')
.withExactArgs(
path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`),
path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)
)
.returns(true);
const deviceInfo = {isRealDevice: true, udid, platformVersion};
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
.should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`));
});
it('should return platform based path', async function () {
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
.returns(false);
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`))
.returns(false);
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`))
.returns(true);
mocks.fs.expects('copyFile')
.never();
const deviceInfo = {isRealDevice: false, udid, platformVersion};
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
.should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`));
});
it('should return platform based path without udid, copy them', async function () {
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
.returns(false);
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`))
.returns(false);
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`))
.returns(false);
mocks.fs.expects('exists')
.withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-x86_64.xctestrun`))
.returns(true);
mocks.fs.expects('copyFile')
.withExactArgs(
path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-x86_64.xctestrun`),
path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)
)
.returns(true);
const deviceInfo = {isRealDevice: false, udid, platformVersion};
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
.should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`));
});
it('should raise an exception because of no files', async function () {
const expected = path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`);
mocks.fs.expects('exists').exactly(4).returns(false);
const deviceInfo = {isRealDevice: false, udid, platformVersion};
try {
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath);
fail();
} catch (err) {
err.message.should.equal(`If you are using 'useXctestrunFile' capability then you need to have a xctestrun file (expected: '${expected}')`);
}
});
}));
});