Repository navigation
Expand file tree
/
Copy pathbinaryControl.test.js
More file actions
662 lines (603 loc) · 24.8 KB
/
Copy pathbinaryControl.test.js
File metadata and controls
662 lines (603 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
const { expect, assert } = require('chai');
const sinon = require('sinon');
const tc = require('@actions/tool-cache');
const io = require('@actions/io');
const exec = require('@actions/exec');
const core = require('@actions/core');
const path = require('path');
const github = require('@actions/github');
const os = require('os');
const fs = require('fs');
const BinaryControl = require('../src/binaryControl');
const ArtifactsManager = require('../src/artifactsManager');
const constants = require('../config/constants');
const Utils = require('../src/utils');
const {
BINARY_LINKS,
LOCAL_BINARY_FOLDER,
PLATFORMS,
LOCAL_BINARY_NAME,
LOCAL_BINARY_ZIP,
LOCAL_LOG_FILE_PREFIX,
LOCAL_BINARY_TRIGGER,
RETRY_DELAY_BINARY,
ALLOWED_INPUT_VALUES: {
LOCAL_TESTING,
},
ENV_VARS: {
BROWSERSTACK_LOCAL_LOGS_FILE,
},
} = constants;
describe('Binary Control Operations', () => {
const earlierGitHubWorkspace = process.env.GITHUB_WORKSPACE;
beforeEach(() => {
process.env.GITHUB_WORKSPACE = 'some_workspace';
});
afterEach(() => {
process.env.GITHUB_WORKSPACE = earlierGitHubWorkspace;
});
context('Private Methods Behaviour', () => {
before(() => {
process.env.GITHUB_WORKSPACE = '/some/work/space';
});
after(() => {
process.env.GITHUB_WORKSPACE = '';
});
const platformAndBinary = [
{
binary: BINARY_LINKS.DARWIN,
folder: `/_work/binary/${LOCAL_BINARY_FOLDER}/darwin`,
arch: 'x64',
platform: PLATFORMS.DARWIN,
}, {
binary: BINARY_LINKS.LINUX_32,
folder: `/_work/binary/${LOCAL_BINARY_FOLDER}/linux`,
arch: 'x32',
platform: PLATFORMS.LINUX,
}, {
binary: BINARY_LINKS.LINUX_64,
folder: `/_work/binary/${LOCAL_BINARY_FOLDER}/linux`,
arch: 'x64',
platform: PLATFORMS.LINUX,
}, {
binary: BINARY_LINKS.WINDOWS,
folder: `/_work/binary/${LOCAL_BINARY_FOLDER}/win32`,
arch: 'x32',
platform: PLATFORMS.WIN32,
},
];
platformAndBinary.forEach((system) => {
it(`decides the binary and the folder based on the platform and architecture for ${system.platform} - ${system.arch}`, () => {
sinon.stub(os, 'platform').returns(system.platform);
sinon.stub(os, 'arch').returns(system.arch);
sinon.stub(path, 'resolve').returns(system.folder);
const binaryControl = new BinaryControl();
expect(binaryControl.binaryLink).to.eql(system.binary);
expect(binaryControl.binaryFolder).to.eq(system.folder);
os.platform.restore();
os.arch.restore();
path.resolve.restore();
});
});
it(`Throws error and exits the workflow if the platform is not supported`, () => {
sinon.stub(os, 'platform').returns('somePlatform');
try {
// eslint-disable-next-line no-new
new BinaryControl();
} catch (e) {
expect(e.message).to.eq('Unsupported Platform: somePlatform. No BrowserStackLocal binary found.');
}
os.platform.restore();
});
it('Makes Directory for the binary folder in recursive manner', async () => {
sinon.stub(io, 'mkdirP').returns(true);
const binaryControl = new BinaryControl();
await binaryControl._makeDirectory();
sinon.assert.calledWith(io.mkdirP, path.resolve(
process.env.GITHUB_WORKSPACE,
'..', '..', '..',
'_work',
'binary',
LOCAL_BINARY_FOLDER,
os.platform(),
));
io.mkdirP.restore();
});
context('Log File metadata', () => {
beforeEach(() => {
sinon.stub(core, 'exportVariable');
sinon.stub(github, 'context').value({
job: 'someJobName',
});
});
afterEach(() => {
delete process.env[BROWSERSTACK_LOCAL_LOGS_FILE];
core.exportVariable.restore();
});
it('Generates log-file name and path for Binary', () => {
sinon.stub(Date, 'now').returns('now');
const expectedLogFileName = `${LOCAL_LOG_FILE_PREFIX}_${github.context.job}_now.log`;
const expectedLogFilePath = path.resolve(
path.resolve(
process.env.GITHUB_WORKSPACE,
'..', '..', '..',
'_work',
'binary',
LOCAL_BINARY_FOLDER,
os.platform(),
),
expectedLogFileName,
);
const binaryControl = new BinaryControl();
binaryControl._generateLogFileMetadata();
expect(binaryControl.logFileName).to.eq(expectedLogFileName);
expect(binaryControl.logFilePath).to.eq(expectedLogFilePath);
sinon.assert.calledWith(
core.exportVariable,
BROWSERSTACK_LOCAL_LOGS_FILE,
expectedLogFileName,
);
Date.now.restore();
});
it('Fetches log-file name and generates path for Binary if logs file name was already defined', () => {
process.env[BROWSERSTACK_LOCAL_LOGS_FILE] = `${LOCAL_LOG_FILE_PREFIX}_${github.context.job}_now.log`;
const expectedLogFileName = `${LOCAL_LOG_FILE_PREFIX}_${github.context.job}_now.log`;
const expectedLogFilePath = path.resolve(
path.resolve(
process.env.GITHUB_WORKSPACE,
'..', '..', '..',
'_work',
'binary',
LOCAL_BINARY_FOLDER,
os.platform(),
),
expectedLogFileName,
);
const binaryControl = new BinaryControl();
binaryControl._generateLogFileMetadata();
expect(binaryControl.logFileName).to.eq(expectedLogFileName);
expect(binaryControl.logFilePath).to.eq(expectedLogFilePath);
sinon.assert.calledWith(
core.exportVariable,
BROWSERSTACK_LOCAL_LOGS_FILE,
expectedLogFileName,
);
});
});
context('Generates args string based on the input to Binary Control & the operation required, i.e. start/stop', () => {
beforeEach(() => {
sinon.stub(github, 'context').value({
job: 'someJobName',
});
sinon.stub(Date, 'now').returns('now');
sinon.stub(core, 'exportVariable');
process.env.GITHUB_WORKSPACE = '/some/work/space';
});
afterEach(() => {
Date.now.restore();
core.exportVariable.restore();
process.env.GITHUB_WORKSPACE = '';
});
context('Start Operation', () => {
it('with localArgs, localIdentifier, localLoggingLevel', () => {
const stateForBinary = {
accessKey: 'someKey',
localArgs: ['--arg1', 'val1', '--arg2', 'val2'],
localIdentifier: 'someIdentifier',
localLoggingLevel: 1,
localTesting: 'start',
};
const expectedLogFilePath = path.resolve(
process.env.GITHUB_WORKSPACE,
'..', '..', '..',
'_work',
'binary',
'LocalBinaryFolder',
os.platform(),
'BrowserStackLocal_someJobName_now.log',
);
const expectedFinalArgs = [
'--key', 'someKey', '--only-automate', '--ci-plugin', 'GitHubAction',
'--arg1', 'val1', '--arg2', 'val2',
'--local-identifier', 'someIdentifier', '--verbose', '1', '--log-file', expectedLogFilePath,
];
const binaryControl = new BinaryControl(stateForBinary);
binaryControl._generateArgsForBinary();
expect(binaryControl.binaryArgs).to.deep.eq(expectedFinalArgs);
});
it('with localArgs, localIdentifier', () => {
const stateForBinary = {
accessKey: 'someKey',
localArgs: ['--arg1', 'val1', '--arg2', 'val2'],
localIdentifier: 'someIdentifier',
localLoggingLevel: 0,
localTesting: 'start',
};
const expectedFinalArgs = ['--key', 'someKey', '--only-automate', '--ci-plugin', 'GitHubAction', '--arg1', 'val1', '--arg2', 'val2', '--local-identifier', 'someIdentifier'];
const binaryControl = new BinaryControl(stateForBinary);
binaryControl._generateArgsForBinary();
expect(binaryControl.binaryArgs).to.deep.eq(expectedFinalArgs);
});
it('with localArgs', () => {
const stateForBinary = {
accessKey: 'someKey',
localArgs: ['--arg1', 'val1', '--arg2', 'val2'],
localIdentifier: '',
localLoggingLevel: 0,
localTesting: 'start',
};
const expectedFinalArgs = ['--key', 'someKey', '--only-automate', '--ci-plugin', 'GitHubAction', '--arg1', 'val1', '--arg2', 'val2'];
const binaryControl = new BinaryControl(stateForBinary);
binaryControl._generateArgsForBinary();
expect(binaryControl.binaryArgs).to.deep.eq(expectedFinalArgs);
});
it('with the default args', () => {
const stateForBinary = {
accessKey: 'someKey',
localArgs: [],
localIdentifier: '',
localLoggingLevel: 0,
localTesting: 'start',
};
const expectedFinalArgs = ['--key', 'someKey', '--only-automate', '--ci-plugin', 'GitHubAction'];
const binaryControl = new BinaryControl(stateForBinary);
binaryControl._generateArgsForBinary();
expect(binaryControl.binaryArgs).to.deep.eq(expectedFinalArgs);
});
});
context('Stop operation', () => {
it('with localIdentifier', () => {
const stateForBinary = {
accessKey: 'someKey',
localArgs: [],
localIdentifier: 'someIdentifier',
localLoggingLevel: 0,
localTesting: 'stop',
};
const expectedFinalArgs = ['--key', 'someKey', '--only-automate', '--ci-plugin', 'GitHubAction', '--local-identifier', 'someIdentifier'];
const binaryControl = new BinaryControl(stateForBinary);
binaryControl._generateArgsForBinary();
expect(binaryControl.binaryArgs).to.deep.eq(expectedFinalArgs);
});
it('without localIdentifier', () => {
const stateForBinary = {
accessKey: 'someKey',
localArgs: [],
localIdentifier: '',
localLoggingLevel: 0,
localTesting: 'stop',
};
const expectedFinalArgs = ['--key', 'someKey', '--only-automate', '--ci-plugin', 'GitHubAction'];
const binaryControl = new BinaryControl(stateForBinary);
binaryControl._generateArgsForBinary();
expect(binaryControl.binaryArgs).to.deep.eq(expectedFinalArgs);
});
});
context('Invalid Operation', () => {
it('Throws error in case its not start/stop', () => {
const stateForBinary = {
accessKey: 'someKey',
localArgs: [],
localIdentifier: 'someIdentifier',
localLoggingLevel: 0,
localTesting: 'someOperation',
};
const binaryControl = new BinaryControl(stateForBinary);
assert.throw(() => {
binaryControl._generateArgsForBinary();
}, 'Invalid Binary Action');
});
});
});
context('Triggers Binary with the required operation, i.e. start/stop', () => {
let binaryControl;
beforeEach(() => {
sinon.stub(exec, 'exec');
binaryControl = new BinaryControl();
binaryControl.binaryArgs = ['someArgs'];
});
afterEach(() => {
exec.exec.restore();
});
it('Start Operation', async () => {
const response = await binaryControl._triggerBinary(LOCAL_TESTING.START);
sinon.assert.calledWith(exec.exec, LOCAL_BINARY_NAME, ['someArgs', '--daemon', 'start']);
expect(response).to.eql({
output: '',
error: '',
});
});
it('Stop Operation', async () => {
const response = await binaryControl._triggerBinary(LOCAL_TESTING.STOP);
sinon.assert.calledWith(exec.exec, LOCAL_BINARY_NAME, ['someArgs', '--daemon', 'stop']);
expect(response).to.eql({
output: '',
error: '',
});
});
});
});
context('Public Methods Behaviour', () => {
context('Downloading Binary', () => {
let binaryControl;
beforeEach(() => {
binaryControl = new BinaryControl();
sinon.stub(binaryControl, '_makeDirectory').returns(true);
binaryControl.binaryLink = 'someLink';
binaryControl.binaryFolder = 'someFolder';
sinon.stub(core, 'info');
sinon.stub(core, 'debug');
sinon.stub(core, 'addPath');
sinon.stub(io, 'rmRF');
});
afterEach(() => {
core.info.restore();
core.debug.restore();
core.addPath.restore();
io.rmRF.restore();
});
it('Downloads and sets the binary path without any error', async () => {
sinon.stub(Utils, 'checkToolInCache').returns(false);
sinon.stub(tc, 'downloadTool').returns('downloadPath');
sinon.stub(tc, 'extractZip').returns('extractedPath');
sinon.stub(tc, 'cacheDir').returns('cachedPath');
sinon.stub(binaryControl, '_removeAnyStaleBinary');
await binaryControl.downloadBinary();
sinon.assert.called(binaryControl._removeAnyStaleBinary);
tc.downloadTool.restore();
tc.extractZip.restore();
tc.cacheDir.restore();
Utils.checkToolInCache.restore();
binaryControl._removeAnyStaleBinary.restore();
});
it('Delete any stale local binary (non windows)', async () => {
binaryControl.platform = PLATFORMS.DARWIN;
await binaryControl._removeAnyStaleBinary();
const binaryZipPath = path.resolve(binaryControl.binaryFolder, LOCAL_BINARY_ZIP);
const staleBinaryPath = path.resolve(
binaryControl.binaryFolder,
`${LOCAL_BINARY_NAME}`,
);
sinon.assert.calledWith(io.rmRF, binaryZipPath);
sinon.assert.calledWith(io.rmRF, staleBinaryPath);
});
it('Delete any stale local binary (windows)', async () => {
binaryControl.platform = PLATFORMS.WIN32;
await binaryControl._removeAnyStaleBinary();
const binaryZipPath = path.resolve(binaryControl.binaryFolder, LOCAL_BINARY_ZIP);
const staleBinaryPath = path.resolve(
binaryControl.binaryFolder,
`${LOCAL_BINARY_NAME}.exe`,
);
sinon.assert.calledWith(io.rmRF, binaryZipPath);
sinon.assert.calledWith(io.rmRF, staleBinaryPath);
});
it('Uses cached binary if it already exists (was already downloaded)', async () => {
sinon.stub(Utils, 'checkToolInCache').returns('some/path/of/tool');
sinon.stub(tc, 'downloadTool').returns('downloadPath');
sinon.stub(tc, 'extractZip').returns('extractedPath');
sinon.stub(tc, 'cacheDir').returns('cachedPath');
await binaryControl.downloadBinary();
sinon.assert.calledWith(core.info, 'BrowserStackLocal binary already exists in cache. Using that instead of downloading again...');
sinon.assert.calledWith(core.addPath, 'some/path/of/tool');
sinon.assert.notCalled(tc.downloadTool);
sinon.assert.notCalled(tc.extractZip);
sinon.assert.notCalled(tc.cacheDir);
sinon.assert.notCalled(binaryControl._makeDirectory);
tc.downloadTool.restore();
tc.extractZip.restore();
tc.cacheDir.restore();
Utils.checkToolInCache.restore();
});
it('Throws error if download of Binary fails', async () => {
sinon.stub(Utils, 'checkToolInCache').returns(false);
sinon.stub(tc, 'downloadTool').throws(Error('someError'));
try {
await binaryControl.downloadBinary();
} catch (e) {
expect(e.message).to.eq('BrowserStackLocal binary could not be downloaded due to someError');
}
tc.downloadTool.restore();
Utils.checkToolInCache.restore();
});
});
context('Triggering Binary to Start/Stop Local Tunnel', () => {
let binaryControl;
beforeEach(() => {
binaryControl = new BinaryControl();
sinon.stub(binaryControl, '_generateArgsForBinary').returns(true);
sinon.stub(core, 'info');
sinon.stub(Utils, 'sleepFor');
});
afterEach(() => {
core.info.restore();
Utils.sleepFor.restore();
});
context('Starting Local Tunnel', () => {
it("Starts the local tunnel successfully (with local identifier) and gets connected if the response state is 'connected'", async () => {
const response = {
output: JSON.stringify({
state: LOCAL_BINARY_TRIGGER.START.CONNECTED,
pid: 1234,
message: 'some message',
}),
error: '',
};
sinon.stub(binaryControl, 'stateForBinary').value({
localIdentifier: 'someIdentifier',
});
sinon.stub(binaryControl, '_triggerBinary').returns(response);
await binaryControl.startBinary();
sinon.assert.calledWith(binaryControl._triggerBinary, LOCAL_TESTING.START);
sinon.assert.calledWith(core.info, 'Starting local tunnel with local-identifier=someIdentifier in daemon mode...');
sinon.assert.calledWith(core.info, 'Local tunnel status: "some message"');
});
it("Starts the local tunnel successfully (without local identifier) and gets connected if the response state is 'connected'", async () => {
const response = {
output: JSON.stringify({
state: LOCAL_BINARY_TRIGGER.START.CONNECTED,
pid: 1234,
message: 'some message',
}),
error: '',
};
sinon.stub(binaryControl, 'stateForBinary').value({
localIdentifier: '',
});
sinon.stub(binaryControl, '_triggerBinary').returns(response);
await binaryControl.startBinary();
sinon.assert.calledWith(core.info, 'Starting local tunnel in daemon mode...');
sinon.assert.calledWith(core.info, 'Local tunnel status: "some message"');
});
it("Fails and doesn't connect the local tunnel if the response state is 'disconnected' after each available tries", async () => {
const response = {
output: JSON.stringify({
state: LOCAL_BINARY_TRIGGER.START.DISCONNECTED,
pid: 1234,
message: 'some message',
}),
error: '',
};
sinon.stub(binaryControl, 'stateForBinary').value({
localIdentifier: 'someIdentifier',
});
sinon.stub(binaryControl, '_triggerBinary').returns(response);
try {
await binaryControl.startBinary();
} catch (e) {
sinon.assert.calledWith(Utils.sleepFor, RETRY_DELAY_BINARY);
sinon.assert.calledWith(core.info, 'Error in starting local tunnel: "some message". Trying again in 5 seconds...');
expect(e.message).to.eq('Local tunnel could not be started. Error message from binary: "some message"');
}
});
it("Fails and doesn't connect if binary throws an error message after each available tries", async () => {
const response = {
output: '',
error: JSON.stringify({
key: 'value',
}),
};
sinon.stub(binaryControl, 'stateForBinary').value({
localIdentifier: 'someIdentifier',
});
sinon.stub(binaryControl, '_triggerBinary').returns(response);
try {
await binaryControl.startBinary();
} catch (e) {
sinon.assert.calledWith(Utils.sleepFor, RETRY_DELAY_BINARY);
sinon.assert.calledWith(core.info, `Error in starting local tunnel: ${JSON.stringify(response.error)}. Trying again in 5 seconds...`);
expect(e.message).to.eq(`Local tunnel could not be started. Error message from binary: ${JSON.stringify(response.error)}`);
}
});
});
context('Stopping Local Tunnel', () => {
it("Stops the local tunnel successfully (with local identifier) if the response status is 'success'", async () => {
const response = {
output: JSON.stringify({
status: LOCAL_BINARY_TRIGGER.STOP.SUCCESS,
message: 'some message',
}),
error: '',
};
sinon.stub(binaryControl, 'stateForBinary').value({
localIdentifier: 'someIdentifier',
});
sinon.stub(binaryControl, '_triggerBinary').returns(response);
await binaryControl.stopBinary();
sinon.assert.calledWith(binaryControl._triggerBinary, LOCAL_TESTING.STOP);
sinon.assert.calledWith(core.info, 'Stopping local tunnel with local-identifier=someIdentifier in daemon mode...');
sinon.assert.calledWith(core.info, 'Local tunnel stopping status: some message');
});
it("Stops the local tunnel successfully (without local identifier) if the response status is 'success'", async () => {
const response = {
output: JSON.stringify({
status: LOCAL_BINARY_TRIGGER.STOP.SUCCESS,
message: 'some message',
}),
error: '',
};
sinon.stub(binaryControl, 'stateForBinary').value({
localIdentifier: '',
});
sinon.stub(binaryControl, '_triggerBinary').returns(response);
await binaryControl.stopBinary();
sinon.assert.calledWith(binaryControl._triggerBinary, LOCAL_TESTING.STOP);
sinon.assert.calledWith(core.info, 'Stopping local tunnel in daemon mode...');
sinon.assert.calledWith(core.info, 'Local tunnel stopping status: some message');
});
it("Fails while disconnecting the local tunnel if the response status is not 'success'", async () => {
const response = {
output: JSON.stringify({
status: 'someStatus',
message: 'some message',
}),
error: '',
};
sinon.stub(binaryControl, 'stateForBinary').value({
localIdentifier: '',
});
sinon.stub(binaryControl, '_triggerBinary').returns(response);
await binaryControl.stopBinary();
sinon.assert.calledWith(binaryControl._triggerBinary, LOCAL_TESTING.STOP);
sinon.assert.calledWith(core.info, 'Stopping local tunnel in daemon mode...');
sinon.assert.calledWith(core.info, '[Warning] Error in stopping local tunnel: "some message". Continuing the workflow without breaking...');
});
it("Fails while disconnecting the local tunnel if binanry thrown as error message", async () => {
const response = {
output: '',
error: JSON.stringify({
key: 'value',
}),
};
sinon.stub(binaryControl, 'stateForBinary').value({
localIdentifier: '',
});
sinon.stub(binaryControl, '_triggerBinary').returns(response);
await binaryControl.stopBinary();
sinon.assert.calledWith(binaryControl._triggerBinary, LOCAL_TESTING.STOP);
sinon.assert.calledWith(core.info, 'Stopping local tunnel in daemon mode...');
sinon.assert.calledWith(core.info, `[Warning] Error in stopping local tunnel: ${JSON.stringify(response.error)}. Continuing the workflow without breaking...`);
});
});
});
context('Uploading log files if they exists', () => {
let binaryControl;
beforeEach(() => {
binaryControl = new BinaryControl();
sinon.stub(binaryControl, '_generateLogFileMetadata');
sinon.stub(io, 'rmRF');
sinon.stub(ArtifactsManager, 'uploadArtifacts').returns(true);
sinon.stub(Utils, 'clearEnvironmentVariable');
binaryControl.logFilePath = 'somePath';
binaryControl.logFileName = 'someName';
binaryControl.binaryFolder = 'someFolderPath';
});
afterEach(() => {
io.rmRF.restore();
ArtifactsManager.uploadArtifacts.restore();
Utils.clearEnvironmentVariable.restore();
});
it('Uploads the log files if they exists', async () => {
sinon.stub(fs, 'existsSync').returns(true);
await binaryControl.uploadLogFilesIfAny();
sinon.assert.calledWith(
ArtifactsManager.uploadArtifacts,
'someName',
['somePath'],
'someFolderPath',
);
sinon.assert.calledWith(io.rmRF, 'somePath');
sinon.assert.calledWith(Utils.clearEnvironmentVariable, BROWSERSTACK_LOCAL_LOGS_FILE);
fs.existsSync.restore();
});
it("Doesn't upload the log files if they don't exist", async () => {
sinon.stub(fs, 'existsSync').returns(false);
await binaryControl.uploadLogFilesIfAny();
sinon.assert.notCalled(ArtifactsManager.uploadArtifacts);
sinon.assert.notCalled(io.rmRF);
sinon.assert.calledWith(Utils.clearEnvironmentVariable, BROWSERSTACK_LOCAL_LOGS_FILE);
fs.existsSync.restore();
});
});
});
});