Skip to content

Commit fa44af7

Browse files
committed
Adding tests for utils methods and fixing issue with method
1 parent 3069019 commit fa44af7

File tree

2 files changed

+128
-3
lines changed

2 files changed

+128
-3
lines changed

bin/helpers/utils.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,16 @@ exports.verifyCypressConfigFileOption = () => {
131131
exports.setCypressConfigFilename = (bsConfig, args) => {
132132
let userProvidedCypessConfigFile = this.verifyCypressConfigFileOption();
133133

134+
bsConfig.run_settings.userProvidedCypessConfigFile = (userProvidedCypessConfigFile || (!this.isUndefined(bsConfig.run_settings.cypress_config_file)));
135+
134136
if (userProvidedCypessConfigFile || this.isUndefined(bsConfig.run_settings.cypress_config_file)) {
135-
bsConfig.run_settings.cypress_config_filename = path.basename(args.cypressConfigFile);
136137
bsConfig.run_settings.cypress_config_file = args.cypressConfigFile;
137-
bsConfig.run_settings.userProvidedCypessConfigFile = userProvidedCypessConfigFile;
138+
bsConfig.run_settings.cypress_config_filename = path.basename(args.cypressConfigFile);
139+
} else if (!this.isUndefined(bsConfig.run_settings.cypress_config_file)) {
140+
bsConfig.run_settings.cypress_config_filename = path.basename(bsConfig.run_settings.cypress_config_file);
138141
}
139142

140-
bsConfig.run_settings.cypressConfigFilePath = userProvidedCypessConfigFile ? bsConfig.run_settings.cypress_config_file : path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json');
143+
bsConfig.run_settings.cypressConfigFilePath = bsConfig.run_settings.userProvidedCypessConfigFile ? bsConfig.run_settings.cypress_config_file : path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json');
141144
}
142145

143146
exports.isUndefined = value => (value === undefined || value === null);

test/unit/bin/helpers/utils.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,126 @@ describe("utils", () => {
482482
});
483483

484484
});
485+
486+
describe("verifyCypressConfigFileOption", () => {
487+
let utilsearchForOptionCypressConfigFileStub, userOption, testOption;
488+
489+
beforeEach(function() {
490+
utilsearchForOptionCypressConfigFileStub = sinon
491+
.stub(utils, 'searchForOption')
492+
.callsFake((...userOption) => {
493+
return (userOption == testOption);
494+
});
495+
});
496+
497+
afterEach(function() {
498+
utilsearchForOptionCypressConfigFileStub.restore();
499+
});
500+
501+
it("-ccf user option", () => {
502+
testOption = '-ccf';
503+
expect(utils.verifyCypressConfigFileOption()).to.be.true;
504+
sinon.assert.calledWithExactly(utilsearchForOptionCypressConfigFileStub, testOption);
505+
});
506+
507+
it("--ccf user option", () => {
508+
testOption = '--ccf';
509+
expect(utils.verifyCypressConfigFileOption()).to.be.true;
510+
sinon.assert.calledWithExactly(utilsearchForOptionCypressConfigFileStub, testOption);
511+
});
512+
513+
it("-cypress-config-file user option", () => {
514+
testOption = '-cypress-config-file';
515+
expect(utils.verifyCypressConfigFileOption()).to.be.true;
516+
sinon.assert.calledWithExactly(utilsearchForOptionCypressConfigFileStub, testOption);
517+
});
518+
519+
it("--cypress-config-file user option", () => {
520+
testOption = '--cypress-config-file';
521+
expect(utils.verifyCypressConfigFileOption()).to.be.true;
522+
sinon.assert.calledWithExactly(utilsearchForOptionCypressConfigFileStub, testOption);
523+
});
524+
525+
it("-cypressConfigFile user option", () => {
526+
testOption = '-cypressConfigFile';
527+
expect(utils.verifyCypressConfigFileOption()).to.be.true;
528+
sinon.assert.calledWithExactly(utilsearchForOptionCypressConfigFileStub, testOption);
529+
});
530+
531+
it("--cypressConfigFile user option", () => {
532+
testOption = '--cypressConfigFile';
533+
expect(utils.verifyCypressConfigFileOption()).to.be.true;
534+
sinon.assert.calledWithExactly(utilsearchForOptionCypressConfigFileStub, testOption);
535+
});
536+
});
537+
538+
describe("setCypressConfigFilename", () => {
539+
let verifyCypressConfigFileOptionStub,
540+
ccfBool, args, bsConfig, cypress_config_file;
541+
542+
beforeEach(function() {
543+
verifyCypressConfigFileOptionStub = sinon
544+
.stub(utils, 'verifyCypressConfigFileOption')
545+
.callsFake(() => ccfBool);
546+
547+
args = {
548+
cypressConfigFile: "args_cypress_config_file"
549+
};
550+
});
551+
552+
it("has user provided ccf flag", () => {
553+
ccfBool = true;
554+
555+
bsConfig = {
556+
run_settings: {
557+
cypress_config_file: "run_settings_cypress_config_file"
558+
}
559+
};
560+
561+
utils.setCypressConfigFilename(bsConfig, args);
562+
563+
expect(bsConfig.run_settings.cypress_config_file).to.be.eq(args.cypressConfigFile);
564+
expect(bsConfig.run_settings.cypress_config_filename).to.be.eq(path.basename(args.cypressConfigFile));
565+
expect(bsConfig.run_settings.userProvidedCypessConfigFile).to.be.true;
566+
expect(bsConfig.run_settings.cypressConfigFilePath).to.be.eq(bsConfig.run_settings.cypress_config_file);
567+
});
568+
569+
it("does not have user provided ccf flag, sets the value from cypress_proj_dir", () => {
570+
ccfBool = false;
571+
572+
bsConfig = {
573+
run_settings: {
574+
cypress_proj_dir: "cypress_proj_dir"
575+
}
576+
};
577+
578+
utils.setCypressConfigFilename(bsConfig, args);
579+
580+
expect(bsConfig.run_settings.cypress_config_file).to.be.eq(args.cypressConfigFile);
581+
expect(bsConfig.run_settings.cypress_config_filename).to.be.eq(path.basename(args.cypressConfigFile));
582+
expect(bsConfig.run_settings.userProvidedCypessConfigFile).to.be.false;
583+
expect(bsConfig.run_settings.cypressConfigFilePath).to.be.eq(path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json'));
584+
});
585+
586+
it("does not have user provided ccf flag, sets from config file", () => {
587+
cypress_config_file = "run_settings_cypress_config_file";
588+
ccfBool = false;
589+
bsConfig = {
590+
run_settings: {
591+
cypress_config_file: cypress_config_file
592+
}
593+
};
594+
595+
utils.setCypressConfigFilename(bsConfig, args);
596+
597+
expect(bsConfig.run_settings.cypress_config_file).to.be.eq(cypress_config_file);
598+
expect(bsConfig.run_settings.cypress_config_filename).to.be.eq(path.basename(cypress_config_file));
599+
expect(bsConfig.run_settings.userProvidedCypessConfigFile).to.be.true;
600+
expect(bsConfig.run_settings.cypressConfigFilePath).to.be.eq(bsConfig.run_settings.cypress_config_file);
601+
});
602+
603+
afterEach(function() {
604+
verifyCypressConfigFileOptionStub.restore();
605+
})
606+
});
485607
});

0 commit comments

Comments
 (0)