Skip to content

Commit 9b42310

Browse files
Adding specs for config options
1 parent 79cfacc commit 9b42310

File tree

3 files changed

+116
-7
lines changed

3 files changed

+116
-7
lines changed

test/unit/bin/commands/runs.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const chai = require("chai"),
55
const Constants = require("../../../../bin/helpers/constants"),
66
logger = require("../../../../bin/helpers/logger").winstonLogger,
77
testObjects = require("../../support/fixtures/testObjects");
8-
const { initTimeComponents, markBlockStart, markBlockEnd } = require("../../../../bin/helpers/timeComponents");
9-
const { setHeaded, setupLocalTesting, stopLocalBinary, setUserSpecs, setLocalConfigFile } = require("../../../../bin/helpers/utils");
10-
8+
119
const proxyquire = require("proxyquire").noCallThru();
1210

1311
chai.use(chaiAsPromised);
@@ -108,6 +106,8 @@ describe("runs", () => {
108106
setDefaultsStub = sandbox.stub();
109107
setLocalModeStub = sandbox.stub();
110108
setLocalConfigFileStub = sandbox.stub();
109+
setBrowsersStub = sandbox.stub();
110+
setConfigStub = sandbox.stub();
111111
});
112112

113113
afterEach(() => {
@@ -143,7 +143,9 @@ describe("runs", () => {
143143
isJSONInvalid: isJSONInvalidStub,
144144
setLocalMode: setLocalModeStub,
145145
setLocalConfigFile: setLocalConfigFileStub,
146-
setSystemEnvs: setSystemEnvsStub
146+
setSystemEnvs: setSystemEnvsStub,
147+
setBrowsers: setBrowsersStub,
148+
setConfig: setConfigStub
147149
},
148150
'../helpers/capabilityHelper': {
149151
validate: capabilityValidatorStub
@@ -176,6 +178,7 @@ describe("runs", () => {
176178
sinon.assert.calledOnce(setLocalConfigFileStub);
177179
sinon.assert.calledOnce(setHeadedStub);
178180
sinon.assert.calledOnce(setNoWrapStub);
181+
sinon.assert.calledOnce(setConfigStub);
179182
sinon.assert.calledOnce(capabilityValidatorStub);
180183
sinon.assert.calledOnce(getErrorCodeFromMsgStub);
181184
sinon.assert.calledOnce(setLocalIdentifierStub);
@@ -226,6 +229,8 @@ describe("runs", () => {
226229
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
227230
setDefaultsStub = sandbox.stub();
228231
setLocalConfigFileStub = sandbox.stub();
232+
setBrowsersStub = sandbox.stub();
233+
setConfigStub = sandbox.stub();
229234
});
230235

231236
afterEach(() => {
@@ -262,7 +267,9 @@ describe("runs", () => {
262267
setDefaults: setDefaultsStub,
263268
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
264269
setLocalConfigFile: setLocalConfigFileStub,
265-
setSystemEnvs: setSystemEnvsStub
270+
setSystemEnvs: setSystemEnvsStub,
271+
setBrowsers: setBrowsersStub,
272+
setConfig: setConfigStub
266273
},
267274
'../helpers/capabilityHelper': {
268275
validate: capabilityValidatorStub,
@@ -359,6 +366,8 @@ describe("runs", () => {
359366
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
360367
setDefaultsStub = sandbox.stub();
361368
setLocalConfigFileStub = sandbox.stub();
369+
setConfigStub = sandbox.stub();
370+
setBrowsersStub = sandbox.stub();
362371
});
363372

364373
afterEach(() => {
@@ -395,7 +404,9 @@ describe("runs", () => {
395404
deleteResults: deleteResultsStub,
396405
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
397406
setDefaults: setDefaultsStub,
398-
setLocalConfigFile: setLocalConfigFileStub
407+
setLocalConfigFile: setLocalConfigFileStub,
408+
setBrowsers: setBrowsersStub,
409+
setConfig: setConfigStub
399410
},
400411
'../helpers/capabilityHelper': {
401412
validate: capabilityValidatorStub,
@@ -497,6 +508,8 @@ describe("runs", () => {
497508
setDefaultsStub = sandbox.stub();
498509
stopLocalBinaryStub = sandbox.stub();
499510
setLocalConfigFileStub = sandbox.stub();
511+
setConfigStub = sandbox.stub();
512+
setBrowsersStub = sandbox.stub();
500513
});
501514

502515
afterEach(() => {
@@ -534,7 +547,9 @@ describe("runs", () => {
534547
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
535548
setDefaults: setDefaultsStub,
536549
stopLocalBinary: stopLocalBinaryStub,
537-
setLocalConfigFile: setLocalConfigFileStub
550+
setLocalConfigFile: setLocalConfigFileStub,
551+
setBrowsers: setBrowsersStub,
552+
setConfig: setConfigStub
538553
},
539554
'../helpers/capabilityHelper': {
540555
validate: capabilityValidatorStub,
@@ -652,6 +667,8 @@ describe("runs", () => {
652667
initTimeComponentsStub = sandbox.stub();
653668
markBlockStartStub = sandbox.stub();
654669
markBlockEndStub = sandbox.stub();
670+
setConfigStub = sandbox.stub();
671+
setBrowsersStub = sandbox.stub();
655672
});
656673

657674
afterEach(() => {
@@ -693,6 +710,8 @@ describe("runs", () => {
693710
isUndefined: isUndefinedStub,
694711
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
695712
setLocalConfigFile: setLocalConfigFileStub,
713+
setBrowsers: setBrowsersStub,
714+
setConfig: setConfigStub
696715
},
697716
'../helpers/capabilityHelper': {
698717
validate: capabilityValidatorStub,

test/unit/bin/helpers/fileHelpers.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ describe("fileHelpers", () => {
4545
expect(dataMock).to.eql(1);
4646
});
4747

48+
it("callback fn is executed after file write", () => {
49+
let dataMock = 0;
50+
51+
let callbackStub = sandbox.stub().callsFake(() => {
52+
dataMock = 1;
53+
});
54+
55+
const fileExtraStub = sinon.stub(fs,'writeFile');
56+
fileExtraStub.yields(true);
57+
fileHelpers.write({path: "./random_path", file: "random"}, "writing successful", {}, callbackStub);
58+
59+
sinon.assert.calledOnce(callbackStub);
60+
sinon.assert.calledOnce(fileExtraStub);
61+
expect(dataMock).to.eql(1);
62+
});
63+
4864
it("callback fn is executed after fileExists returns error", () => {
4965
let dataMock = undefined;
5066

test/unit/bin/helpers/utils.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,4 +2032,78 @@ describe('utils', () => {
20322032
});
20332033
});
20342034

2035+
describe('setConfig', () => {
2036+
it('the args config should be assigned to bsconfig run_settings config', () => {
2037+
let bsConfig = {
2038+
run_settings: {
2039+
}
2040+
};
2041+
let args = {
2042+
config: "pageLoadTimeout=60000"
2043+
};
2044+
utils.setConfig(bsConfig, args);
2045+
expect(args.config).to.be.eql(bsConfig.run_settings.config);
2046+
});
2047+
});
2048+
2049+
describe('setBrowsers', () => {
2050+
it('the args browser should override the bsconfig browsers', async () => {
2051+
let bsConfig = {
2052+
browsers: [
2053+
{
2054+
"browser": "chrome",
2055+
"os": "Windows 10",
2056+
"versions": ["latest", "latest-1"]
2057+
},
2058+
{
2059+
"browser": "chrome",
2060+
"os": "Windows 10",
2061+
"versions": ["latest", "latest-1"]
2062+
},
2063+
]
2064+
};
2065+
let args = {
2066+
browser: "chrome@91:Windows 10,chrome:OS X Mojave"
2067+
};
2068+
let browserResult = [
2069+
{
2070+
"browser": "chrome",
2071+
"os": "Windows 10",
2072+
"versions": ["91"]
2073+
},
2074+
{
2075+
"browser": "chrome",
2076+
"os": "OS X Mojave",
2077+
"versions": ["latest"]
2078+
},
2079+
]
2080+
await utils.setBrowsers(bsConfig, args);
2081+
expect(bsConfig.browsers).to.be.eql(browserResult);
2082+
});
2083+
it('the args browser should throw an error in case of exception raised', async () => {
2084+
let bsConfig = {
2085+
browsers: [
2086+
{
2087+
"browser": "chrome",
2088+
"os": "Windows 10",
2089+
"versions": ["latest", "latest-1"]
2090+
},
2091+
{
2092+
"browser": "chrome",
2093+
"os": "Windows 10",
2094+
"versions": ["latest", "latest-1"]
2095+
},
2096+
]
2097+
};
2098+
let args = {
2099+
browser: ":Windows 10"
2100+
};
2101+
try {
2102+
await utils.setBrowsers(bsConfig, args);
2103+
} catch(err){{
2104+
expect(err).to.be.eql(constant.validationMessages.INVALID_BROWSER_ARGS);
2105+
}}
2106+
});
2107+
});
2108+
20352109
});

0 commit comments

Comments
 (0)