Skip to content

Commit c075a8d

Browse files
committed
add specs
1 parent 6d0032e commit c075a8d

File tree

3 files changed

+212
-5
lines changed

3 files changed

+212
-5
lines changed

test/unit/bin/commands/runs.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ describe("runs", () => {
120120
setGeolocationStub = sandbox.stub();
121121
setSpecTimeoutStub = sandbox.stub().returns(undefined);
122122
setRecordCapsStub = sandbox.stub().returns(undefined);
123+
setNodeVersionStub = sandbox.stub();
123124
});
124125

125126
afterEach(() => {
@@ -163,7 +164,8 @@ describe("runs", () => {
163164
setGeolocation: setGeolocationStub,
164165
setSpecTimeout: setSpecTimeoutStub,
165166
setRecordCaps: setRecordCapsStub,
166-
setDebugMode: setDebugModeStub
167+
setDebugMode: setDebugModeStub,
168+
setNodeVersion: setNodeVersionStub
167169
},
168170
'../helpers/capabilityHelper': {
169171
validate: capabilityValidatorStub
@@ -206,6 +208,7 @@ describe("runs", () => {
206208
sinon.assert.calledOnce(setGeolocationStub);
207209
sinon.assert.calledOnce(setSpecTimeoutStub);
208210
sinon.assert.calledOnce(setRecordCapsStub);
211+
sinon.assert.calledOnce(setNodeVersionStub);
209212
sinon.assert.calledOnceWithExactly(
210213
sendUsageReportStub,
211214
bsConfig,
@@ -265,6 +268,7 @@ describe("runs", () => {
265268
getVideoConfigStub = sandbox.stub();
266269
setSpecTimeoutStub = sandbox.stub().returns(undefined);
267270
setRecordCapsStub = sandbox.stub().returns(undefined);
271+
setNodeVersionStub = sandbox.stub();
268272
});
269273

270274
afterEach(() => {
@@ -311,7 +315,8 @@ describe("runs", () => {
311315
getVideoConfig: getVideoConfigStub,
312316
setSpecTimeout: setSpecTimeoutStub,
313317
setRecordCaps: setRecordCapsStub,
314-
setDebugMode: setDebugModeStub
318+
setDebugMode: setDebugModeStub,
319+
setNodeVersion: setNodeVersionStub
315320
},
316321
'../helpers/capabilityHelper': {
317322
validate: capabilityValidatorStub,
@@ -373,6 +378,7 @@ describe("runs", () => {
373378
sinon.assert.calledOnce(setGeolocationStub);
374379
sinon.assert.calledOnce(setSpecTimeoutStub);
375380
sinon.assert.calledOnce(setRecordCapsStub);
381+
sinon.assert.calledOnce(setNodeVersionStub);
376382
sinon.assert.calledOnceWithExactly(
377383
sendUsageReportStub,
378384
bsConfig,
@@ -434,6 +440,7 @@ describe("runs", () => {
434440
getVideoConfigStub = sandbox.stub();
435441
setSpecTimeoutStub = sandbox.stub().returns(undefined);
436442
setRecordCapsStub = sandbox.stub().returns(undefined);
443+
setNodeVersionStub = sandbox.stub();
437444
});
438445

439446
afterEach(() => {
@@ -481,7 +488,8 @@ describe("runs", () => {
481488
getVideoConfig: getVideoConfigStub,
482489
setSpecTimeout: setSpecTimeoutStub,
483490
setRecordCaps: setRecordCapsStub,
484-
setDebugMode: setDebugModeStub
491+
setDebugMode: setDebugModeStub,
492+
setNodeVersion: setNodeVersionStub
485493
},
486494
'../helpers/capabilityHelper': {
487495
validate: capabilityValidatorStub,
@@ -545,6 +553,7 @@ describe("runs", () => {
545553
sinon.assert.calledOnce(setGeolocationStub);
546554
sinon.assert.calledOnce(setSpecTimeoutStub);
547555
sinon.assert.calledOnce(setRecordCapsStub);
556+
sinon.assert.calledOnce(setNodeVersionStub);
548557
sinon.assert.calledOnceWithExactly(
549558
sendUsageReportStub,
550559
bsConfig,
@@ -611,6 +620,7 @@ describe("runs", () => {
611620
getVideoConfigStub = sandbox.stub();
612621
setSpecTimeoutStub = sandbox.stub().returns(undefined);
613622
setRecordCapsStub = sandbox.stub().returns(undefined);
623+
setNodeVersionStub = sandbox.stub();
614624
});
615625

616626
afterEach(() => {
@@ -659,7 +669,8 @@ describe("runs", () => {
659669
getVideoConfig: getVideoConfigStub,
660670
setSpecTimeout: setSpecTimeoutStub,
661671
setRecordCaps: setRecordCapsStub,
662-
setDebugMode: setDebugModeStub
672+
setDebugMode: setDebugModeStub,
673+
setNodeVersion: setNodeVersionStub,
663674
},
664675
'../helpers/capabilityHelper': {
665676
validate: capabilityValidatorStub,
@@ -734,6 +745,7 @@ describe("runs", () => {
734745
sinon.assert.calledOnce(setGeolocationStub);
735746
sinon.assert.calledOnce(setSpecTimeoutStub);
736747
sinon.assert.calledOnce(setRecordCapsStub);
748+
sinon.assert.calledOnce(setNodeVersionStub);
737749

738750
sinon.assert.calledOnceWithExactly(
739751
sendUsageReportStub,
@@ -814,6 +826,7 @@ describe("runs", () => {
814826
getVideoConfigStub = sandbox.stub();
815827
setSpecTimeoutStub = sandbox.stub().returns(undefined);
816828
setRecordCapsStub = sandbox.stub().returns(undefined);
829+
setNodeVersionStub = sandbox.stub();
817830
});
818831

819832
afterEach(() => {
@@ -870,7 +883,8 @@ describe("runs", () => {
870883
getVideoConfig: getVideoConfigStub,
871884
setSpecTimeout: setSpecTimeoutStub,
872885
setRecordCaps: setRecordCapsStub,
873-
setDebugMode: setDebugModeStub
886+
setDebugMode: setDebugModeStub,
887+
setNodeVersion: setNodeVersionStub,
874888
},
875889
'../helpers/capabilityHelper': {
876890
validate: capabilityValidatorStub,
@@ -961,6 +975,7 @@ describe("runs", () => {
961975
sinon.assert.calledOnce(setSystemEnvsStub);
962976
sinon.assert.calledOnce(setGeolocationStub);
963977
sinon.assert.calledOnce(setRecordCapsStub);
978+
sinon.assert.calledOnce(setNodeVersionStub);
964979
sinon.assert.match(
965980
sendUsageReportStub.getCall(0).args,
966981
[

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,42 @@ describe("capabilityHelper.js", () => {
11701170
});
11711171
});
11721172

1173+
describe("validate nodeVersion", () => {
1174+
beforeEach(() => {
1175+
bsConfig = {
1176+
auth: {},
1177+
browsers: [
1178+
{
1179+
browser: "chrome",
1180+
os: "Windows 10",
1181+
versions: ["78", "77"],
1182+
},
1183+
],
1184+
run_settings: {
1185+
cypress_proj_dir: "random path",
1186+
cypressConfigFilePath: "random path",
1187+
cypressProjectDir: "random path",
1188+
cypress_config_filename: "false"
1189+
},
1190+
connection_settings: {}
1191+
};
1192+
loggerWarningSpy = sinon.stub(logger, 'warn');
1193+
});
1194+
1195+
afterEach(function() {
1196+
loggerWarningSpy.restore();
1197+
});
1198+
1199+
it("should log a warning if nodeVersion is not in x.x.x format where x is a number", () => {
1200+
1201+
return capabilityHelper
1202+
.validate(bsConfig, {})
1203+
.then(function (data) {
1204+
sinon.assert.called(loggerWarningSpy);
1205+
});
1206+
});
1207+
});
1208+
11731209
describe("validate home directory", () => {
11741210
beforeEach(() => {
11751211
bsConfig = {

test/unit/bin/helpers/utils.js

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,162 @@ describe('utils', () => {
19751975
});
19761976
});
19771977

1978+
describe('verifyNodeVersionOption', () => {
1979+
let utilsearchForOptionNodeVersionStub, userOption, testOption;
1980+
1981+
beforeEach(function () {
1982+
utilsearchForOptionNodeVersionStub = sinon
1983+
.stub(utils, 'searchForOption')
1984+
.callsFake((...userOption) => {
1985+
return userOption == testOption;
1986+
});
1987+
});
1988+
1989+
afterEach(function () {
1990+
utilsearchForOptionNodeVersionStub.restore();
1991+
});
1992+
1993+
it('-nv user option', () => {
1994+
testOption = '-nv';
1995+
expect(utils.verifyNodeVersionOption()).to.be.true;
1996+
sinon.assert.calledWithExactly(
1997+
utilsearchForOptionNodeVersionStub,
1998+
testOption
1999+
);
2000+
});
2001+
2002+
it('--nv user option', () => {
2003+
testOption = '--nv';
2004+
expect(utils.verifyNodeVersionOption()).to.be.true;
2005+
sinon.assert.calledWithExactly(
2006+
utilsearchForOptionNodeVersionStub,
2007+
testOption
2008+
);
2009+
});
2010+
2011+
it('-node-version user option', () => {
2012+
testOption = '-node-version';
2013+
expect(utils.verifyNodeVersionOption()).to.be.true;
2014+
sinon.assert.calledWithExactly(
2015+
utilsearchForOptionNodeVersionStub,
2016+
testOption
2017+
);
2018+
});
2019+
2020+
it('--node-version user option', () => {
2021+
testOption = '--node-version';
2022+
expect(utils.verifyNodeVersionOption()).to.be.true;
2023+
sinon.assert.calledWithExactly(
2024+
utilsearchForOptionNodeVersionStub,
2025+
testOption
2026+
);
2027+
});
2028+
2029+
it('-nodeVersion user option', () => {
2030+
testOption = '-nodeVersion';
2031+
expect(utils.verifyNodeVersionOption()).to.be.true;
2032+
sinon.assert.calledWithExactly(
2033+
utilsearchForOptionNodeVersionStub,
2034+
testOption
2035+
);
2036+
});
2037+
2038+
it('--nodeVersion user option', () => {
2039+
testOption = '--nodeVersion';
2040+
expect(utils.verifyNodeVersionOption()).to.be.true;
2041+
sinon.assert.calledWithExactly(
2042+
utilsearchForOptionNodeVersionStub,
2043+
testOption
2044+
);
2045+
});
2046+
});
2047+
2048+
describe('setNodeVersion', () => {
2049+
let verifyNodeVersionOptionStub,
2050+
nvBool,
2051+
args,
2052+
bsConfig,
2053+
nodeVersion,
2054+
get_versionStub;
2055+
let userNodeVersion = 'z.z.z';
2056+
2057+
beforeEach(function () {
2058+
verifyNodeVersionOptionStub = sinon
2059+
.stub(utils, 'verifyNodeVersionOption')
2060+
.callsFake(() => nvBool);
2061+
2062+
get_versionStub = sinon
2063+
.stub(usageReporting, 'get_version')
2064+
.callsFake(() => userNodeVersion);
2065+
2066+
args = {
2067+
nodeVersion: 'x.x.x',
2068+
};
2069+
});
2070+
2071+
afterEach(function () {
2072+
sinon.restore();
2073+
});
2074+
2075+
it('has user provided nv flag', () => {
2076+
nvBool = true;
2077+
2078+
bsConfig = {
2079+
run_settings: {
2080+
nodeVersion: 'y.y.y',
2081+
},
2082+
};
2083+
2084+
utils.setNodeVersion(bsConfig, args);
2085+
2086+
expect(bsConfig.run_settings.nodeVersion).to.be.eq(
2087+
args.nodeVersion
2088+
);
2089+
expect(bsConfig.run_settings.userProvidedNodeVersion).to.be.true;
2090+
});
2091+
2092+
it('does not have user provided nv flag, sets the value from bsConfig', () => {
2093+
nvBool = false;
2094+
args = {
2095+
nodeVersion: null
2096+
};
2097+
bsConfig = {
2098+
run_settings: {
2099+
nodeVersion: 'x.x.x',
2100+
},
2101+
};
2102+
2103+
utils.setNodeVersion(bsConfig, args);
2104+
2105+
expect(bsConfig.run_settings.nodeVersion).to.not.be.eq(
2106+
args.nodeVersion
2107+
);
2108+
expect(bsConfig.run_settings.nodeVersion).to.be.eq('x.x.x');
2109+
expect(bsConfig.run_settings.userProvidedNodeVersion).to.be.true;
2110+
});
2111+
2112+
it('does not have user provided nv flag and config value, sets nodeVersion to the value of the user\'s nodeVersion that was used to trigger the build', () => {
2113+
nvBool = false;
2114+
args = {
2115+
nodeVersion: null
2116+
};
2117+
bsConfig = {
2118+
run_settings: {
2119+
nodeVersion: null,
2120+
},
2121+
};
2122+
2123+
utils.setNodeVersion(bsConfig, args);
2124+
2125+
expect(bsConfig.run_settings.nodeVersion).to.be.eq(userNodeVersion);
2126+
expect(bsConfig.run_settings.userProvidedNodeVersion).to.be.false;
2127+
});
2128+
2129+
afterEach(function () {
2130+
verifyNodeVersionOptionStub.restore();
2131+
});
2132+
});
2133+
19782134
describe('setDefaults', () => {
19792135
beforeEach(function () {
19802136
delete process.env.BROWSERSTACK_USERNAME;

0 commit comments

Comments
 (0)