@appium/base-driver 8.2.2 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/build/lib/basedriver/capabilities.js +3 -1
  2. package/build/lib/basedriver/commands/find.js +4 -11
  3. package/build/lib/basedriver/commands/log.js +3 -6
  4. package/build/lib/basedriver/commands/session.js +18 -27
  5. package/build/lib/basedriver/commands/settings.js +4 -8
  6. package/build/lib/basedriver/commands/timeout.js +10 -15
  7. package/build/lib/basedriver/device-settings.js +14 -2
  8. package/build/lib/basedriver/driver.js +25 -23
  9. package/build/lib/basedriver/helpers.js +140 -84
  10. package/build/lib/express/express-logging.js +2 -2
  11. package/build/lib/express/idempotency.js +2 -2
  12. package/build/lib/helpers/capabilities.js +39 -0
  13. package/build/lib/index.js +7 -7
  14. package/build/lib/jsonwp-proxy/protocol-converter.js +19 -16
  15. package/build/lib/jsonwp-proxy/proxy.js +20 -16
  16. package/build/lib/protocol/errors.js +4 -2
  17. package/build/lib/protocol/helpers.js +3 -20
  18. package/build/lib/protocol/protocol.js +44 -45
  19. package/build/lib/protocol/routes.js +67 -1
  20. package/build/test/basedriver/capabilities-specs.js +43 -1
  21. package/build/test/basedriver/capability-specs.js +126 -167
  22. package/build/test/basedriver/commands/log-specs.js +12 -5
  23. package/build/test/basedriver/driver-tests.js +11 -14
  24. package/build/test/basedriver/helpers-specs.js +5 -1
  25. package/build/test/basedriver/timeout-specs.js +7 -9
  26. package/build/test/express/server-e2e-specs.js +10 -5
  27. package/build/test/express/server-specs.js +22 -16
  28. package/build/test/express/static-specs.js +10 -5
  29. package/build/test/jsonwp-proxy/proxy-e2e-specs.js +1 -2
  30. package/build/test/jsonwp-proxy/proxy-specs.js +1 -6
  31. package/build/test/protocol/fake-driver.js +12 -15
  32. package/build/test/protocol/protocol-e2e-specs.js +49 -103
  33. package/build/test/protocol/routes-specs.js +2 -2
  34. package/lib/basedriver/capabilities.js +3 -0
  35. package/lib/basedriver/commands/find.js +3 -6
  36. package/lib/basedriver/commands/log.js +2 -4
  37. package/lib/basedriver/commands/session.js +21 -22
  38. package/lib/basedriver/commands/settings.js +3 -5
  39. package/lib/basedriver/commands/timeout.js +9 -10
  40. package/lib/basedriver/device-settings.js +10 -1
  41. package/lib/basedriver/driver.js +29 -16
  42. package/lib/basedriver/helpers.js +201 -83
  43. package/lib/express/express-logging.js +1 -1
  44. package/lib/express/idempotency.js +1 -1
  45. package/lib/helpers/capabilities.js +25 -0
  46. package/lib/index.js +6 -4
  47. package/lib/jsonwp-proxy/protocol-converter.js +15 -18
  48. package/lib/jsonwp-proxy/proxy.js +17 -15
  49. package/lib/protocol/errors.js +1 -1
  50. package/lib/protocol/helpers.js +5 -25
  51. package/lib/protocol/protocol.js +43 -54
  52. package/lib/protocol/routes.js +60 -1
  53. package/package.json +29 -22
  54. package/test/basedriver/capabilities-specs.js +34 -2
  55. package/test/basedriver/capability-specs.js +120 -146
  56. package/test/basedriver/commands/log-specs.js +12 -3
  57. package/test/basedriver/driver-tests.js +12 -7
  58. package/test/basedriver/helpers-specs.js +4 -0
  59. package/test/basedriver/timeout-specs.js +6 -11
  60. package/build/lib/protocol/sessions-cache.js +0 -88
  61. package/lib/protocol/sessions-cache.js +0 -74
@@ -1,54 +1,47 @@
1
+ // @ts-check
2
+
3
+ import B from 'bluebird';
1
4
  import { default as BaseDriver, errors } from '../../lib';
2
5
  import logger from '../../lib/basedriver/logger';
3
- import sinon from 'sinon';
4
-
6
+ import { createSandbox } from 'sinon';
5
7
 
6
8
  describe('Desired Capabilities', function () {
7
9
  let d;
10
+ let sandbox;
8
11
 
9
12
  beforeEach(function () {
10
13
  d = new BaseDriver();
11
- sinon.spy(logger, 'warn');
14
+ sandbox = createSandbox();
15
+ sandbox.spy(d.log, 'warn');
16
+ sandbox.spy(logger, 'warn');
12
17
  });
13
18
 
14
19
  afterEach(function () {
15
- logger.warn.restore();
20
+ sandbox.restore();
16
21
  });
17
22
 
18
23
  it('should require platformName and deviceName', async function () {
19
- try {
20
- await d.createSession(null, null, {});
21
- } catch (e) {
22
- e.should.be.instanceof(errors.SessionNotCreatedError);
23
- e.message.should.contain('platformName');
24
- return;
25
- }
26
-
27
- should.fail('error should have been thrown');
24
+ await d.createSession({
25
+ firstMatch: [{}]
26
+ }).should.eventually.be.rejectedWith(errors.SessionNotCreatedError, /platformName/);
28
27
  });
29
28
 
30
29
 
31
30
  it('should require platformName', async function () {
32
- try {
33
- await d.createSession(null, null, {'deviceName': 'Delorean'});
34
- } catch (e) {
35
- e.should.be.instanceof(errors.SessionNotCreatedError);
36
- e.message.should.contain('platformName');
37
- return;
38
- }
39
-
40
- should.fail('error should have been thrown');
31
+ await d.createSession({
32
+ alwaysMatch: {
33
+ 'appium:deviceName': 'Delorean'
34
+ }
35
+ }).should.eventually.be.rejectedWith(errors.SessionNotCreatedError, /platformName/);
41
36
  });
42
37
 
43
38
  it('should not care about cap order', async function () {
44
-
45
39
  await d.createSession(null, null, {
46
40
  alwaysMatch: {
47
41
  'appium:deviceName': 'Delorean',
48
42
  platformName: 'iOS'
49
43
  }
50
- });
51
-
44
+ }).should.eventually.be.fulfilled;
52
45
  });
53
46
 
54
47
  it('should check required caps which are added to driver', async function () {
@@ -63,21 +56,12 @@ describe('Desired Capabilities', function () {
63
56
  }
64
57
  };
65
58
 
66
- try {
67
- await d.createSession(null, null, {
68
- alwaysMatch: {
69
- 'platformName': 'iOS',
70
- 'appium:deviceName': 'Delorean'
71
- }
72
- });
73
- } catch (e) {
74
- e.should.be.instanceof(errors.SessionNotCreatedError);
75
- e.message.should.contain('necessary');
76
- e.message.should.contain('proper');
77
- return;
78
- }
79
-
80
- should.fail('error should have been thrown');
59
+ await d.createSession(null, null, {
60
+ alwaysMatch: {
61
+ 'platformName': 'iOS',
62
+ 'appium:deviceName': 'Delorean'
63
+ }
64
+ }).should.eventually.be.rejectedWith(errors.SessionNotCreatedError, /necessary.*proper/);
81
65
  });
82
66
 
83
67
  it('should check added required caps in addition to base', async function () {
@@ -92,19 +76,11 @@ describe('Desired Capabilities', function () {
92
76
  }
93
77
  };
94
78
 
95
- try {
96
- await d.createSession(null, null, {
97
- alwaysMatch: {
98
- 'appium:necessary': 'yup'
99
- }
100
- });
101
- } catch (e) {
102
- e.should.be.instanceof(errors.SessionNotCreatedError);
103
- e.message.should.contain('platformName');
104
- return;
105
- }
106
-
107
- should.fail('error should have been thrown');
79
+ await d.createSession(null, null, {
80
+ alwaysMatch: {
81
+ 'appium:necessary': 'yup'
82
+ }
83
+ }).should.eventually.be.rejectedWith(errors.SessionNotCreatedError, /platformName/);
108
84
  });
109
85
 
110
86
  it('should accept extra capabilities', async function () {
@@ -115,7 +91,7 @@ describe('Desired Capabilities', function () {
115
91
  'appium:extra': 'cheese',
116
92
  'appium:hold the': 'sauce'
117
93
  }
118
- });
94
+ }).should.eventually.be.fulfilled;
119
95
  });
120
96
 
121
97
  it('should log the use of extra caps', async function () {
@@ -130,24 +106,16 @@ describe('Desired Capabilities', function () {
130
106
  }
131
107
  });
132
108
 
133
- logger.warn.callCount.should.be.above(0);
109
+ d.log.warn.should.have.been.called;
134
110
  });
135
111
 
136
112
  it('should be sensitive to the case of caps', async function () {
137
- try {
138
- await d.createSession(null, null, {
139
- alwaysMatch: {
140
- 'platformname': 'iOS',
141
- 'appium:deviceName': 'Delorean'
142
- }
143
- });
144
- } catch (e) {
145
- e.should.be.instanceof(errors.SessionNotCreatedError);
146
- e.message.should.contain('platformName');
147
- return;
148
- }
149
-
150
- should.fail('error should have been thrown');
113
+ await d.createSession(null, null, {
114
+ alwaysMatch: {
115
+ 'platformname': 'iOS',
116
+ 'appium:deviceName': 'Delorean'
117
+ }
118
+ }).should.eventually.be.rejectedWith(errors.SessionNotCreatedError, /platformName/);
151
119
  });
152
120
 
153
121
  describe('boolean capabilities', function () {
@@ -159,7 +127,7 @@ describe('Desired Capabilities', function () {
159
127
  'appium:noReset': 'false'
160
128
  }
161
129
  });
162
- logger.warn.callCount.should.be.above(0);
130
+ d.log.warn.should.have.been.called;
163
131
 
164
132
  let sessions = await d.getSessions();
165
133
  sessions[0].capabilities.noReset.should.eql(false);
@@ -173,7 +141,7 @@ describe('Desired Capabilities', function () {
173
141
  'appium:noReset': 'true'
174
142
  }
175
143
  });
176
- logger.warn.callCount.should.be.above(0);
144
+ d.log.warn.should.have.been.called;
177
145
 
178
146
  let sessions = await d.getSessions();
179
147
  sessions[0].capabilities.noReset.should.eql(true);
@@ -187,7 +155,7 @@ describe('Desired Capabilities', function () {
187
155
  'appium:language': 'true'
188
156
  }
189
157
  });
190
- logger.warn.callCount.should.equal(0);
158
+ d.log.warn.should.not.have.been.called;
191
159
 
192
160
  let sessions = await d.getSessions();
193
161
  sessions[0].capabilities.language.should.eql('true');
@@ -203,7 +171,7 @@ describe('Desired Capabilities', function () {
203
171
  'appium:newCommandTimeout': '1'
204
172
  }
205
173
  });
206
- logger.warn.callCount.should.be.above(0);
174
+ d.log.warn.should.have.been.called;
207
175
 
208
176
  let sessions = await d.getSessions();
209
177
  sessions[0].capabilities.newCommandTimeout.should.eql(1);
@@ -217,7 +185,7 @@ describe('Desired Capabilities', function () {
217
185
  'appium:newCommandTimeout': '1.1'
218
186
  }
219
187
  });
220
- logger.warn.callCount.should.be.above(0);
188
+ d.log.warn.should.have.been.called;
221
189
 
222
190
  let sessions = await d.getSessions();
223
191
  sessions[0].capabilities.newCommandTimeout.should.eql(1.1);
@@ -231,7 +199,7 @@ describe('Desired Capabilities', function () {
231
199
  'appium:language': '1'
232
200
  }
233
201
  });
234
- logger.warn.callCount.should.equal(0);
202
+ d.log.warn.should.not.have.been.called;
235
203
 
236
204
  let sessions = await d.getSessions();
237
205
  sessions[0].capabilities.language.should.eql('1');
@@ -239,20 +207,12 @@ describe('Desired Capabilities', function () {
239
207
  });
240
208
 
241
209
  it ('should error if objects in caps', async function () {
242
- try {
243
- await d.createSession(null, null, {
244
- alwaysMatch: {
245
- 'platformName': {a: 'iOS'},
246
- 'appium:deviceName': 'Delorean'
247
- }
248
- });
249
- } catch (e) {
250
- e.should.be.instanceof(errors.SessionNotCreatedError);
251
- e.message.should.contain('platformName');
252
- return;
253
- }
254
-
255
- should.fail('error should have been thrown');
210
+ await d.createSession(null, null, {
211
+ alwaysMatch: {
212
+ 'platformName': {a: 'iOS'},
213
+ 'appium:deviceName': 'Delorean'
214
+ }
215
+ }).should.eventually.be.rejectedWith(errors.SessionNotCreatedError, /platformName/i);
256
216
  });
257
217
 
258
218
  it('should check for deprecated caps', async function () {
@@ -272,7 +232,7 @@ describe('Desired Capabilities', function () {
272
232
  }
273
233
  });
274
234
 
275
- logger.warn.callCount.should.be.above(0);
235
+ logger.warn.should.have.been.called;
276
236
  });
277
237
 
278
238
  it('should not warn if deprecated=false', async function () {
@@ -292,7 +252,7 @@ describe('Desired Capabilities', function () {
292
252
  }
293
253
  });
294
254
 
295
- logger.warn.callCount.should.equal(0);
255
+ d.log.warn.should.not.have.been.called;
296
256
  });
297
257
 
298
258
  it('should not validate against null/undefined caps', async function () {
@@ -302,14 +262,17 @@ describe('Desired Capabilities', function () {
302
262
  }
303
263
  };
304
264
 
305
- await d.createSession(null, null, {
306
- alwaysMatch: {
307
- platformName: 'iOS',
308
- 'appium:deviceName': 'Dumb',
309
- 'appium:foo': null
310
- }
311
- });
312
- await d.deleteSession();
265
+ try {
266
+ await d.createSession(null, null, {
267
+ alwaysMatch: {
268
+ platformName: 'iOS',
269
+ 'appium:deviceName': 'Dumb',
270
+ 'appium:foo': null
271
+ }
272
+ });
273
+ } finally {
274
+ await d.deleteSession();
275
+ }
313
276
 
314
277
  await d.createSession(null, null, {
315
278
  alwaysMatch: {
@@ -319,23 +282,29 @@ describe('Desired Capabilities', function () {
319
282
  }
320
283
  }).should.eventually.be.rejectedWith(/'foo' must be of type string/);
321
284
 
322
- await d.createSession(null, null, {
323
- alwaysMatch: {
324
- platformName: 'iOS',
325
- 'appium:deviceName': 'Dumb',
326
- 'appium:foo': undefined
327
- }
328
- });
329
- await d.deleteSession();
285
+ try {
286
+ await d.createSession(null, null, {
287
+ alwaysMatch: {
288
+ platformName: 'iOS',
289
+ 'appium:deviceName': 'Dumb',
290
+ 'appium:foo': undefined
291
+ }
292
+ });
293
+ } finally {
294
+ await d.deleteSession();
295
+ }
330
296
 
331
- await d.createSession(null, null, {
332
- alwaysMatch: {
333
- platformName: 'iOS',
334
- 'appium:deviceName': 'Dumb',
335
- 'appium:foo': ''
336
- }
337
- });
338
- await d.deleteSession();
297
+ try {
298
+ await d.createSession(null, null, {
299
+ alwaysMatch: {
300
+ platformName: 'iOS',
301
+ 'appium:deviceName': 'Dumb',
302
+ 'appium:foo': ''
303
+ }
304
+ });
305
+ } finally {
306
+ await d.deleteSession();
307
+ }
339
308
  });
340
309
 
341
310
  it('should still validate null/undefined/empty caps whose presence is required', async function () {
@@ -353,28 +322,36 @@ describe('Desired Capabilities', function () {
353
322
  }
354
323
  }).should.eventually.be.rejectedWith(/blank/);
355
324
 
356
- await d.createSession(null, null, {
357
- platformName: 'iOS',
358
- 'appium:deviceName': 'Dumb',
359
- 'appium:foo': ''
325
+ await d.createSession(null, {
326
+ alwaysMatch: {
327
+ platformName: 'iOS',
328
+ 'appium:deviceName': 'Dumb',
329
+ 'appium:foo': ''
330
+ }
360
331
  }).should.eventually.be.rejectedWith(/blank/);
361
332
 
362
- await d.createSession(null, null, {
363
- platformName: 'iOS',
364
- 'appium:deviceName': 'Dumb',
365
- 'appium:foo': {}
333
+ await d.createSession({
334
+ firstMatch: [{
335
+ platformName: 'iOS',
336
+ 'appium:deviceName': 'Dumb',
337
+ 'appium:foo': {}
338
+ }]
366
339
  }).should.eventually.be.rejectedWith(/blank/);
367
340
 
368
- await d.createSession(null, null, {
369
- platformName: 'iOS',
370
- 'appium:deviceName': 'Dumb',
371
- 'appium:foo': []
341
+ await d.createSession({
342
+ alwaysMatch: {
343
+ platformName: 'iOS',
344
+ 'appium:deviceName': 'Dumb',
345
+ 'appium:foo': []
346
+ }
372
347
  }).should.eventually.be.rejectedWith(/blank/);
373
348
 
374
- await d.createSession(null, null, {
375
- platformName: 'iOS',
376
- 'appium:deviceName': 'Dumb',
377
- 'appium:foo': ' '
349
+ await d.createSession({
350
+ alwaysMatch: {
351
+ platformName: 'iOS',
352
+ 'appium:deviceName': 'Dumb',
353
+ 'appium:foo': ' '
354
+ }
378
355
  }).should.eventually.be.rejectedWith(/blank/);
379
356
  });
380
357
 
@@ -386,24 +363,21 @@ describe('Desired Capabilities', function () {
386
363
  'appium:deviceName': 'Delorean'
387
364
  }, firstMatch: [{}],
388
365
  });
389
- sessionId.should.exist;
390
- caps.should.eql({
391
- platformName: 'iOS',
392
- deviceName: 'Delorean',
393
- });
394
- await d.deleteSession();
366
+ try {
367
+ sessionId.should.exist;
368
+ caps.should.eql({
369
+ platformName: 'iOS',
370
+ deviceName: 'Delorean',
371
+ });
372
+ } finally {
373
+ await d.deleteSession();
374
+ }
395
375
  });
396
376
 
397
377
  it('should raise an error if w3c capabilities is not a plain JSON object', async function () {
398
- for (const val of [true, 'string', [], 100]) {
399
- try {
400
- await d.createSession(null, null, val);
401
- } catch (e) {
402
- e.should.be.instanceof(errors.SessionNotCreatedError);
403
- continue;
404
- }
405
- should.fail('error should have been thrown');
406
- }
378
+ const testValues = [true, 'string', [], 100];
379
+ // this loop runs in parallel, and does not guarantee all assertions will be made
380
+ await B.map(testValues, (val) => d.createSession(null, null, val).should.eventually.be.rejectedWith(errors.SessionNotCreatedError));
407
381
  });
408
382
  });
409
383
  });
@@ -1,5 +1,5 @@
1
1
  import logCommands from '../../../lib/basedriver/commands/log';
2
- import sinon from 'sinon';
2
+ import { createSandbox } from 'sinon';
3
3
  import _ from 'lodash';
4
4
 
5
5
 
@@ -19,10 +19,19 @@ const SUPPORTED_LOG_TYPES = {
19
19
  };
20
20
 
21
21
  describe('log commands -', function () {
22
+ let sandbox;
23
+
22
24
  beforeEach(function () {
25
+ sandbox = createSandbox();
23
26
  // reset the supported log types
24
27
  logCommands.supportedLogTypes = {};
28
+ logCommands.log = {debug: _.noop};
29
+ });
30
+
31
+ afterEach(function () {
32
+ sandbox.restore();
25
33
  });
34
+
26
35
  describe('getLogTypes', function () {
27
36
  it('should return empty array when no supported log types', async function () {
28
37
  (await logCommands.getLogTypes()).should.eql([]);
@@ -34,8 +43,8 @@ describe('log commands -', function () {
34
43
  });
35
44
  describe('getLog', function () {
36
45
  beforeEach(function () {
37
- sinon.spy(SUPPORTED_LOG_TYPES.one, 'getter');
38
- sinon.spy(SUPPORTED_LOG_TYPES.two, 'getter');
46
+ sandbox.spy(SUPPORTED_LOG_TYPES.one, 'getter');
47
+ sandbox.spy(SUPPORTED_LOG_TYPES.two, 'getter');
39
48
  });
40
49
  afterEach(function () {
41
50
  SUPPORTED_LOG_TYPES.one.getter.restore();
@@ -1,7 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import B from 'bluebird';
3
3
  import { DeviceSettings } from '../../lib';
4
- import sinon from 'sinon';
4
+ import { createSandbox } from 'sinon';
5
5
 
6
6
 
7
7
  // wrap these tests in a function so we can export the tests and re-use them
@@ -10,10 +10,14 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
10
10
  // to display the driver under test in report
11
11
  const className = DriverClass.name || '(unknown driver)';
12
12
 
13
+
13
14
  describe(`BaseDriver (as ${className})`, function () {
14
15
  let d, w3cCaps;
15
16
 
17
+ let sandbox;
18
+
16
19
  beforeEach(function () {
20
+ sandbox = createSandbox();
17
21
  d = new DriverClass();
18
22
  w3cCaps = {
19
23
  alwaysMatch: Object.assign({}, defaultCaps, {
@@ -25,6 +29,7 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
25
29
  });
26
30
  afterEach(async function () {
27
31
  await d.deleteSession();
32
+ sandbox.restore();
28
33
  });
29
34
 
30
35
  it('should report the version of BaseDriver used', function () {
@@ -345,7 +350,7 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
345
350
 
346
351
  describe('#proxyRouteIsAvoided', function () {
347
352
  it('should validate form of avoidance list', function () {
348
- const avoidStub = sinon.stub(d, 'getProxyAvoidList');
353
+ const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
349
354
  avoidStub.returns([['POST', /\/foo/], ['GET']]);
350
355
  (() => { d.proxyRouteIsAvoided(); }).should.throw;
351
356
  avoidStub.returns([['POST', /\/foo/], ['GET', /^foo/, 'bar']]);
@@ -353,31 +358,31 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
353
358
  avoidStub.restore();
354
359
  });
355
360
  it('should reject bad http methods', function () {
356
- const avoidStub = sinon.stub(d, 'getProxyAvoidList');
361
+ const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
357
362
  avoidStub.returns([['POST', /^foo/], ['BAZETE', /^bar/]]);
358
363
  (() => { d.proxyRouteIsAvoided(); }).should.throw;
359
364
  avoidStub.restore();
360
365
  });
361
366
  it('should reject non-regex routes', function () {
362
- const avoidStub = sinon.stub(d, 'getProxyAvoidList');
367
+ const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
363
368
  avoidStub.returns([['POST', /^foo/], ['GET', '/bar']]);
364
369
  (() => { d.proxyRouteIsAvoided(); }).should.throw;
365
370
  avoidStub.restore();
366
371
  });
367
372
  it('should return true for routes in the avoid list', function () {
368
- const avoidStub = sinon.stub(d, 'getProxyAvoidList');
373
+ const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
369
374
  avoidStub.returns([['POST', /^\/foo/]]);
370
375
  d.proxyRouteIsAvoided(null, 'POST', '/foo/bar').should.be.true;
371
376
  avoidStub.restore();
372
377
  });
373
378
  it('should strip away any wd/hub prefix', function () {
374
- const avoidStub = sinon.stub(d, 'getProxyAvoidList');
379
+ const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
375
380
  avoidStub.returns([['POST', /^\/foo/]]);
376
381
  d.proxyRouteIsAvoided(null, 'POST', '/foo/bar').should.be.true;
377
382
  avoidStub.restore();
378
383
  });
379
384
  it('should return false for routes not in the avoid list', function () {
380
- const avoidStub = sinon.stub(d, 'getProxyAvoidList');
385
+ const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
381
386
  avoidStub.returns([['POST', /^\/foo/]]);
382
387
  d.proxyRouteIsAvoided(null, 'GET', '/foo/bar').should.be.false;
383
388
  d.proxyRouteIsAvoided(null, 'POST', '/boo').should.be.false;
@@ -98,6 +98,10 @@ describe('helpers', function () {
98
98
  sandbox.stub(zip, 'extractAllTo').resolves();
99
99
  sandbox.stub(zip, 'assertValidZip').resolves();
100
100
  sandbox.stub(fs, 'mv').resolves();
101
+ sandbox.stub(fs, 'stat').resolves({
102
+ isFile: () => true,
103
+ isDirectory: () => false,
104
+ });
101
105
  sandbox.stub(fs, 'exists').resolves(true);
102
106
  sandbox.stub(fs, 'hash').resolves('0xDEADBEEF');
103
107
  sandbox.stub(fs, 'glob').resolves(['/path/to/an.apk']);
@@ -1,22 +1,17 @@
1
1
  import BaseDriver from '../../lib';
2
- import sinon from 'sinon';
3
-
4
-
5
-
2
+ import { createSandbox } from 'sinon';
6
3
 
7
4
  describe('timeout', function () {
8
5
  let driver = new BaseDriver();
9
- let implicitWaitSpy, newCommandTimeoutSpy;
10
- before(function () {
11
- implicitWaitSpy = sinon.spy(driver, 'setImplicitWait');
12
- newCommandTimeoutSpy = sinon.spy(driver, 'setNewCommandTimeout');
13
- });
6
+ let implicitWaitSpy;
7
+ let sandbox;
14
8
  beforeEach(function () {
9
+ sandbox = createSandbox();
15
10
  driver.implicitWaitMs = 0;
11
+ implicitWaitSpy = sandbox.spy(driver, 'setImplicitWait');
16
12
  });
17
13
  afterEach(function () {
18
- implicitWaitSpy.resetHistory();
19
- newCommandTimeoutSpy.resetHistory();
14
+ sandbox.restore();
20
15
  });
21
16
  describe('timeouts', function () {
22
17
  describe('errors', function () {
@@ -1,88 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- require("source-map-support/register");
11
-
12
- var _lruCache = _interopRequireDefault(require("lru-cache"));
13
-
14
- var _support = require("@appium/support");
15
-
16
- var _constants = require("../constants");
17
-
18
- const GENERIC_PROTOCOL = 'GENERIC';
19
-
20
- const mjsonwpLog = _support.logger.getLogger('MJSONWP');
21
-
22
- const w3cLog = _support.logger.getLogger('W3C');
23
-
24
- const genericProtocolLog = _support.logger.getLogger(GENERIC_PROTOCOL);
25
-
26
- class SessionsCache {
27
- constructor(max) {
28
- this._cache = new _lruCache.default({
29
- max
30
- });
31
- }
32
-
33
- getLogger(sessionId, protocol) {
34
- if (sessionId) {
35
- if (this._cache.has(sessionId)) {
36
- const value = this._cache.get(sessionId);
37
-
38
- if (value.logger) {
39
- return value.logger;
40
- }
41
-
42
- protocol = protocol || value.protocol;
43
- }
44
-
45
- return _support.logger.getLogger(`${protocol || GENERIC_PROTOCOL} ` + `(${sessionId.substring(0, Math.min(sessionId.length, 8))})`);
46
- }
47
-
48
- switch (protocol) {
49
- case _constants.PROTOCOLS.W3C:
50
- return w3cLog;
51
-
52
- case _constants.PROTOCOLS.MJSONWP:
53
- return mjsonwpLog;
54
-
55
- default:
56
- return genericProtocolLog;
57
- }
58
- }
59
-
60
- getProtocol(sessionId) {
61
- return (this._cache.get(sessionId) || {}).protocol;
62
- }
63
-
64
- putSession(sessionId, value) {
65
- if (sessionId && value) {
66
- this._cache.set(sessionId, {
67
- protocol: value,
68
- logger: this.getLogger(sessionId, value)
69
- });
70
- }
71
-
72
- return value;
73
- }
74
-
75
- resetLogger(sessionId) {
76
- if (this._cache.has(sessionId)) {
77
- this._cache.get(sessionId).logger = null;
78
- }
79
- }
80
-
81
- }
82
-
83
- const SESSIONS_CACHE = new SessionsCache(100);
84
- var _default = SESSIONS_CACHE;
85
- exports.default = _default;require('source-map-support').install();
86
-
87
-
88
- //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImxpYi9wcm90b2Nvb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