Skip to content

Commit 83ccfeb

Browse files
Unit cases for process exit handler
1 parent d0219ff commit 83ccfeb

File tree

4 files changed

+82
-14
lines changed

4 files changed

+82
-14
lines changed

bin/helpers/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const messageTypes = {
147147
NULL: null
148148
}
149149

150-
const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip', 'npmrc', 'xml', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'jsx', 'coffee', 'cjsx', 'csv', 'tsv', 'yml', 'yaml', 'env'];
150+
const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip', 'npmrc', 'xml', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'jsx', 'coffee', 'cjsx', 'csv', 'tsv', 'yml', 'yaml', 'env', 'mov', 'mp4'];
151151

152152
const filesToIgnoreWhileUploading = [
153153
'**/node_modules/**',

bin/helpers/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ exports.getCypressJSON = (bsConfig) => {
833833
}
834834

835835
exports.setCLIMode = (bsConfig, args) => {
836+
args.sync = true;
836837
if(!this.isUndefined(args.async) && args.async){
837838
args.sync = false;
838839
}
@@ -917,7 +918,7 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args) => {
917918

918919
async function processExitHandler(exitData){
919920
logger.warn(Constants.userMessages.PROCESS_KILL_MESSAGE);
920-
await this.stopBrowserStackBuild(exitData.bsConfig, exitData.args, exitData.buildId)
921-
await this.stopLocalBinary( exitData.bsConfig, exitData.bsLocalInstance, exitData.args );
922-
process.exit(1);
921+
await this.stopBrowserStackBuild(exitData.bsConfig, exitData.args, exitData.buildId);
922+
await this.stopLocalBinary(exitData.bsConfig, exitData.bsLocalInstance, exitData.args);
923+
process.exit(0);
923924
}

test/unit/bin/commands/runs.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe("runs", () => {
109109
setLocalConfigFileStub = sandbox.stub();
110110
setBrowsersStub = sandbox.stub();
111111
setConfigStub = sandbox.stub();
112+
setCLIModeStub = sandbox.stub();
112113
});
113114

114115
afterEach(() => {
@@ -147,7 +148,8 @@ describe("runs", () => {
147148
setLocalConfigFile: setLocalConfigFileStub,
148149
setSystemEnvs: setSystemEnvsStub,
149150
setBrowsers: setBrowsersStub,
150-
setConfig: setConfigStub
151+
setConfig: setConfigStub,
152+
setCLIMode: setCLIModeStub
151153
},
152154
'../helpers/capabilityHelper': {
153155
validate: capabilityValidatorStub
@@ -181,6 +183,7 @@ describe("runs", () => {
181183
sinon.assert.calledOnce(setHeadedStub);
182184
sinon.assert.calledOnce(setNoWrapStub);
183185
sinon.assert.calledOnce(setConfigStub);
186+
sinon.assert.calledOnce(setCLIModeStub);
184187
sinon.assert.calledOnce(setOtherConfigsStub);
185188
sinon.assert.calledOnce(capabilityValidatorStub);
186189
sinon.assert.calledOnce(getErrorCodeFromMsgStub);
@@ -235,6 +238,7 @@ describe("runs", () => {
235238
setLocalConfigFileStub = sandbox.stub();
236239
setBrowsersStub = sandbox.stub();
237240
setConfigStub = sandbox.stub();
241+
setCLIModeStub = sandbox.stub();
238242
});
239243

240244
afterEach(() => {
@@ -274,7 +278,8 @@ describe("runs", () => {
274278
setLocalConfigFile: setLocalConfigFileStub,
275279
setSystemEnvs: setSystemEnvsStub,
276280
setBrowsers: setBrowsersStub,
277-
setConfig: setConfigStub
281+
setConfig: setConfigStub,
282+
setCLIMode: setCLIModeStub
278283
},
279284
'../helpers/capabilityHelper': {
280285
validate: capabilityValidatorStub,
@@ -316,6 +321,7 @@ describe("runs", () => {
316321
sinon.assert.calledOnce(setLocalIdentifierStub);
317322
sinon.assert.calledOnce(setHeadedStub);
318323
sinon.assert.calledOnce(setNoWrapStub);
324+
sinon.assert.calledOnce(setCLIModeStub);
319325
sinon.assert.calledOnce(setOtherConfigsStub);
320326
sinon.assert.calledOnce(validateBstackJsonStub);
321327
sinon.assert.calledOnce(capabilityValidatorStub);
@@ -375,6 +381,7 @@ describe("runs", () => {
375381
setLocalConfigFileStub = sandbox.stub();
376382
setConfigStub = sandbox.stub();
377383
setBrowsersStub = sandbox.stub();
384+
setCLIModeStub = sandbox.stub();
378385
});
379386

380387
afterEach(() => {
@@ -414,7 +421,8 @@ describe("runs", () => {
414421
setDefaults: setDefaultsStub,
415422
setLocalConfigFile: setLocalConfigFileStub,
416423
setBrowsers: setBrowsersStub,
417-
setConfig: setConfigStub
424+
setConfig: setConfigStub,
425+
setCLIMode: setCLIModeStub
418426
},
419427
'../helpers/capabilityHelper': {
420428
validate: capabilityValidatorStub,
@@ -456,6 +464,7 @@ describe("runs", () => {
456464
sinon.assert.calledOnce(setLocalIdentifierStub);
457465
sinon.assert.calledOnce(setHeadedStub);
458466
sinon.assert.calledOnce(setNoWrapStub);
467+
sinon.assert.calledOnce(setCLIModeStub);
459468
sinon.assert.calledOnce(setOtherConfigsStub);
460469
sinon.assert.calledOnce(validateBstackJsonStub);
461470
sinon.assert.calledOnce(capabilityValidatorStub);
@@ -520,6 +529,7 @@ describe("runs", () => {
520529
setLocalConfigFileStub = sandbox.stub();
521530
setConfigStub = sandbox.stub();
522531
setBrowsersStub = sandbox.stub();
532+
setCLIModeStub = sandbox.stub();
523533
});
524534

525535
afterEach(() => {
@@ -560,7 +570,8 @@ describe("runs", () => {
560570
stopLocalBinary: stopLocalBinaryStub,
561571
setLocalConfigFile: setLocalConfigFileStub,
562572
setBrowsers: setBrowsersStub,
563-
setConfig: setConfigStub
573+
setConfig: setConfigStub,
574+
setCLIMode: setCLIModeStub
564575
},
565576
'../helpers/capabilityHelper': {
566577
validate: capabilityValidatorStub,
@@ -612,6 +623,7 @@ describe("runs", () => {
612623
sinon.assert.calledOnce(setLocalIdentifierStub);
613624
sinon.assert.calledOnce(setHeadedStub);
614625
sinon.assert.calledOnce(setNoWrapStub);
626+
sinon.assert.calledOnce(setCLIModeStub);
615627
sinon.assert.calledOnce(setOtherConfigsStub);
616628
sinon.assert.calledOnce(archiverStub);
617629
sinon.assert.calledOnce(setUsageReportingFlagStub);
@@ -686,6 +698,8 @@ describe("runs", () => {
686698
setBrowsersStub = sandbox.stub();
687699
stopLocalBinaryStub = sandbox.stub();
688700
nonEmptyArrayStub = sandbox.stub();
701+
setCLIModeStub = sandbox.stub();
702+
setProcessHooksStub = sandbox.stub();
689703
});
690704

691705
afterEach(() => {
@@ -733,6 +747,8 @@ describe("runs", () => {
733747
setConfig: setConfigStub,
734748
stopLocalBinary: stopLocalBinaryStub,
735749
nonEmptyArray: nonEmptyArrayStub,
750+
setCLIMode: setCLIModeStub,
751+
setProcessHooks: setProcessHooksStub
736752
},
737753
'../helpers/capabilityHelper': {
738754
validate: capabilityValidatorStub,
@@ -795,6 +811,8 @@ describe("runs", () => {
795811
sinon.assert.calledOnce(setLocalIdentifierStub);
796812
sinon.assert.calledOnce(setHeadedStub);
797813
sinon.assert.calledOnce(setNoWrapStub);
814+
sinon.assert.calledOnce(setCLIModeStub);
815+
sinon.assert.calledOnce(setProcessHooksStub);
798816
sinon.assert.calledOnce(setOtherConfigsStub);
799817
sinon.assert.calledOnce(generateUniqueHashStub);
800818
sinon.assert.calledOnce(archiverStub);

test/unit/bin/helpers/utils.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,30 +1994,33 @@ describe('utils', () => {
19941994
describe('#versionChangedMessage', () => {
19951995
it('should return proper error message with placeholders replaced', () => {
19961996
let preferredVersion = 'v1',
1997-
actualVersion = 'v2';
1997+
actualVersion = 'v2',
1998+
frameworkUpgradeMessage = 'framework_upgrade_message';
19981999
let message = constant.userMessages.CYPRESS_VERSION_CHANGED.replace(
19992000
'<preferredVersion>',
20002001
preferredVersion
2001-
).replace('<actualVersion>', actualVersion);
2002+
).replace('<actualVersion>', actualVersion).replace('<frameworkUpgradeMessage>', 'framework_upgrade_message');
20022003
expect(
2003-
utils.versionChangedMessage(preferredVersion, actualVersion)
2004+
utils.versionChangedMessage(preferredVersion, actualVersion, frameworkUpgradeMessage)
20042005
).to.eq(message);
20052006
});
20062007
});
20072008

20082009
describe('#latestSyntaxToActualVersionMessage', () => {
20092010
it('should return proper info message with placeholders replaced', () => {
20102011
let latestSyntaxVersion = '7.latest',
2011-
actualVersion = '7.6.0';
2012+
actualVersion = '7.6.0',
2013+
frameworkUpgradeMessage = 'framework_upgrade_message';
20122014
let message =
20132015
constant.userMessages.LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE.replace(
20142016
'<latestSyntaxVersion>',
20152017
latestSyntaxVersion
2016-
).replace('<actualVersion>', actualVersion);
2018+
).replace('<actualVersion>', actualVersion).replace('<frameworkUpgradeMessage>', 'framework_upgrade_message');
20172019
expect(
20182020
utils.latestSyntaxToActualVersionMessage(
20192021
latestSyntaxVersion,
2020-
actualVersion
2022+
actualVersion,
2023+
frameworkUpgradeMessage
20212024
)
20222025
).to.eq(message);
20232026
});
@@ -2375,4 +2378,50 @@ describe('utils', () => {
23752378
}
23762379
});
23772380
});
2381+
2382+
describe('setCLIMode', () => {
2383+
it('should set sync mode to false when async is set', () => {
2384+
let args = {
2385+
sync: true,
2386+
async: true
2387+
}
2388+
let bsConfig = {}
2389+
utils.setCLIMode(bsConfig, args);
2390+
expect(args.sync).to.be.eql(false)
2391+
});
2392+
2393+
it('should set sync mode to true by default', () => {
2394+
let args = {
2395+
sync: true
2396+
}
2397+
let bsConfig = {}
2398+
utils.setCLIMode(bsConfig, args);
2399+
expect(args.sync).to.be.eql(true)
2400+
});
2401+
});
2402+
2403+
describe('setProcessHooks', () => {
2404+
it.only('should handle "SIGINT" event', (done) => {
2405+
let buildId = 'build_id';
2406+
let bsConfig = {
2407+
2408+
}
2409+
let bsLocalStub = sinon.stub();
2410+
let args= {}
2411+
2412+
let warnLogSpy = sinon.spy(logger, 'warn')
2413+
let stopBrowserStackBuildStub= sinon.stub(utils, 'stopBrowserStackBuild').returns(Promise.resolve(true));
2414+
let stopLocalBinaryStub = sinon.stub(utils, 'stopLocalBinary').returns(Promise.resolve(true));
2415+
let processExitStub = sinon.stub(process, 'exit').returns({});
2416+
utils.setProcessHooks(buildId, bsConfig, bsLocalStub, args);
2417+
process.on('SIGINT', () => {
2418+
sinon.assert.calledWith(warnLogSpy, constant.userMessages.PROCESS_KILL_MESSAGE);
2419+
sinon.assert.calledOnce(stopBrowserStackBuildStub);
2420+
sinon.assert.calledOnce(stopLocalBinaryStub);
2421+
sinon.assert.calledOnce(processExitStub);
2422+
done();
2423+
});
2424+
process.emit('SIGINT');
2425+
});
2426+
});
23782427
});

0 commit comments

Comments
 (0)