Skip to content

Commit cb281f2

Browse files
Adding validations to check if the cypress.json is a valid json.
1 parent 634d337 commit cb281f2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

bin/helpers/capabilityHelper.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ const validate = (bsConfig) => {
9595

9696
if (!fs.existsSync(path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json'))) reject(Constants.validationMessages.CYPRESS_JSON_NOT_FOUND + bsConfig.run_settings.cypress_proj_dir);
9797

98+
try{
99+
let cypressJson = fs.readFileSync(path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json'))
100+
JSON.parse(cypressJson)
101+
}catch(error){
102+
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
103+
}
104+
98105
resolve(Constants.validationMessages.VALIDATED);
99106
});
100107
}

bin/helpers/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const validationMessages = {
2424
NOT_VALID: "browerstack.json is not valid",
2525
NOT_VALID_JSON: "browerstack.json is not a valid json",
2626
INVALID_EXTENSION: "Invalid files, please remove these files and try again.",
27-
CYPRESS_JSON_NOT_FOUND: "cypress.json file is not found at cypress_proj_dir path "
27+
CYPRESS_JSON_NOT_FOUND: "cypress.json file is not found at cypress_proj_dir path ",
28+
INVALID_CYPRESS_JSON: "cypress.json is not a valid json"
2829
};
2930

3031
const cliMessages = {

0 commit comments

Comments
 (0)