Skip to content

Commit 5c7cd2e

Browse files
chore: Ditch usage of @appium/test-support (#1080)
1 parent 6bef3c2 commit 5c7cd2e

File tree

2 files changed

+35
-46
lines changed

2 files changed

+35
-46
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"homepage": "https://github.com/appium/WebDriverAgent#readme",
5050
"devDependencies": {
5151
"@appium/eslint-config-appium-ts": "^2.0.0-rc.1",
52-
"@appium/test-support": "^4.0.0-rc.1",
5352
"@appium/tsconfig": "^1.0.0-rc.1",
5453
"@appium/types": "^1.0.0-rc.1",
5554
"@semantic-release/changelog": "^6.0.1",

test/unit/utils-specs.js

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { getXctestrunFilePath, getAdditionalRunContent, getXctestrunFileName } from '../../lib/utils';
22
import { PLATFORM_NAME_IOS, PLATFORM_NAME_TVOS } from '../../lib/constants';
3-
import { withMocks } from '@appium/test-support';
43
import { fs } from '@appium/support';
54
import path from 'path';
65
import { fail } from 'assert';
76
import { arch } from 'os';
7+
import sinon from 'sinon';
88

99
function get_arch() {
1010
return arch() === 'arm64' ? 'arm64' : 'x86_64';
@@ -21,82 +21,72 @@ describe('utils', function () {
2121
chai.use(chaiAsPromised.default);
2222
});
2323

24-
describe('#getXctestrunFilePath', withMocks({fs}, function (mocks) {
24+
describe('#getXctestrunFilePath', function () {
2525
const platformVersion = '12.0';
2626
const sdkVersion = '12.2';
2727
const udid = 'xxxxxyyyyyyzzzzzz';
2828
const bootstrapPath = 'path/to/data';
2929
const platformName = PLATFORM_NAME_IOS;
30+
let sandbox;
31+
32+
beforeEach(function () {
33+
sandbox = sinon.createSandbox();
34+
});
3035

3136
afterEach(function () {
32-
mocks.verify();
37+
sandbox.restore();
3338
});
3439

3540
it('should return sdk based path with udid', async function () {
36-
mocks.fs.expects('exists')
37-
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
38-
.returns(true);
39-
mocks.fs.expects('copyFile')
40-
.never();
41+
sandbox.stub(fs, 'exists')
42+
.withArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
43+
.resolves(true);
44+
sandbox.stub(fs, 'copyFile');
4145
const deviceInfo = {isRealDevice: true, udid, platformVersion, platformName};
4246
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
4347
.should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`));
48+
sandbox.assert.notCalled(fs.copyFile);
4449
});
4550

4651
it('should return sdk based path without udid, copy them', async function () {
47-
mocks.fs.expects('exists')
48-
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
49-
.returns(false);
50-
mocks.fs.expects('exists')
51-
.withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`))
52-
.returns(true);
53-
mocks.fs.expects('copyFile')
54-
.withExactArgs(
52+
const existsStub = sandbox.stub(fs, 'exists');
53+
existsStub.withArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)).resolves(false);
54+
existsStub.withArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`)).resolves(true);
55+
sandbox.stub(fs, 'copyFile')
56+
.withArgs(
5557
path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`),
5658
path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)
5759
)
58-
.returns(true);
60+
.resolves();
5961
const deviceInfo = {isRealDevice: true, udid, platformVersion};
6062
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
6163
.should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`));
6264
});
6365

6466
it('should return platform based path', async function () {
65-
mocks.fs.expects('exists')
66-
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
67-
.returns(false);
68-
mocks.fs.expects('exists')
69-
.withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-${get_arch()}.xctestrun`))
70-
.returns(false);
71-
mocks.fs.expects('exists')
72-
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`))
73-
.returns(true);
74-
mocks.fs.expects('copyFile')
75-
.never();
67+
const existsStub = sandbox.stub(fs, 'exists');
68+
existsStub.withArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)).resolves(false);
69+
existsStub.withArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-${get_arch()}.xctestrun`)).resolves(false);
70+
existsStub.withArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)).resolves(true);
71+
sandbox.stub(fs, 'copyFile');
7672
const deviceInfo = {isRealDevice: false, udid, platformVersion};
7773
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
7874
.should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`));
75+
sandbox.assert.notCalled(fs.copyFile);
7976
});
8077

8178
it('should return platform based path without udid, copy them', async function () {
82-
mocks.fs.expects('exists')
83-
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
84-
.returns(false);
85-
mocks.fs.expects('exists')
86-
.withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-${get_arch()}.xctestrun`))
87-
.returns(false);
88-
mocks.fs.expects('exists')
89-
.withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`))
90-
.returns(false);
91-
mocks.fs.expects('exists')
92-
.withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-${get_arch()}.xctestrun`))
93-
.returns(true);
94-
mocks.fs.expects('copyFile')
95-
.withExactArgs(
79+
const existsStub = sandbox.stub(fs, 'exists');
80+
existsStub.withArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)).resolves(false);
81+
existsStub.withArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-${get_arch()}.xctestrun`)).resolves(false);
82+
existsStub.withArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)).resolves(false);
83+
existsStub.withArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-${get_arch()}.xctestrun`)).resolves(true);
84+
sandbox.stub(fs, 'copyFile')
85+
.withArgs(
9686
path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-${get_arch()}.xctestrun`),
9787
path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)
9888
)
99-
.returns(true);
89+
.resolves();
10090

10191
const deviceInfo = {isRealDevice: false, udid, platformVersion};
10292
await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
@@ -105,7 +95,7 @@ describe('utils', function () {
10595

10696
it('should raise an exception because of no files', async function () {
10797
const expected = path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-${get_arch()}.xctestrun`);
108-
mocks.fs.expects('exists').exactly(4).returns(false);
98+
sandbox.stub(fs, 'exists').resolves(false);
10999

110100
const deviceInfo = {isRealDevice: false, udid, platformVersion};
111101
try {
@@ -115,7 +105,7 @@ describe('utils', function () {
115105
err.message.should.equal(`If you are using 'useXctestrunFile' capability then you need to have a xctestrun file (expected: '${expected}')`);
116106
}
117107
});
118-
}));
108+
});
119109

120110
describe('#getAdditionalRunContent', function () {
121111
it('should return ios format', function () {

0 commit comments

Comments
 (0)