Skip to content

Commit f06dfbf

Browse files
committed
remove comments and update test case
1 parent 4fffe30 commit f06dfbf

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

bin/helpers/capabilityHelper.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,8 @@ const caps = (bsConfig, zip) => {
133133
const addCypressZipStartLocation = (runSettings) => {
134134
let resolvedHomeDirectoryPath = path.resolve(runSettings.home_directory);
135135
let resolvedCypressConfigFilePath = path.resolve(runSettings.cypressConfigFilePath);
136-
// For example
137-
// resolvedHomeDirectoryPath -> '/Users/<user_name>/path'
138-
// resolvedCypressConfigFilePath -> '/Users/<user_name>/path/cypress.json' or '/Users/<user_name>/path/more_path/cypress.json'
139-
runSettings.cypressZipStartLocation = path.dirname(resolvedCypressConfigFilePath.split(resolvedHomeDirectoryPath)[1]); // cypressZipStartLocation -> '/' or '/more_path'
140-
runSettings.cypressZipStartLocation = runSettings.cypressZipStartLocation.substring(1); // cypressZipStartLocation -> '' or 'more_path'
136+
runSettings.cypressZipStartLocation = path.dirname(resolvedCypressConfigFilePath.split(resolvedHomeDirectoryPath)[1]);
137+
runSettings.cypressZipStartLocation = runSettings.cypressZipStartLocation.substring(1);
141138
}
142139

143140
const validate = (bsConfig, args) => {

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,6 @@ describe("capabilityHelper.js", () => {
10851085
});
10861086

10871087
it("does not exist", () => {
1088-
// sinon.stub(fs, 'existsSync').returns(false);
10891088
bsConfig.run_settings.cypressConfigFilePath = 'false';
10901089
bsConfig.run_settings.cypress_config_filename = 'false';
10911090
bsConfig.run_settings.home_directory = '/some/random';
@@ -1107,7 +1106,6 @@ describe("capabilityHelper.js", () => {
11071106
});
11081107

11091108
it("is not a directory", () => {
1110-
// sinon.stub(fs, 'existsSync').returns(false);
11111109
bsConfig.run_settings.cypressConfigFilePath = 'false';
11121110
bsConfig.run_settings.cypress_config_filename = 'false';
11131111
bsConfig.run_settings.home_directory = '/some/random/file.ext';
@@ -1131,7 +1129,6 @@ describe("capabilityHelper.js", () => {
11311129
});
11321130

11331131
it("does not contain cypressConfigFilePath", () => {
1134-
// sinon.stub(fs, 'existsSync').returns(false);
11351132
bsConfig.run_settings.cypressConfigFilePath = 'false';
11361133
bsConfig.run_settings.cypress_config_filename = 'false';
11371134
bsConfig.run_settings.home_directory = '/some/random';
@@ -1153,6 +1150,29 @@ describe("capabilityHelper.js", () => {
11531150
fs.statSync.restore();
11541151
});
11551152
});
1153+
1154+
it("does not contain cypressConfigFilePath with special chars", () => {
1155+
bsConfig.run_settings.cypressConfigFilePath = 'false';
1156+
bsConfig.run_settings.cypress_config_filename = 'false';
1157+
bsConfig.run_settings.home_directory = '/$some!@#$%^&*()_+=-[]{};:<>?\'\\\//random';
1158+
1159+
sinon.stub(fs, 'existsSync').returns(true);
1160+
sinon.stub(fs, 'statSync').returns({ isDirectory: () => true });
1161+
1162+
return capabilityHelper
1163+
.validate(bsConfig, {})
1164+
.then(function (data) {
1165+
chai.assert.fail("Promise error");
1166+
})
1167+
.catch((error) => {
1168+
chai.assert.equal(
1169+
error,
1170+
Constants.validationMessages.CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY
1171+
);
1172+
fs.existsSync.restore();
1173+
fs.statSync.restore();
1174+
});
1175+
});
11561176
});
11571177
});
11581178
});

0 commit comments

Comments
 (0)