Skip to content

Commit 137aa3f

Browse files
Unit test cases fix
1 parent 3db1d90 commit 137aa3f

File tree

4 files changed

+52
-38
lines changed

4 files changed

+52
-38
lines changed

bin/helpers/capabilityHelper.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ const validate = (bsConfig, args) => {
141141
} catch(error){
142142
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
143143
}
144-
145144
resolve(cypressJson);
146145
});
147146
}

test/unit/bin/commands/runs.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ describe("runs", () => {
189189
setLocalIdentifierStub = sandbox.stub();
190190
deleteResultsStub = sandbox.stub();
191191
setDefaultAuthHashStub = sandbox.stub();
192+
getNumberOfSpecFilesStub = sandbox.stub();
192193
});
193194

194195
afterEach(() => {
@@ -217,7 +218,8 @@ describe("runs", () => {
217218
setLocal: setLocalStub,
218219
setLocalIdentifier: setLocalIdentifierStub,
219220
deleteResults: deleteResultsStub,
220-
setDefaultAuthHash: setDefaultAuthHashStub
221+
setDefaultAuthHash: setDefaultAuthHashStub,
222+
getNumberOfSpecFiles: getNumberOfSpecFilesStub
221223
},
222224
'../helpers/capabilityHelper': {
223225
validate: capabilityValidatorStub,
@@ -289,6 +291,7 @@ describe("runs", () => {
289291
setLocalIdentifierStub = sandbox.stub();
290292
deleteResultsStub = sandbox.stub();
291293
setDefaultAuthHashStub = sandbox.stub();
294+
getNumberOfSpecFilesStub = sandbox.stub();
292295
});
293296

294297
afterEach(() => {
@@ -317,7 +320,8 @@ describe("runs", () => {
317320
setLocal: setLocalStub,
318321
setLocalIdentifier: setLocalIdentifierStub,
319322
deleteResults: deleteResultsStub,
320-
setDefaultAuthHash: setDefaultAuthHashStub
323+
setDefaultAuthHash: setDefaultAuthHashStub,
324+
getNumberOfSpecFiles: getNumberOfSpecFilesStub
321325
},
322326
'../helpers/capabilityHelper': {
323327
validate: capabilityValidatorStub,
@@ -397,6 +401,7 @@ describe("runs", () => {
397401
setLocalIdentifierStub = sandbox.stub();
398402
deleteResultsStub = sandbox.stub();
399403
setDefaultAuthHashStub = sandbox.stub();
404+
getNumberOfSpecFilesStub = sandbox.stub();
400405
});
401406

402407
afterEach(() => {
@@ -425,7 +430,8 @@ describe("runs", () => {
425430
setLocal: setLocalStub,
426431
setLocalIdentifier: setLocalIdentifierStub,
427432
deleteResults: deleteResultsStub,
428-
setDefaultAuthHash: setDefaultAuthHashStub
433+
setDefaultAuthHash: setDefaultAuthHashStub,
434+
getNumberOfSpecFiles: getNumberOfSpecFilesStub
429435
},
430436
'../helpers/capabilityHelper': {
431437
validate: capabilityValidatorStub,
@@ -519,6 +525,7 @@ describe("runs", () => {
519525
isUndefinedStub = sandbox.stub();
520526
setLocalStub = sandbox.stub();
521527
setLocalIdentifierStub = sandbox.stub();
528+
getNumberOfSpecFilesStub = sandbox.stub();
522529
});
523530

524531
afterEach(() => {
@@ -532,8 +539,8 @@ describe("runs", () => {
532539
let message = `Success! ${Constants.userMessages.BUILD_CREATED} with build id: random_build_id`;
533540
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}random_build_id`;
534541

535-
const runs = proxyquire("../../../../bin/commands/runs", {
536-
"../helpers/utils": {
542+
const runs = proxyquire('../../../../bin/commands/runs', {
543+
'../helpers/utils': {
537544
validateBstackJson: validateBstackJsonStub,
538545
sendUsageReport: sendUsageReportStub,
539546
setUsername: setUsernameStub,
@@ -550,24 +557,25 @@ describe("runs", () => {
550557
exportResults: exportResultsStub,
551558
deleteResults: deleteResultsStub,
552559
setDefaultAuthHash: setDefaultAuthHashStub,
553-
isUndefined: isUndefinedStub
560+
isUndefined: isUndefinedStub,
561+
getNumberOfSpecFiles: getNumberOfSpecFilesStub
554562
},
555-
"../helpers/capabilityHelper": {
563+
'../helpers/capabilityHelper': {
556564
validate: capabilityValidatorStub,
557565
},
558-
"../helpers/archiver": {
566+
'../helpers/archiver': {
559567
archive: archiverStub,
560568
},
561-
"../helpers/fileHelpers": {
569+
'../helpers/fileHelpers': {
562570
deleteZip: deleteZipStub,
563571
},
564-
"../helpers/zipUpload": {
572+
'../helpers/zipUpload': {
565573
zipUpload: zipUploadStub,
566574
},
567-
"../helpers/build": {
575+
'../helpers/build': {
568576
createBuild: createBuildStub,
569577
},
570-
"../helpers/config": {
578+
'../helpers/config': {
571579
dashboardUrl: dashboardUrl,
572580
},
573581
});

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,7 @@ describe("capabilityHelper.js", () => {
561561
return capabilityHelper
562562
.validate(bsConfig, { parallels: undefined })
563563
.then(function (data) {
564-
chai.assert.equal(data, Constants.validationMessages.VALIDATED);
565-
})
566-
.catch((error) => {
567-
chai.assert.fail("Promise error");
564+
chai.assert.deepEqual(data, {});
568565
});
569566
});
570567

@@ -574,10 +571,7 @@ describe("capabilityHelper.js", () => {
574571
return capabilityHelper
575572
.validate(bsConfig, { parallels: undefined })
576573
.then(function (data) {
577-
chai.assert.equal(data, Constants.validationMessages.VALIDATED);
578-
})
579-
.catch((error) => {
580-
chai.assert.fail("Promise error");
574+
chai.assert.deepEqual(data, {});
581575
});
582576
});
583577

@@ -586,10 +580,7 @@ describe("capabilityHelper.js", () => {
586580
return capabilityHelper
587581
.validate(bsConfig, { parallels: 200 })
588582
.then(function (data) {
589-
chai.assert.equal(data, Constants.validationMessages.VALIDATED);
590-
})
591-
.catch((error) => {
592-
chai.assert.fail("Promise error");
583+
chai.assert.deepEqual(data, {});
593584
});
594585
});
595586

@@ -598,10 +589,7 @@ describe("capabilityHelper.js", () => {
598589
return capabilityHelper
599590
.validate(bsConfig, { parallels: -1 })
600591
.then(function (data) {
601-
chai.assert.equal(data, Constants.validationMessages.VALIDATED);
602-
})
603-
.catch((error) => {
604-
chai.assert.fail("Promise error");
592+
chai.assert.deepEqual(data, {});
605593
});
606594
});
607595

@@ -611,10 +599,7 @@ describe("capabilityHelper.js", () => {
611599
return capabilityHelper
612600
.validate(bsConfig, { parallels: -1 })
613601
.then(function (data) {
614-
chai.assert.equal(data, Constants.validationMessages.VALIDATED);
615-
})
616-
.catch((error) => {
617-
chai.assert.fail("Promise error");
602+
chai.assert.deepEqual(data, {});
618603
});
619604
});
620605

@@ -624,10 +609,7 @@ describe("capabilityHelper.js", () => {
624609
return capabilityHelper
625610
.validate(bsConfig, { parallels: -1 })
626611
.then(function (data) {
627-
chai.assert.equal(data, Constants.validationMessages.VALIDATED);
628-
})
629-
.catch((error) => {
630-
chai.assert.fail("Promise error");
612+
chai.assert.deepEqual(data, {});
631613
});
632614
});
633615
});

test/unit/bin/helpers/utils.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
'use strict';
2+
const { it } = require('mocha');
23
const path = require('path');
4+
const { sandbox } = require('sinon');
35

46
const chai = require('chai'),
57
expect = chai.expect,
68
sinon = require('sinon'),
79
chaiAsPromised = require('chai-as-promised'),
8-
fs = require('fs');
10+
fs = require('fs'),
11+
glob = require('glob');
912

1013
const utils = require('../../../../bin/helpers/utils'),
1114
constant = require('../../../../bin/helpers/constants'),
@@ -946,4 +949,26 @@ describe('utils', () => {
946949
expect(utils.isUndefined(bsConfig.auth)).to.be.true;
947950
});
948951
});
952+
953+
describe('getNumberOfSpecFiles', () => {
954+
955+
it('glob search pattern should be equal to bsConfig.run_settings.specs', () => {
956+
sinon.stub(glob, 'sync').returns(true);
957+
let bsConfig = {
958+
run_settings: {
959+
cypressConfigFilePath: 'cypressConfigFilePath',
960+
exclude: 'exclude'
961+
},
962+
};
963+
// sinon.assert.calledOnce(getNumberOfSpecFilesStub);
964+
// sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, 'specs', {
965+
// cmd: 'cypressConfigFilePath',
966+
// matchBase: true,
967+
// ignore: 'exclude',
968+
// });
969+
utils.getNumberOfSpecFiles(bsConfig,{},{});
970+
glob.sync.restore();
971+
});
972+
});
973+
949974
});

0 commit comments

Comments
 (0)