browserstack-cypress-cli 1.8.0 → 1.11.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 (47) hide show
  1. package/.nyc_output/4a952689-f098-4108-8a3e-26deb80519a8.json +1 -0
  2. package/.nyc_output/97ba506f-6310-4b5c-b0cf-54cdd82c7af6.json +1 -0
  3. package/.nyc_output/processinfo/4a952689-f098-4108-8a3e-26deb80519a8.json +1 -0
  4. package/.nyc_output/processinfo/97ba506f-6310-4b5c-b0cf-54cdd82c7af6.json +1 -0
  5. package/.nyc_output/processinfo/index.json +1 -0
  6. package/bin/commands/generateDownloads.js +39 -0
  7. package/bin/commands/generateReport.js +1 -0
  8. package/bin/commands/info.js +1 -0
  9. package/bin/commands/runs.js +186 -60
  10. package/bin/commands/stop.js +3 -63
  11. package/bin/helpers/archiver.js +5 -20
  12. package/bin/helpers/buildArtifacts.js +220 -0
  13. package/bin/helpers/capabilityHelper.js +15 -22
  14. package/bin/helpers/checkUploaded.js +153 -0
  15. package/bin/helpers/config.js +3 -0
  16. package/bin/helpers/constants.js +98 -13
  17. package/bin/helpers/fileHelpers.js +14 -0
  18. package/bin/helpers/hashUtil.js +70 -0
  19. package/bin/helpers/packageInstaller.js +138 -0
  20. package/bin/helpers/reporterHTML.js +117 -9
  21. package/bin/helpers/sync/syncSpecsLogs.js +36 -8
  22. package/bin/helpers/timeComponents.js +71 -0
  23. package/bin/helpers/usageReporting.js +5 -4
  24. package/bin/helpers/utils.js +388 -9
  25. package/bin/helpers/zipUpload.js +42 -24
  26. package/bin/runner.js +108 -113
  27. package/package.json +6 -2
  28. package/test/test_files/dummy_bstack.json +0 -0
  29. package/test/test_files/dummy_bstack_2.json +0 -1
  30. package/test/test_files/dummy_bstack_3.json +0 -3
  31. package/test/unit/bin/commands/generateReport.js +0 -112
  32. package/test/unit/bin/commands/info.js +0 -374
  33. package/test/unit/bin/commands/init.js +0 -187
  34. package/test/unit/bin/commands/runs.js +0 -700
  35. package/test/unit/bin/commands/stop.js +0 -388
  36. package/test/unit/bin/helpers/archiver.js +0 -57
  37. package/test/unit/bin/helpers/build.js +0 -210
  38. package/test/unit/bin/helpers/capabilityHelper.js +0 -1049
  39. package/test/unit/bin/helpers/fileHelpers.js +0 -102
  40. package/test/unit/bin/helpers/reporterHTML.js +0 -272
  41. package/test/unit/bin/helpers/sync/failedSpecDetails.js +0 -76
  42. package/test/unit/bin/helpers/sync/specSummary.js +0 -55
  43. package/test/unit/bin/helpers/sync/syncSpecsLogs.js +0 -403
  44. package/test/unit/bin/helpers/usageReporting.js +0 -411
  45. package/test/unit/bin/helpers/utils.js +0 -1743
  46. package/test/unit/bin/helpers/zipUpload.js +0 -205
  47. package/test/unit/support/fixtures/testObjects.js +0 -149
@@ -1,1743 +0,0 @@
1
- 'use strict';
2
- const path = require('path');
3
- var sandbox = require('sinon').createSandbox();
4
-
5
- const request = require('request');
6
- const chai = require('chai'),
7
- expect = chai.expect,
8
- sinon = require('sinon'),
9
- chaiAsPromised = require('chai-as-promised'),
10
- glob = require('glob'),
11
- chalk = require('chalk'),
12
- fs = require('fs');
13
- const getmac = require('getmac').default;
14
- const usageReporting = require('../../../../bin/helpers/usageReporting');
15
- const utils = require('../../../../bin/helpers/utils'),
16
- constant = require('../../../../bin/helpers/constants'),
17
- logger = require('../../../../bin/helpers/logger').winstonLogger,
18
- testObjects = require('../../support/fixtures/testObjects'),
19
- syncLogger = require("../../../../bin/helpers/logger").syncCliLogger;
20
- const browserstack = require('browserstack-local');
21
- chai.use(chaiAsPromised);
22
- logger.transports['console.info'].silent = true;
23
-
24
- describe('utils', () => {
25
- describe('getErrorCodeFromMsg', () => {
26
- it("should return null for errMsg which isn't present in the list", () => {
27
- expect(utils.getErrorCodeFromMsg('random_value')).to.be.null;
28
- });
29
-
30
- it(`should return value depending on validation messages`, () => {
31
- expect(
32
- utils.getErrorCodeFromMsg(
33
- constant.validationMessages.EMPTY_BROWSERSTACK_JSON
34
- )
35
- ).to.eq('bstack_json_invalid_empty');
36
- expect(
37
- utils.getErrorCodeFromMsg(
38
- constant.validationMessages.INCORRECT_AUTH_PARAMS
39
- )
40
- ).to.eq('bstack_json_invalid_missing_keys');
41
- expect(
42
- utils.getErrorCodeFromMsg(
43
- constant.validationMessages.EMPTY_BROWSER_LIST
44
- )
45
- ).to.eq('bstack_json_invalid_no_browsers');
46
- expect(
47
- utils.getErrorCodeFromMsg(
48
- constant.validationMessages.EMPTY_RUN_SETTINGS
49
- )
50
- ).to.eq('bstack_json_invalid_no_run_settings');
51
- expect(
52
- utils.getErrorCodeFromMsg(
53
- constant.validationMessages.EMPTY_CYPRESS_PROJ_DIR
54
- )
55
- ).to.eq('bstack_json_invalid_no_cypress_proj_dir');
56
- expect(
57
- utils.getErrorCodeFromMsg(
58
- constant.validationMessages.INVALID_DEFAULT_AUTH_PARAMS
59
- )
60
- ).to.eq('bstack_json_default_auth_keys');
61
- expect(
62
- utils.getErrorCodeFromMsg(
63
- constant.validationMessages.INVALID_PARALLELS_CONFIGURATION
64
- )
65
- ).to.eq('invalid_parallels_specified');
66
- expect(
67
- utils.getErrorCodeFromMsg(constant.validationMessages.LOCAL_NOT_SET)
68
- ).to.eq('cypress_json_base_url_no_local');
69
- expect(
70
- utils.getErrorCodeFromMsg(
71
- constant.validationMessages.INCORRECT_DIRECTORY_STRUCTURE
72
- )
73
- ).to.eq('invalid_directory_structure');
74
- expect(
75
- utils.getErrorCodeFromMsg(
76
- 'Please use --config-file <path to browserstack.json>.'
77
- )
78
- ).to.eq('bstack_json_path_invalid');
79
- expect(
80
- utils.getErrorCodeFromMsg(
81
- constant.validationMessages.INVALID_LOCAL_IDENTIFIER
82
- )
83
- ).to.eq('invalid_local_identifier');
84
- expect(
85
- utils.getErrorCodeFromMsg(
86
- constant.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER
87
- )
88
- ).to.eq('invalid_local_identifier');
89
- expect(
90
- utils.getErrorCodeFromMsg(
91
- constant.validationMessages.INVALID_LOCAL_MODE
92
- )
93
- ).to.eq('invalid_local_mode');
94
- expect(
95
- utils.getErrorCodeFromMsg(
96
- constant.validationMessages.INVALID_LOCAL_CONFIG_FILE
97
- )
98
- ).to.eq('invalid_local_config_file');
99
- expect(
100
- utils.getErrorCodeFromMsg(
101
- "Invalid browserstack.json file."
102
- )
103
- ).to.eq("bstack_json_invalid");
104
- });
105
- });
106
-
107
- describe('isParallelValid', () => {
108
- it('should return false for a float value', () => {
109
- expect(utils.isParallelValid(1.2)).to.be.equal(false);
110
- expect(utils.isParallelValid('7.3')).to.be.equal(false);
111
- expect(utils.isParallelValid(7.33333)).to.be.equal(false);
112
- expect(utils.isParallelValid('1.2.2.2')).to.be.equal(false);
113
- expect(utils.isParallelValid('1.456789')).to.be.equal(false);
114
- });
115
-
116
- it('should return false for a string which is not a number', () => {
117
- expect(utils.isParallelValid('cypress')).to.be.equal(false);
118
- expect(utils.isParallelValid('browserstack')).to.be.equal(false);
119
- });
120
-
121
- it('should return false for any negative value less than -1 or zero', () => {
122
- expect(utils.isParallelValid(-200)).to.be.equal(false);
123
- expect(utils.isParallelValid('-200')).to.be.equal(false);
124
- expect(utils.isParallelValid(-1000)).to.be.equal(false);
125
- expect(utils.isParallelValid('0')).to.be.equal(false);
126
- expect(utils.isParallelValid(0)).to.be.equal(false);
127
- });
128
-
129
- it('should return true for any positive value or -1', () => {
130
- expect(utils.isParallelValid(5)).to.be.equal(true);
131
- expect(utils.isParallelValid('5')).to.be.equal(true);
132
- expect(utils.isParallelValid(10)).to.be.equal(true);
133
- expect(utils.isParallelValid('-1')).to.be.equal(true);
134
- expect(utils.isParallelValid(-1)).to.be.equal(true);
135
- });
136
-
137
- it('should return true for undefined', () => {
138
- expect(utils.isParallelValid(undefined)).to.be.equal(true);
139
- });
140
- });
141
-
142
- describe('isFloat', () => {
143
- it('should return true for a float value', () => {
144
- expect(utils.isFloat(1.2333)).to.be.equal(true);
145
- expect(utils.isFloat(-1.2333567)).to.be.equal(true);
146
- expect(utils.isFloat(0.123456)).to.be.equal(true);
147
- });
148
-
149
- it('should return false for a non float value', () => {
150
- expect(utils.isFloat(100)).to.be.equal(false);
151
- expect(utils.isFloat(-1000)).to.be.equal(false);
152
- expect(utils.isFloat(333)).to.be.equal(false);
153
- });
154
- });
155
-
156
- describe('isUndefined', () => {
157
- it('should return true for a undefined value', () => {
158
- expect(utils.isUndefined(undefined)).to.be.equal(true);
159
- expect(utils.isUndefined(null)).to.be.equal(true);
160
- });
161
-
162
- it('should return false for a defined value', () => {
163
- expect(utils.isUndefined(1.234)).to.be.equal(false);
164
- expect(utils.isUndefined('1.234')).to.be.equal(false);
165
- expect(utils.isUndefined(100)).to.be.equal(false);
166
- expect(utils.isUndefined(-1)).to.be.equal(false);
167
- });
168
- });
169
-
170
- describe('setParallels', () => {
171
- var sandbox;
172
- beforeEach(() => {
173
- sandbox = sinon.createSandbox();
174
- sandbox.stub(utils,'getBrowserCombinations').returns(['a','b']);
175
- });
176
-
177
- afterEach(() => {
178
- sandbox.restore();
179
- sinon.restore();
180
- });
181
-
182
- it('should set bsconfig parallels equal to value provided in args', () => {
183
- let bsConfig = {
184
- run_settings: {
185
- parallels: 10,
186
- },
187
- };
188
-
189
- utils.setParallels(bsConfig, {parallels: 100}, 100);
190
- expect(bsConfig['run_settings']['parallels']).to.be.eq(100);
191
- });
192
-
193
- it('should retain bsconfig parallels if args is undefined', () => {
194
- let bsConfig = {
195
- run_settings: {
196
- parallels: 10,
197
- },
198
- };
199
- utils.setParallels(bsConfig, {parallels: undefined}, 10);
200
- expect(bsConfig['run_settings']['parallels']).to.be.eq(10);
201
- });
202
-
203
- it('should set bsconfig parallels to browserCombinations.length if numOfSpecs is zero', () => {
204
- let bsConfig = {
205
- run_settings: {
206
- parallels: 10,
207
- },
208
- };
209
- utils.setParallels(bsConfig, {parallels: undefined}, 0);
210
- expect(bsConfig['run_settings']['parallels']).to.be.eq(2);
211
- });
212
-
213
- it('shouldnot set bsconfig parallels if parallels is -1', () => {
214
- let bsConfig = {
215
- run_settings: {
216
- parallels: -1,
217
- },
218
- };
219
- utils.setParallels(bsConfig, {parallels: undefined}, 2);
220
- expect(bsConfig['run_settings']['parallels']).to.be.eq(-1);
221
- });
222
-
223
- it('should set bsconfig parallels if parallels is greater than numOfSpecs * combinations', () => {
224
- let bsConfig = {
225
- run_settings: {
226
- parallels: 100,
227
- },
228
- };
229
- utils.setParallels(bsConfig, {parallels: undefined}, 2);
230
- expect(bsConfig['run_settings']['parallels']).to.be.eq(4);
231
- });
232
-
233
- });
234
-
235
- describe('getErrorCodeFromErr', () => {
236
- it('should return bstack_json_invalid_unknown if err.Code is not present in the list', () => {
237
- expect(utils.getErrorCodeFromErr('random_value')).to.be.eq(
238
- 'bstack_json_invalid_unknown'
239
- );
240
- });
241
-
242
- it(`should return value depending on validation messages`, () => {
243
- expect(utils.getErrorCodeFromErr({code: 'SyntaxError'})).to.eq(
244
- 'bstack_json_parse_error'
245
- );
246
- expect(utils.getErrorCodeFromErr({code: 'EACCES'})).to.eq(
247
- 'bstack_json_no_permission'
248
- );
249
- });
250
- });
251
-
252
- describe('getUserAgent', () => {
253
- it('should return string', () => {
254
- expect(utils.getUserAgent()).to.be.string;
255
- });
256
- });
257
-
258
- describe("validateBstackJson", () => {
259
- it("should reject with SyntaxError for empty file", () => {
260
- let bsConfigPath = path.join(process.cwd(), 'test', 'test_files', 'dummy_bstack.json');
261
- return utils.validateBstackJson(bsConfigPath).catch((error)=>{
262
- sinon.match(error, "Invalid browserstack.json file")
263
- });
264
- });
265
- it("should resolve with data for valid json", () => {
266
- let bsConfigPath = path.join(process.cwd(), 'test', 'test_files', 'dummy_bstack_2.json');
267
- expect(utils.validateBstackJson(bsConfigPath)).to.be.eventually.eql({});
268
- });
269
- it("should reject with SyntaxError for invalid json file", () => {
270
- let bsConfigPath = path.join(process.cwd(), 'test', 'test_files', 'dummy_bstack_3.json');
271
- return utils.validateBstackJson(bsConfigPath).catch((error) => {
272
- sinon.match(error, "Invalid browserstack.json file")
273
- });
274
- });
275
- });
276
-
277
- describe('setUsageReportingFlag', () => {
278
- beforeEach(function () {
279
- delete process.env.DISABLE_USAGE_REPORTING;
280
- });
281
-
282
- afterEach(function () {
283
- delete process.env.DISABLE_USAGE_REPORTING;
284
- });
285
-
286
- it('should set env variable if no args are defined', () => {
287
- utils.setUsageReportingFlag(undefined, undefined);
288
- expect(process.env.DISABLE_USAGE_REPORTING).to.be.eq('undefined');
289
- });
290
-
291
- it('should set DISABLE_USAGE_REPORTING=true when disableUsageReporting=true', () => {
292
- utils.setUsageReportingFlag(undefined, true);
293
- expect(process.env.DISABLE_USAGE_REPORTING).to.be.eq('true');
294
- });
295
-
296
- it('should set DISABLE_USAGE_REPORTING=false when disableUsageReporting=false', () => {
297
- utils.setUsageReportingFlag(undefined, false);
298
- expect(process.env.DISABLE_USAGE_REPORTING).to.be.eq('false');
299
- });
300
-
301
- it('should set DISABLE_USAGE_REPORTING=true if defined in bsConfig', () => {
302
- let bsConfig = {
303
- disable_usage_reporting: true,
304
- };
305
- utils.setUsageReportingFlag(bsConfig, undefined);
306
- expect(process.env.DISABLE_USAGE_REPORTING).to.be.eq('true');
307
- });
308
-
309
- it('should set DISABLE_USAGE_REPORTING=false if defined in bsConfig', () => {
310
- let bsConfig = {
311
- disable_usage_reporting: false,
312
- };
313
- utils.setUsageReportingFlag(bsConfig, undefined);
314
- expect(process.env.DISABLE_USAGE_REPORTING).to.be.eq('false');
315
- });
316
-
317
- it('should give priority to disableUsageReporting arg', () => {
318
- let bsConfig = {
319
- disable_usage_reporting: true,
320
- };
321
- utils.setUsageReportingFlag(bsConfig, false);
322
- expect(process.env.DISABLE_USAGE_REPORTING).to.be.eq('false');
323
- });
324
-
325
- it('should handle both bsConfig and disableUsageReporting arg', () => {
326
- let bsConfig = {
327
- disable_usage_reporting: true,
328
- };
329
- utils.setUsageReportingFlag(bsConfig, true);
330
- expect(process.env.DISABLE_USAGE_REPORTING).to.be.eq('true');
331
- });
332
- });
333
-
334
- describe('isAbsolute', () => {
335
- it('should return true when path is absolute', () => {
336
- expect(utils.isAbsolute('/Absolute/Path')).to.be.true;
337
- });
338
-
339
- it('should return false when path is relative', () => {
340
- expect(utils.isAbsolute('../Relative/Path')).to.be.false;
341
- });
342
- });
343
-
344
- describe('getConfigPath', () => {
345
- it('should return given path, when path is absolute', () => {
346
- expect(utils.getConfigPath('/Absolute/Path')).to.be.eq('/Absolute/Path');
347
- });
348
-
349
- it('should return path joined with current dir path, when path is relative', () => {
350
- let configPath = '../Relative/Path';
351
- expect(utils.getConfigPath(configPath)).to.be.eq(
352
- path.join(process.cwd(), configPath)
353
- );
354
- });
355
- });
356
-
357
- describe('configCreated', () => {
358
- let args = testObjects.initSampleArgs;
359
-
360
- it('should call sendUsageReport', () => {
361
- sendUsageReportStub = sandbox
362
- .stub(utils, 'sendUsageReport')
363
- .callsFake(function () {
364
- return 'end';
365
- });
366
- utils.configCreated(args);
367
- sinon.assert.calledOnce(sendUsageReportStub);
368
- sandbox.restore();
369
- sinon.restore();
370
- });
371
- });
372
-
373
- describe('setBuildName', () => {
374
- it('sets the build name from args list', () => {
375
- let argBuildName = 'argBuildName';
376
- let bsConfig = {
377
- run_settings: {
378
- build_name: 'build_name',
379
- },
380
- };
381
- let args = {
382
- 'build-name': argBuildName,
383
- };
384
-
385
- utils.setBuildName(bsConfig, args);
386
- expect(bsConfig.run_settings.build_name).to.be.eq(argBuildName);
387
- });
388
- });
389
-
390
- describe('setUsername', () => {
391
- it('sets the username from args list', () => {
392
- let argUserName = 'argUserName';
393
- let bsConfig = {
394
- auth: {
395
- username: 'username',
396
- },
397
- };
398
- let args = {
399
- username: argUserName,
400
- };
401
-
402
- utils.setUsername(bsConfig, args);
403
- expect(bsConfig.auth.username).to.be.eq(argUserName);
404
- });
405
- });
406
-
407
- describe('setAccessKey', () => {
408
- it('sets the access key from args list', () => {
409
- let argAccessKey = 'argAccessKey';
410
- let bsConfig = {
411
- auth: {
412
- access_key: 'access_key',
413
- },
414
- };
415
- let args = {
416
- key: argAccessKey,
417
- };
418
-
419
- utils.setAccessKey(bsConfig, args);
420
- expect(bsConfig.auth.access_key).to.be.eq(argAccessKey);
421
- });
422
- });
423
-
424
- describe('setUserSpecs', () => {
425
- it('sets the specs from args list without space after comma with single space in given list', () => {
426
- let argsSpecs = 'spec3, spec4';
427
- let bsConfig = {
428
- run_settings: {
429
- specs: 'spec1, spec2',
430
- },
431
- };
432
- let args = {
433
- specs: argsSpecs,
434
- };
435
-
436
- utils.setUserSpecs(bsConfig, args);
437
- expect(bsConfig.run_settings.specs).to.be.eq('spec3,spec4');
438
- });
439
-
440
- it('sets the specs from args list without space after comma with spaces in given list', () => {
441
- let argsSpecs = 'spec3 , spec4';
442
- let bsConfig = {
443
- run_settings: {
444
- specs: 'spec1, spec2',
445
- },
446
- };
447
- let args = {
448
- specs: argsSpecs,
449
- };
450
-
451
- utils.setUserSpecs(bsConfig, args);
452
- expect(bsConfig.run_settings.specs).to.be.eq('spec3,spec4');
453
- });
454
-
455
- it('sets the specs list from specs key without space after comma with once space after comma in given list', () => {
456
- let bsConfig = {
457
- run_settings: {
458
- specs: 'spec1, spec2',
459
- },
460
- };
461
- let args = {
462
- specs: null,
463
- };
464
-
465
- utils.setUserSpecs(bsConfig, args);
466
- expect(bsConfig.run_settings.specs).to.be.eq('spec1,spec2');
467
- });
468
-
469
- it('sets the specs list from specs key without space after comma with extra space in given list', () => {
470
- let bsConfig = {
471
- run_settings: {
472
- specs: 'spec1 , spec2',
473
- },
474
- };
475
- let args = {
476
- specs: null,
477
- };
478
-
479
- utils.setUserSpecs(bsConfig, args);
480
- expect(bsConfig.run_settings.specs).to.be.eq('spec1,spec2');
481
- });
482
-
483
- it('sets the specs list from specs key array without space with comma', () => {
484
- let bsConfig = {
485
- run_settings: {
486
- specs: ['spec1', 'spec2'],
487
- },
488
- };
489
- let args = {
490
- specs: null,
491
- };
492
-
493
- utils.setUserSpecs(bsConfig, args);
494
- expect(bsConfig.run_settings.specs).to.be.eq('spec1,spec2');
495
- });
496
-
497
- it('does not set the specs list if no specs key specified', () => {
498
- let bsConfig = {
499
- run_settings: {},
500
- };
501
- let args = {
502
- specs: null,
503
- };
504
-
505
- utils.setUserSpecs(bsConfig, args);
506
- expect(bsConfig.run_settings.specs).to.be.eq(null);
507
- });
508
- });
509
-
510
- describe('setTestEnvs', () => {
511
- it('sets env only from args', () => {
512
- let argsEnv = 'env3=value3, env4=value4';
513
- let bsConfig = {
514
- run_settings: {
515
- env: 'env1=value1, env2=value2',
516
- },
517
- };
518
- let args = {
519
- env: argsEnv,
520
- };
521
-
522
- utils.setTestEnvs(bsConfig, args);
523
- expect(bsConfig.run_settings.env).to.be.eq('env3=value3,env4=value4');
524
- });
525
-
526
- it('sets env from args without spaces in it', () => {
527
- let argsEnv = 'env3=value3 , env4=value4';
528
- let bsConfig = {
529
- run_settings: {
530
- env: 'env1=value1 , env2=value2',
531
- },
532
- };
533
- let args = {
534
- env: argsEnv,
535
- };
536
-
537
- utils.setTestEnvs(bsConfig, args);
538
- expect(bsConfig.run_settings.env).to.be.eq('env3=value3,env4=value4');
539
- });
540
-
541
- it('does not set env if not specified in args', () => {
542
- let argsEnv = 'env3=value3 , env4=value4';
543
- let bsConfig = {
544
- run_settings: {
545
- env: 'env1=value1 , env2=value2',
546
- },
547
- };
548
- let args = {
549
- env: null,
550
- };
551
-
552
- utils.setTestEnvs(bsConfig, args);
553
- expect(bsConfig.run_settings.env).to.be.eq(null);
554
- });
555
- });
556
-
557
- describe('fixCommaSeparatedString', () => {
558
- it('string with spaces after comma', () => {
559
- let commaString = 'string1, string2';
560
- let result = utils.fixCommaSeparatedString(commaString);
561
- expect(result).to.be.eq('string1,string2');
562
- });
563
-
564
- it('string with spaces around comma', () => {
565
- let commaString = 'string1 , string2';
566
- let result = utils.fixCommaSeparatedString(commaString);
567
- expect(result).to.be.eq('string1,string2');
568
- });
569
-
570
- it('string with 2 spaces around comma', () => {
571
- let commaString = 'string1 , string2';
572
- let result = utils.fixCommaSeparatedString(commaString);
573
- expect(result).to.be.eq('string1,string2');
574
- });
575
- });
576
-
577
- describe('setHeaded', () => {
578
- it('sets the headless to false', () => {
579
- let args = {
580
- headed: true
581
- };
582
- let bsConfig = {
583
- run_settings: {}
584
- };
585
-
586
- utils.setHeaded(bsConfig, args);
587
- expect(bsConfig.run_settings.headless).to.be.eq(false);
588
- });
589
-
590
- it('sets the headless to false', () => {
591
- let args = {
592
- headed: false
593
- };
594
- let bsConfig = {
595
- run_settings: {}
596
- };
597
-
598
- utils.setHeaded(bsConfig, args);
599
- expect(bsConfig.run_settings.headless).to.be.eq(undefined);
600
- });
601
- });
602
-
603
- describe('exportResults', () => {
604
- it('should export results to log/build_results.txt', () => {
605
- sinon.stub(fs, 'writeFileSync').returns(true);
606
- utils.exportResults('build_id', 'build_url');
607
- fs.writeFileSync.restore();
608
- });
609
-
610
- it('should log warning if write to log/build_results.txt fails', () => {
611
- let writeFileSyncStub = sinon.stub(fs, 'writeFileSync');
612
- let loggerWarnStub = sinon.stub(logger, 'warn');
613
- writeFileSyncStub.yields(new Error('Write Failed'));
614
- utils.exportResults('build_id', 'build_url');
615
- sinon.assert.calledOnce(writeFileSyncStub);
616
- sinon.assert.calledTwice(loggerWarnStub);
617
- fs.writeFileSync.restore();
618
- });
619
- });
620
-
621
- describe('deleteResults', () => {
622
- it('should delete log/build_results.txt', () => {
623
- sinon.stub(fs, 'unlink').returns(true);
624
- utils.deleteResults();
625
- fs.unlink.restore();
626
- });
627
- });
628
-
629
- describe('isCypressProjDirValid', () => {
630
- it('should return true when cypressProjDir and integrationFoldDir is same', () => {
631
- expect(utils.isCypressProjDirValid('/absolute/path', '/absolute/path')).to.be.true;
632
-
633
- // should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
634
- // expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute\\path')).to.be.true;
635
- expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute/path')).to.be.true;
636
- });
637
-
638
- it('should return true when integrationFoldDir is child directory of cypressProjDir', () => {
639
- expect(utils.isCypressProjDirValid('/absolute/path', '/absolute/path/childpath')).to.be.true;
640
-
641
- // should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
642
- // expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute\\path\\childpath')).to.be.true;
643
- expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute/path/childpath')).to.be.true;
644
- });
645
-
646
- it('should return false when integrationFoldDir is not child directory of cypressProjDir', () => {
647
- expect(utils.isCypressProjDirValid('/absolute/path', '/absolute')).to.be.false;
648
-
649
- // should be as below for windows but path.resolve thinks windows path as a filename when run on linux/mac
650
- // expect(utils.isCypressProjDirValid('C:\\absolute\\path', 'C:\\absolute')).to.be.false;
651
- expect(utils.isCypressProjDirValid('/C/absolute/path', '/C/absolute')).to.be.false;
652
- });
653
- });
654
-
655
- describe('getLocalFlag', () => {
656
- it('should return false if connectionSettings is undefined', () => {
657
- expect(utils.getLocalFlag(undefined)).to.be.false;
658
- });
659
-
660
- it('should return false if connectionSettings.local is undefined', () => {
661
- expect(utils.getLocalFlag({})).to.be.false;
662
- });
663
-
664
- it('should return false if connectionSettings.local is false', () => {
665
- expect(utils.getLocalFlag({local: false})).to.be.false;
666
- });
667
-
668
- it('should return true if connectionSettings.local is true', () => {
669
- expect(utils.getLocalFlag({local: true})).to.be.true;
670
- });
671
- });
672
-
673
- describe('setLocal', () => {
674
- afterEach(function () {
675
- sinon.restore();
676
- delete process.env.BROWSERSTACK_LOCAL;
677
- });
678
-
679
- it('bsconfig connection_settings local_inferred as true if serachforOption returns false with args local-mode true', () => {
680
- let bsConfig = {
681
- connection_settings: {
682
- }
683
- };
684
- let args = {
685
- localMode: "always-on"
686
- };
687
- let searchForOptionStub = sinon.stub(utils,"searchForOption");
688
- searchForOptionStub.returns(false);
689
- utils.setLocal(bsConfig,args);
690
- expect(bsConfig.connection_settings.local_inferred).to.be.eq(true);
691
- });
692
-
693
- it('should not change local in bsConfig if process.env.BROWSERSTACK_LOCAL is undefined', () => {
694
- let bsConfig = {
695
- connection_settings: {
696
- local: true,
697
- },
698
- };
699
- let args = {};
700
- utils.setLocal(bsConfig,args);
701
- expect(bsConfig.connection_settings.local).to.be.eq(true);
702
- });
703
-
704
- it('should change local to true in bsConfig if process.env.BROWSERSTACK_LOCAL is set to true', () => {
705
- let bsConfig = {
706
- connection_settings: {
707
- local: false,
708
- },
709
- };
710
- let args = {
711
- };
712
- process.env.BROWSERSTACK_LOCAL = true;
713
- utils.setLocal(bsConfig,args);
714
- expect(bsConfig.connection_settings.local).to.be.eq(true);
715
- });
716
-
717
- it('should change local to false in bsConfig if process.env.BROWSERSTACK_LOCAL is set to false', () => {
718
- let bsConfig = {
719
- connection_settings: {
720
- local: true,
721
- },
722
- };
723
- let args = {};
724
- process.env.BROWSERSTACK_LOCAL = false;
725
- utils.setLocal(bsConfig,args);
726
- expect(bsConfig.connection_settings.local).to.be.eq(false);
727
- });
728
-
729
- it('should change local to true in bsConfig if process.env.BROWSERSTACK_LOCAL is set to true', () => {
730
- let bsConfig = {
731
- connection_settings: {
732
- local: false,
733
- },
734
- };
735
- let args = {};
736
- process.env.BROWSERSTACK_LOCAL = true;
737
- utils.setLocal(bsConfig,args);
738
- expect(bsConfig.connection_settings.local).to.be.eq(true);
739
- });
740
-
741
- it('should set local to true in bsConfig if args is set to true & local is not set in bsConfig', () => {
742
- let bsConfig = {
743
- connection_settings: {},
744
- };
745
- let args = {
746
- local: true
747
- }
748
- utils.setLocal(bsConfig,args);
749
- expect(bsConfig.connection_settings.local).to.be.eq(true);
750
- });
751
- });
752
-
753
- describe('setLocalMode', () => {
754
-
755
- afterEach(() =>{
756
- sinon.restore();
757
- })
758
-
759
- it('if bsconfig local is true and args localMode is always-on then local_mode should be always-on' , () => {
760
- let bsConfig = {
761
- connection_settings: {
762
- local: true,
763
- local_mode: "on-demand"
764
- },
765
- };
766
- let args = {
767
- localMode: "always-on"
768
- };
769
- utils.setLocalMode(bsConfig,args);
770
- expect(bsConfig['connection_settings']['local_mode']).to.be.eq("always-on");
771
- });
772
-
773
- it('if bsconfig local mode is not always-on then local_mode should be on-demand', () => {
774
- let bsConfig = {
775
- connection_settings: {
776
- local: true,
777
- },
778
- };
779
- let args = {};
780
- utils.setLocalMode(bsConfig,args);
781
- expect(bsConfig['connection_settings']['local_mode']).to.be.eq("on-demand");
782
- });
783
-
784
- it('setLocalMode should end up setting args.sync and sync_inferred as true', () => {
785
- let bsConfig = {
786
- connection_settings: {
787
- local: true
788
- },
789
- };
790
- let args = {
791
- localMode: "always-on"
792
- }
793
- utils.setLocalMode(bsConfig,args);
794
- expect(args.sync).to.be.eq(true);
795
- expect(bsConfig.connection_settings.sync_inferred).to.be.eq(true);
796
- });
797
-
798
- it('if local_mode is not provided then the bsConfig local_mode_inferred changes to local_mode', () => {
799
- let bsConfig = {
800
- connection_settings: {
801
- local: true
802
- },
803
- };
804
- let args = {
805
- }
806
- let searchForOptionStub = sinon.stub(utils,"searchForOption");
807
- searchForOptionStub.returns(false);
808
- utils.setLocalMode(bsConfig,args);
809
- expect(bsConfig.connection_settings.local_mode_inferred).to.be.eq("on-demand");
810
- });
811
-
812
- it('if local_mode is provided then the bsConfig local_mode_inferred remains unchanged', () => {
813
- let bsConfig = {
814
- connection_settings: {
815
- local: true,
816
- local_mode: "always-on"
817
- },
818
- };
819
- let args = {
820
- }
821
- let searchForOptionStub = sinon.stub(utils,"searchForOption");
822
- searchForOptionStub.returns(true);
823
- utils.setLocalMode(bsConfig,args);
824
- expect(bsConfig.connection_settings.local_mode_inferred).to.be.undefined;
825
- });
826
- });
827
-
828
- describe('setupLocalTesting' ,() => {
829
-
830
- beforeEach(function () {
831
- sinon.restore();
832
- sandbox.restore();
833
- });
834
-
835
- afterEach(function () {
836
- sinon.restore();
837
- sandbox.restore();
838
- });
839
-
840
- it('if local is true and localIdentifier is not running and start error is raised', () => {
841
- let bsConfig = {
842
- auth: {
843
- access_key: "xyz"
844
- },
845
- connection_settings: {
846
- local: true,
847
- local_identifier: "xyz"
848
- },
849
- };
850
- let args = {};
851
- let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
852
- checkLocalIdentifierRunningStub.returns(Promise.resolve(false));
853
- let setLocalArgsStub = sinon.stub(utils,"setLocalArgs");
854
- setLocalArgsStub.returns({});
855
- let localBinaryStartStub = sandbox.stub().yields(
856
- 'Key is required to start local testing!'
857
- );
858
- let getLocalBinaryStub = sandbox.stub(utils, 'getLocalBinary').returns({
859
- start: localBinaryStartStub
860
- });
861
- let sendUsageReportStub = sandbox
862
- .stub(utils, 'sendUsageReport')
863
- .callsFake(function () {
864
- return 'end';
865
- });
866
- utils.setupLocalTesting(bsConfig,args).catch((error) => {
867
- expect(error).to.eq(constant.userMessages.LOCAL_START_FAILED);
868
- sinon.assert.calledOnce(sendUsageReportStub);
869
- sinon.assert.calledOnce(getLocalBinaryStub);
870
- });
871
- });
872
-
873
- it('if local is true and localIdentifier is not running and start error is not raised', () => {
874
- let bsConfig = {
875
- auth: {
876
- access_key: 'xyz',
877
- },
878
- connection_settings: {
879
- local: true,
880
- local_identifier: 'xyz',
881
- },
882
- };
883
- let args = {};
884
- let localArgs = {
885
- key: 'abc',
886
- localIdentifier: 'abc',
887
- daemon: true,
888
- };
889
- let checkLocalIdentifierRunningStub = sinon.stub(
890
- utils,
891
- 'checkLocalIdentifierRunning'
892
- );
893
- checkLocalIdentifierRunningStub.returns(Promise.resolve(false));
894
- let setLocalArgsStub = sinon.stub(utils, 'setLocalArgs');
895
- setLocalArgsStub.returns(localArgs);
896
-
897
- let localBinaryStartStub = sandbox.stub().yields(undefined);
898
-
899
- let getLocalBinaryStub = sandbox.stub(utils, 'getLocalBinary').returns({
900
- start: localBinaryStartStub,
901
- });
902
-
903
- let sendUsageReportStub = sandbox
904
- .stub(utils, 'sendUsageReport')
905
- .callsFake(function () {
906
- return 'end';
907
- });
908
- utils.setupLocalTesting(bsConfig, args).catch((result) => {
909
- expect(result).to.eq(undefined);
910
- sinon.assert.calledOnce(getLocalBinaryStub);
911
- });
912
- });
913
-
914
- it('if bsconfig local is true then promise should return a browserstack local object', () => {
915
- let bsConfig = {
916
- auth: {
917
- access_key: "xyz"
918
- },
919
- connection_settings: {
920
- local: true,
921
- local_identifier: "xyz"
922
- },
923
- };
924
- let args = {};
925
- let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
926
- checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
927
- return utils.setupLocalTesting(bsConfig,args).then((result) => {
928
- expect(result).to.be.eq(undefined);
929
- });
930
- });
931
- });
932
-
933
- describe('setLocalArgs', () => {
934
- it('setting up local args and returning a local_args hash', () => {
935
- let bsConfig = {
936
- auth: {
937
- access_key: "xyz"
938
- },
939
- connection_settings: {
940
- local: true,
941
- local_identifier: "on-demand",
942
- local_config_file: "./local.yml"
943
- },
944
- };
945
- let args = {};
946
- let cliVersionPathStub = sinon.stub(usageReporting, "cli_version_and_path").withArgs(bsConfig);
947
- cliVersionPathStub.returns("abc");
948
- let local_args = utils.setLocalArgs(bsConfig, args);
949
- expect(local_args["key"]).to.be.eq(bsConfig['auth']['access_key']);
950
- expect(local_args["localIdentifier"]).to.be.eq(bsConfig["connection_settings"]["local_identifier"]);
951
- expect(local_args["daemon"]).to.be.eq(true);
952
- expect(local_args["enable-logging-for-api"]).to.be.eq(true);
953
- expect(local_args['config-file']).to.be.eq(path.resolve('./local.yml'));
954
- sinon.restore();
955
- });
956
- });
957
-
958
- describe('stopLocalBinary' , () => {
959
- afterEach(function () {
960
- sinon.restore();
961
- sandbox.restore();
962
- });
963
- it('stopLocalBinary promise gets resolve with undefined' ,() => {
964
- let bsConfig = {
965
- connection_settings: {
966
- local: true
967
- }
968
- };
969
- let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
970
- checkLocalIdentifierRunningStub.returns(Promise.resolve(false));
971
- let sendUsageReportStub = sandbox
972
- .stub(utils, 'sendUsageReport')
973
- .callsFake(function () {
974
- return 'end';
975
- });
976
- return utils.stopLocalBinary(bsConfig).then((result) => {
977
- expect(result).to.be.eq(undefined);
978
- sinon.assert.calledOnce(sendUsageReportStub);
979
- });
980
- });
981
-
982
- it('stopLocalBinary promise resolves with undefined if the bs_local isRunning is false' ,() => {
983
- let bsConfig = {
984
- connection_settings: {
985
- local_mode: "on-demand"
986
- }
987
- };
988
- let isRunningStub = sandbox.stub().returns(false);
989
- let bs_local = {
990
- isRunning: isRunningStub,
991
- };
992
- let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
993
- checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
994
- return utils.stopLocalBinary(bsConfig, bs_local).then((result) => {
995
- expect(result).to.be.eq(undefined);
996
- });
997
- });
998
-
999
- it('if the bs_local isRunning is true and local_mode is always-on, then gets resolve with undefined' ,() => {
1000
- let bsConfig = {
1001
- connection_settings: {
1002
- local_mode: "always-on"
1003
- }
1004
- };
1005
- let isRunningStub = sandbox.stub().returns(true);
1006
- let bs_local = {
1007
- isRunning: isRunningStub,
1008
- }
1009
- let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
1010
- checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
1011
- return utils.stopLocalBinary(bsConfig, bs_local).then((result) => {
1012
- expect(result).to.be.eq(undefined);
1013
- });
1014
- });
1015
-
1016
- it('if the bs_local isRunning is true and local_mode is not always-on and there is no stop error, then gets resolve with undefined' ,() => {
1017
- let bsConfig = {
1018
- connection_settings: {
1019
- local_mode: "on-demand"
1020
- }
1021
- };
1022
- let isRunningStub = sandbox.stub().returns(true);
1023
- let stopStub = sandbox.stub().yields(undefined);
1024
- let bs_local = {
1025
- isRunning: isRunningStub,
1026
- stop: stopStub
1027
- }
1028
- let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
1029
- checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
1030
- return utils.stopLocalBinary(bsConfig, bs_local).then((result) => {
1031
- expect(result).to.be.eq(undefined);
1032
- });
1033
- });
1034
-
1035
- it('if the bs_local isRunning is true and local_mode is not always-on and there is stop error, then gets resolve with stop error' ,() => {
1036
- let bsConfig = {
1037
- connection_settings: {
1038
- local_mode: "on-demand"
1039
- }
1040
- };
1041
- let isRunningStub = sandbox.stub().returns(true);
1042
- let error = new Error('Local Stop Error');
1043
- let stopStub = sandbox.stub().yields(error);
1044
- let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
1045
- checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
1046
- let bs_local = {
1047
- isRunning: isRunningStub,
1048
- stop: stopStub
1049
- }
1050
- let sendUsageReportStub = sandbox
1051
- .stub(utils, 'sendUsageReport')
1052
- .callsFake(function () {
1053
- return 'end';
1054
- });
1055
- return utils.stopLocalBinary(bsConfig, bs_local, {}).then((result) => {
1056
- expect(result).to.be.eq(constant.userMessages.LOCAL_STOP_FAILED);
1057
- sinon.assert.calledOnce(sendUsageReportStub);
1058
- sinon.assert.calledOnce(stopStub);
1059
- });
1060
- });
1061
-
1062
- });
1063
-
1064
- describe('generateLocalIdentifier', () => {
1065
-
1066
- it('if the mode is always-on it returns getmac() as local-identifier', () => {
1067
- expect(utils.generateLocalIdentifier("always-on")).to.be.eq(Buffer.from(getmac()).toString("base64"));
1068
- });
1069
- it('if the mode is not always-on it returns random uuidv4 as local-identifier', () => {
1070
- let uuidv41 = utils.generateLocalIdentifier("abc");
1071
- let uuidv42 = utils.generateLocalIdentifier("abc");
1072
- expect(uuidv41 != uuidv42).to.be.eq(true);
1073
- });
1074
- });
1075
-
1076
- describe('setLocalIdentifier', () => {
1077
- beforeEach(function () {
1078
- delete process.env.BROWSERSTACK_LOCAL_IDENTIFIER;
1079
- });
1080
-
1081
- afterEach(function () {
1082
- delete process.env.BROWSERSTACK_LOCAL_IDENTIFIER;
1083
- });
1084
- it('should generate local_identifier if args.localIdentifier & process.env.BROWSERSTACK_LOCAL_IDENTIFIER is undefined', () => {
1085
- let bsConfig = {
1086
- connection_settings: {
1087
- local: true
1088
- },
1089
- };
1090
- let args = {};
1091
- let generateLocalIdentifierStub = sinon.stub(utils,"generateLocalIdentifier");
1092
- generateLocalIdentifierStub.returns("abc");
1093
- utils.setLocalIdentifier(bsConfig,args);
1094
- expect(bsConfig.connection_settings.local_identifier).to.be.eq(
1095
- "abc"
1096
- );
1097
- });
1098
-
1099
- it('should change local identifier to local_identifier in bsConfig if process.env.BROWSERSTACK_LOCAL_IDENTIFIER is set to local_identifier', () => {
1100
- let bsConfig = {
1101
- connection_settings: {
1102
- local_identifier: 'test',
1103
- },
1104
- };
1105
- let args = {};
1106
- process.env.BROWSERSTACK_LOCAL_IDENTIFIER = 'local_identifier';
1107
- utils.setLocalIdentifier(bsConfig,args);
1108
- expect(bsConfig.connection_settings.local_identifier).to.be.eq(
1109
- 'local_identifier'
1110
- );
1111
- });
1112
-
1113
- it('should set local identifier in connection_settings in bsConfig if process.env.BROWSERSTACK_LOCAL_IDENTIFIER is present & not set in bsConfig', () => {
1114
- let bsConfig = {
1115
- connection_settings: {},
1116
- };
1117
- let args = {};
1118
- process.env.BROWSERSTACK_LOCAL_IDENTIFIER = 'local_identifier';
1119
- utils.setLocalIdentifier(bsConfig,args);
1120
- expect(bsConfig.connection_settings.local_identifier).to.be.eq(
1121
- 'local_identifier'
1122
- );
1123
- });
1124
-
1125
- it('if args localIdentifier is defined then it gets assigned to bsConfig connection_settings local_identifier' , () => {
1126
- let bsConfig = {
1127
- local: true,
1128
- connection_settings: {
1129
- local_identifier: "abc"
1130
- }
1131
- };
1132
- let args = {
1133
- localIdentifier: "xyz"
1134
- };
1135
- utils.setLocalIdentifier(bsConfig, args);
1136
- expect(bsConfig.connection_settings.local_identifier).to.be.eq("xyz");
1137
- expect(bsConfig.connection_settings.local_mode).to.be.eq('always-on');
1138
- });
1139
-
1140
- it('if localIdentifier is defined then local_mode is set to always-on' , () => {
1141
- let bsConfig = {
1142
- connection_settings: {
1143
- local: true,
1144
- local_identifier: 'abc',
1145
- },
1146
- };
1147
- let args = {}
1148
- utils.setLocalIdentifier(bsConfig, args);
1149
- expect(bsConfig.connection_settings.local_identifier).to.be.eq("abc");
1150
- expect(bsConfig['connection_settings']['local_mode']).to.be.eq('always-on');
1151
- });
1152
- });
1153
-
1154
- describe('setUsername', () => {
1155
- beforeEach(function () {
1156
- delete process.env.BROWSERSTACK_USERNAME;
1157
- });
1158
-
1159
- afterEach(function () {
1160
- delete process.env.BROWSERSTACK_USERNAME;
1161
- });
1162
-
1163
- it('should set username if args.username is present', () => {
1164
- let bsConfig = {
1165
- auth: {
1166
- username: 'test',
1167
- },
1168
- };
1169
- utils.setUsername(bsConfig, {username: 'username'});
1170
- expect(bsConfig.auth.username).to.be.eq('username');
1171
- });
1172
-
1173
- it('should set username if process.env.BROWSERSTACK_USERNAME is present and args.username is not present', () => {
1174
- let bsConfig = {
1175
- auth: {
1176
- username: 'test',
1177
- },
1178
- };
1179
- process.env.BROWSERSTACK_USERNAME = 'username';
1180
- utils.setUsername(bsConfig, {});
1181
- expect(bsConfig.auth.username).to.be.eq('username');
1182
- });
1183
-
1184
- it('should set username to default if process.env.BROWSERSTACK_USERNAME and args.username is not present', () => {
1185
- let bsConfig = {
1186
- auth: {
1187
- username: 'test',
1188
- },
1189
- };
1190
- utils.setUsername(bsConfig, {});
1191
- expect(bsConfig.auth.username).to.be.eq('test');
1192
- });
1193
- });
1194
-
1195
- describe('setAccessKey', () => {
1196
- beforeEach(function () {
1197
- delete process.env.BROWSERSTACK_ACCESS_KEY;
1198
- });
1199
-
1200
- afterEach(function () {
1201
- delete process.env.BROWSERSTACK_ACCESS_KEY;
1202
- });
1203
-
1204
- it('should set access_key if args.key is present', () => {
1205
- let bsConfig = {
1206
- auth: {
1207
- access_key: 'test',
1208
- },
1209
- };
1210
- utils.setAccessKey(bsConfig, {key: 'access_key'});
1211
- expect(bsConfig.auth.access_key).to.be.eq('access_key');
1212
- });
1213
-
1214
- it('should set access_key if process.env.BROWSERSTACK_ACCESS_KEY is present and args.access_key is not present', () => {
1215
- let bsConfig = {
1216
- auth: {
1217
- access_key: 'test',
1218
- },
1219
- };
1220
- process.env.BROWSERSTACK_ACCESS_KEY = 'access_key';
1221
- utils.setAccessKey(bsConfig, {});
1222
- expect(bsConfig.auth.access_key).to.be.eq('access_key');
1223
- });
1224
-
1225
- it('should set access_key to default if process.env.BROWSERSTACK_ACCESS_KEY and args.access_key is not present', () => {
1226
- let bsConfig = {
1227
- auth: {
1228
- access_key: 'test',
1229
- },
1230
- };
1231
- utils.setAccessKey(bsConfig, {});
1232
- expect(bsConfig.auth.access_key).to.be.eq('test');
1233
- });
1234
- });
1235
-
1236
- describe('verifyCypressConfigFileOption', () => {
1237
- let utilsearchForOptionCypressConfigFileStub, userOption, testOption;
1238
-
1239
- beforeEach(function () {
1240
- utilsearchForOptionCypressConfigFileStub = sinon
1241
- .stub(utils, 'searchForOption')
1242
- .callsFake((...userOption) => {
1243
- return userOption == testOption;
1244
- });
1245
- });
1246
-
1247
- afterEach(function () {
1248
- utilsearchForOptionCypressConfigFileStub.restore();
1249
- });
1250
-
1251
- it('-ccf user option', () => {
1252
- testOption = '-ccf';
1253
- expect(utils.verifyCypressConfigFileOption()).to.be.true;
1254
- sinon.assert.calledWithExactly(
1255
- utilsearchForOptionCypressConfigFileStub,
1256
- testOption
1257
- );
1258
- });
1259
-
1260
- it('--ccf user option', () => {
1261
- testOption = '--ccf';
1262
- expect(utils.verifyCypressConfigFileOption()).to.be.true;
1263
- sinon.assert.calledWithExactly(
1264
- utilsearchForOptionCypressConfigFileStub,
1265
- testOption
1266
- );
1267
- });
1268
-
1269
- it('-cypress-config-file user option', () => {
1270
- testOption = '-cypress-config-file';
1271
- expect(utils.verifyCypressConfigFileOption()).to.be.true;
1272
- sinon.assert.calledWithExactly(
1273
- utilsearchForOptionCypressConfigFileStub,
1274
- testOption
1275
- );
1276
- });
1277
-
1278
- it('--cypress-config-file user option', () => {
1279
- testOption = '--cypress-config-file';
1280
- expect(utils.verifyCypressConfigFileOption()).to.be.true;
1281
- sinon.assert.calledWithExactly(
1282
- utilsearchForOptionCypressConfigFileStub,
1283
- testOption
1284
- );
1285
- });
1286
-
1287
- it('-cypressConfigFile user option', () => {
1288
- testOption = '-cypressConfigFile';
1289
- expect(utils.verifyCypressConfigFileOption()).to.be.true;
1290
- sinon.assert.calledWithExactly(
1291
- utilsearchForOptionCypressConfigFileStub,
1292
- testOption
1293
- );
1294
- });
1295
-
1296
- it('--cypressConfigFile user option', () => {
1297
- testOption = '--cypressConfigFile';
1298
- expect(utils.verifyCypressConfigFileOption()).to.be.true;
1299
- sinon.assert.calledWithExactly(
1300
- utilsearchForOptionCypressConfigFileStub,
1301
- testOption
1302
- );
1303
- });
1304
- });
1305
-
1306
- describe('setCypressConfigFilename', () => {
1307
- let verifyCypressConfigFileOptionStub,
1308
- ccfBool,
1309
- args,
1310
- bsConfig,
1311
- cypress_config_file;
1312
-
1313
- beforeEach(function () {
1314
- verifyCypressConfigFileOptionStub = sinon
1315
- .stub(utils, 'verifyCypressConfigFileOption')
1316
- .callsFake(() => ccfBool);
1317
-
1318
- args = {
1319
- cypressConfigFile: 'args_cypress_config_file',
1320
- };
1321
- });
1322
-
1323
- afterEach(function(){
1324
- sinon.restore();
1325
- });
1326
-
1327
- it('has user provided ccf flag', () => {
1328
- ccfBool = true;
1329
-
1330
- bsConfig = {
1331
- run_settings: {
1332
- cypress_config_file: 'run_settings_cypress_config_file',
1333
- },
1334
- };
1335
-
1336
- utils.setCypressConfigFilename(bsConfig, args);
1337
-
1338
- expect(bsConfig.run_settings.cypress_config_file).to.be.eq(
1339
- args.cypressConfigFile
1340
- );
1341
- expect(bsConfig.run_settings.cypress_config_filename).to.be.eq(
1342
- path.basename(args.cypressConfigFile)
1343
- );
1344
- expect(bsConfig.run_settings.userProvidedCypessConfigFile).to.be.true;
1345
- expect(bsConfig.run_settings.cypressConfigFilePath).to.be.eq(
1346
- bsConfig.run_settings.cypress_config_file
1347
- );
1348
- });
1349
-
1350
- it('does not have user provided ccf flag, sets the value from cypress_proj_dir', () => {
1351
- ccfBool = false;
1352
-
1353
- bsConfig = {
1354
- run_settings: {
1355
- cypress_proj_dir: 'cypress_proj_dir',
1356
- },
1357
- };
1358
-
1359
- utils.setCypressConfigFilename(bsConfig, args);
1360
-
1361
- expect(bsConfig.run_settings.cypress_config_file).to.be.eq(
1362
- args.cypressConfigFile
1363
- );
1364
- expect(bsConfig.run_settings.cypress_config_filename).to.be.eq(
1365
- path.basename(args.cypressConfigFile)
1366
- );
1367
- expect(bsConfig.run_settings.userProvidedCypessConfigFile).to.be.false;
1368
- expect(bsConfig.run_settings.cypressConfigFilePath).to.be.eq(
1369
- path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json')
1370
- );
1371
- });
1372
-
1373
- it('does not have user provided ccf flag, sets from config file', () => {
1374
- cypress_config_file = 'run_settings_cypress_config_file';
1375
- ccfBool = false;
1376
- bsConfig = {
1377
- run_settings: {
1378
- cypress_config_file: cypress_config_file,
1379
- },
1380
- };
1381
-
1382
- utils.setCypressConfigFilename(bsConfig, args);
1383
-
1384
- expect(bsConfig.run_settings.cypress_config_file).to.be.eq(
1385
- cypress_config_file
1386
- );
1387
- expect(bsConfig.run_settings.cypress_config_filename).to.be.eq(
1388
- path.basename(cypress_config_file)
1389
- );
1390
- expect(bsConfig.run_settings.userProvidedCypessConfigFile).to.be.true;
1391
- expect(bsConfig.run_settings.cypressConfigFilePath).to.be.eq(
1392
- bsConfig.run_settings.cypress_config_file
1393
- );
1394
- });
1395
-
1396
- afterEach(function () {
1397
- verifyCypressConfigFileOptionStub.restore();
1398
- });
1399
- });
1400
-
1401
- describe('setDefaults', () => {
1402
- beforeEach(function () {
1403
- delete process.env.BROWSERSTACK_USERNAME;
1404
- });
1405
-
1406
- afterEach(function () {
1407
- delete process.env.BROWSERSTACK_USERNAME;
1408
- });
1409
-
1410
- it('should set setDefaults if args.username is present', () => {
1411
- let bsConfig = { run_settings: {} };
1412
- utils.setDefaults(bsConfig, {username: 'username'});
1413
- expect(utils.isUndefined(bsConfig.auth)).to.be.false;
1414
- expect(utils.isUndefined(bsConfig.run_settings.npm_dependencies)).to.be.false;
1415
- });
1416
-
1417
- it('should set setDefaults if process.env.BROWSERSTACK_USERNAME is present and args.username is not present', () => {
1418
- let bsConfig = { run_settings: {} };
1419
- process.env.BROWSERSTACK_USERNAME = 'username';
1420
- utils.setDefaults(bsConfig, {});
1421
- expect(utils.isUndefined(bsConfig.auth)).to.be.false;
1422
- expect(utils.isUndefined(bsConfig.run_settings.npm_dependencies)).to.be.false;
1423
- });
1424
-
1425
- it('should not set setDefaults if process.env.BROWSERSTACK_USERNAME and args.username is not present', () => {
1426
- let bsConfig = { run_settings: {} };
1427
- utils.setDefaults(bsConfig, {});
1428
- expect(utils.isUndefined(bsConfig.auth)).to.be.true;
1429
- expect(utils.isUndefined(bsConfig.run_settings.npm_dependencies)).to.be.false;
1430
- });
1431
- });
1432
-
1433
- describe('getNumberOfSpecFiles', () => {
1434
-
1435
- it('glob search pattern should be equal to bsConfig.run_settings.specs', () => {
1436
- let getNumberOfSpecFilesStub = sinon.stub(glob, 'sync');
1437
- let bsConfig = {
1438
- run_settings: {
1439
- specs: 'specs',
1440
- cypressProjectDir: 'cypressProjectDir',
1441
- exclude: 'exclude',
1442
- },
1443
- };
1444
-
1445
- utils.getNumberOfSpecFiles(bsConfig,{},{});
1446
- sinon.assert.calledOnce(getNumberOfSpecFilesStub);
1447
- sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, 'specs', {
1448
- cwd: 'cypressProjectDir',
1449
- matchBase: true,
1450
- ignore: 'exclude',
1451
- });
1452
- glob.sync.restore();
1453
- });
1454
-
1455
- it('glob search pattern should be equal to default', () => {
1456
- let getNumberOfSpecFilesStub = sinon.stub(glob, 'sync');
1457
- let bsConfig = {
1458
- run_settings: {
1459
- cypressProjectDir: 'cypressProjectDir',
1460
- exclude: 'exclude',
1461
- },
1462
- };
1463
-
1464
- utils.getNumberOfSpecFiles(bsConfig,{},{});
1465
-
1466
- sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, `cypress/integration/**/*.+(${constant.specFileTypes.join("|")})`, {
1467
- cwd: 'cypressProjectDir',
1468
- matchBase: true,
1469
- ignore: 'exclude',
1470
- });
1471
- glob.sync.restore();
1472
- });
1473
-
1474
- it('glob search pattern should be equal to default with integrationFolder', () => {
1475
- let getNumberOfSpecFilesStub = sinon.stub(glob, 'sync');
1476
- let bsConfig = {
1477
- run_settings: {
1478
- cypressProjectDir: 'cypressProjectDir',
1479
- exclude: 'exclude',
1480
- },
1481
- };
1482
-
1483
- utils.getNumberOfSpecFiles(bsConfig, {}, { "integrationFolder": "specs"});
1484
-
1485
- sinon.assert.calledOnceWithExactly(
1486
- getNumberOfSpecFilesStub,
1487
- `specs/**/*.+(${constant.specFileTypes.join('|')})`,
1488
- {
1489
- cwd: 'cypressProjectDir',
1490
- matchBase: true,
1491
- ignore: 'exclude',
1492
- }
1493
- );
1494
- glob.sync.restore();
1495
- });
1496
- });
1497
-
1498
- describe('capitalizeFirstLetter', () => {
1499
-
1500
- it('should capitalize First Letter ', () => {
1501
- expect(utils.capitalizeFirstLetter("chrome")).to.eq("Chrome");
1502
- });
1503
-
1504
- it('should return null if value passed is null', () => {
1505
- expect(utils.capitalizeFirstLetter(null)).to.eq(null);
1506
- });
1507
-
1508
- });
1509
-
1510
- describe('sanitizeSpecsPattern', () => {
1511
-
1512
- it('should wrap pattern around {} when input is csv', () => {
1513
- expect(utils.sanitizeSpecsPattern("pattern1,pattern2")).to.eq("{pattern1,pattern2}");
1514
- });
1515
-
1516
- it('should not wrap pattern around {} when input is single glob pattern', () => {
1517
- expect(utils.sanitizeSpecsPattern("pattern3")).to.eq("pattern3");
1518
- });
1519
-
1520
- it('should return undefined when --spec is undefined', () => {
1521
- expect(utils.sanitizeSpecsPattern(undefined)).to.eq(undefined);
1522
- });
1523
- });
1524
-
1525
- describe('getBrowserCombinations', () => {
1526
-
1527
- it('returns correct number of browserCombinations for one combination', () => {
1528
- let bsConfig = {
1529
- browsers: [
1530
- {
1531
- browser: 'chrome',
1532
- os: 'OS X Mojave',
1533
- versions: ['85'],
1534
- },
1535
- ]
1536
- };
1537
- chai.assert.deepEqual(utils.getBrowserCombinations(bsConfig), ['OS X Mojave-chrome85']);
1538
- });
1539
-
1540
- it('returns correct number of browserCombinations for multiple combinations', () => {
1541
- let bsConfig = {
1542
- browsers: [
1543
- {
1544
- browser: 'chrome',
1545
- os: 'OS X Mojave',
1546
- versions: ['85'],
1547
- },
1548
- {
1549
- browser: 'chrome',
1550
- os: 'OS X Catalina',
1551
- versions: ['85','84'],
1552
- },
1553
- ],
1554
- };
1555
- chai.assert.deepEqual(utils.getBrowserCombinations(bsConfig), [
1556
- 'OS X Mojave-chrome85',
1557
- 'OS X Catalina-chrome85',
1558
- 'OS X Catalina-chrome84'
1559
- ]);
1560
- });
1561
-
1562
- });
1563
-
1564
- describe('#handleSyncExit', () => {
1565
- let processStub;
1566
- beforeEach(function () {
1567
- processStub = sinon.stub(process, 'exit');
1568
- });
1569
-
1570
- afterEach(function () {
1571
- processStub.restore();
1572
- });
1573
- it('should print network error message when exit code is set to network error code', () => {
1574
- let dashboard_url = "dashboard_url", exitCode = 2;
1575
- let getNetworkErrorMessageStub = sinon.stub(utils, 'getNetworkErrorMessage');
1576
- utils.handleSyncExit(exitCode, dashboard_url);
1577
- sinon.assert.calledOnce(getNetworkErrorMessageStub);
1578
- sinon.assert.calledOnceWithExactly(processStub, exitCode);
1579
- getNetworkErrorMessageStub.restore();
1580
- });
1581
-
1582
- it('should print dashboard link when exit code is not network error code', () => {
1583
- let dashboard_url = "dashboard_url", exitCode = 1;
1584
- let syncCliLoggerStub = sinon.stub(syncLogger, 'info');
1585
- utils.handleSyncExit(exitCode, dashboard_url);
1586
- sinon.assert.calledTwice(syncCliLoggerStub);
1587
- sinon.assert.calledOnceWithExactly(processStub, exitCode);
1588
- });
1589
- });
1590
-
1591
- describe('#getNetworkErrorMessage', () => {
1592
- it('should return the error message in red color', () => {
1593
- let dashboard_url = "dashboard_url";
1594
- let message = constant.userMessages.FATAL_NETWORK_ERROR + '\n'
1595
- + constant.userMessages.RETRY_LIMIT_EXCEEDED + '\n'
1596
- + constant.userMessages.CHECK_DASHBOARD_AT + dashboard_url
1597
- expect(utils.getNetworkErrorMessage(dashboard_url)).to.eq(chalk.red(message))
1598
- });
1599
- });
1600
-
1601
- describe('#versionChangedMessage', () => {
1602
- it('should return proper error message with placeholders replaced', () => {
1603
- let preferredVersion = "v1", actualVersion = "v2";
1604
- let message = constant.userMessages.CYPRESS_VERSION_CHANGED.replace("<preferredVersion>", preferredVersion).replace("<actualVersion>", actualVersion);
1605
- expect(utils.versionChangedMessage(preferredVersion, actualVersion)).to.eq(message)
1606
- });
1607
- })
1608
-
1609
- describe('#isJSONInvalid', () => {
1610
- it('JSON is valid when error is parallel misconfiguration', () => {
1611
- let error = constant.validationMessages.INVALID_PARALLELS_CONFIGURATION;
1612
- let args = {"parallels": 4}
1613
- expect(utils.isJSONInvalid(error, args)).to.eq(false)
1614
- });
1615
-
1616
- it('JSON is valid when local is not set for localhost url', () => {
1617
- let error = constant.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", "localhost:4000");
1618
- expect(utils.isJSONInvalid(error, {})).to.eq(false)
1619
- });
1620
-
1621
- it('JSON is invalid for errors apart from Local or Prallell misconfiguration', () => {
1622
- let error = constant.validationMessages.INCORRECT_AUTH_PARAMS;
1623
- expect(utils.isJSONInvalid(error, {})).to.eq(true)
1624
- });
1625
-
1626
- it('JSON is invalid if local identifier is invalid', () =>{
1627
- let error = constant.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER;
1628
- expect(utils.isJSONInvalid(error,{})).to.eq(false);
1629
- });
1630
-
1631
- it('JSON is invalid if local mode is invalid', () =>{
1632
- let error = constant.validationMessages.INVALID_LOCAL_MODE;
1633
- expect(utils.isJSONInvalid(error,{})).to.eq(false);
1634
- });
1635
- })
1636
-
1637
- describe('#deleteBaseUrlFromError', () => {
1638
- it('Replace baseUrl in Local error string', () => {
1639
- let error = constant.validationMessages.LOCAL_NOT_SET;
1640
- expect(utils.deleteBaseUrlFromError(error)).to.match(/To test on BrowserStack/)
1641
- });
1642
-
1643
- it('should not replace baseUrl in other error string', () => {
1644
- let error = constant.validationMessages.NOT_VALID_JSON;
1645
- expect(utils.deleteBaseUrlFromError(error)).not.to.match(/To test on BrowserStack/)
1646
- });
1647
- });
1648
-
1649
- describe('#checkLocalIdentifierRunning', () => {
1650
- afterEach(() =>{
1651
- sinon.restore();
1652
- });
1653
- it('if the bsConfig localIdentifier is not present within the response body then function should resolve with false' , () => {
1654
- const responseObject = {
1655
- statusCode: 200,
1656
- headers: {
1657
- 'content-type': 'application/json'
1658
- }
1659
- };
1660
- const responseBody = {
1661
- status: 'success',
1662
- instances: [
1663
- {
1664
- localIdentifier: 'abcdef',
1665
- },
1666
- {
1667
- localIdentifier: 'ghij',
1668
- },
1669
- {
1670
- localIdentifier: 'lmno',
1671
- }
1672
- ]
1673
- };
1674
- sinon.stub(request, 'get')
1675
- .yields(undefined, responseObject, JSON.stringify(responseBody));
1676
-
1677
- let bsConfig = {
1678
- auth: {
1679
- access_key: "abcd",
1680
- username: "abcd"
1681
- }
1682
- };
1683
-
1684
- let localIdentifier = "abcd";
1685
- return utils.checkLocalIdentifierRunning(bsConfig, localIdentifier).then((result) => {
1686
- expect(result).to.be.eq(false);
1687
- });
1688
- });
1689
-
1690
- it('if the bsConfig localIdentifier if present within the response body then the function should resolve with true' , () => {
1691
- const responseObject = {
1692
- statusCode: 200,
1693
- headers: {
1694
- 'content-type': 'application/json'
1695
- }
1696
- };
1697
- const responseBody = {
1698
- status: 'success',
1699
- instances: [
1700
- {
1701
- localIdentifier: 'abcdef',
1702
- },
1703
- {
1704
- localIdentifier: 'ghij',
1705
- },
1706
- {
1707
- localIdentifier: 'lmno',
1708
- }
1709
- ]
1710
- };
1711
- sinon.stub(request, 'get')
1712
- .yields(undefined, responseObject, JSON.stringify(responseBody));
1713
-
1714
- let bsConfig = {
1715
- auth: {
1716
- access_key: "abcd",
1717
- username: "abcd"
1718
- }
1719
- };
1720
-
1721
- let localIdentifier = "lmno";
1722
- return utils.checkLocalIdentifierRunning(bsConfig, localIdentifier).then((result) => {
1723
- expect(result).to.be.eq(true);
1724
- });
1725
- });
1726
- });
1727
-
1728
- describe('setLocalConfigFile', () => {
1729
- it('the args localConfigfile should be assigned to bsconfig connection_settigs local_config_file', () => {
1730
- let bsConfig = {
1731
- connection_settings: {
1732
- local_config_file: "efgh"
1733
- }
1734
- };
1735
- let args = {
1736
- localConfigFile: "abcd"
1737
- };
1738
- utils.setLocalConfigFile(bsConfig, args);
1739
- expect(args.localConfigFile).to.be.eql(bsConfig.connection_settings.local_config_file);
1740
- });
1741
- });
1742
-
1743
- });