Skip to content

Commit 6eb5042

Browse files
authored
Merge pull request #102 from browserstack/change_error_texts
Change Error Texts
2 parents 7519550 + a06c43f commit 6eb5042

File tree

7 files changed

+58
-7
lines changed

7 files changed

+58
-7
lines changed

bin/commands/runs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ module.exports = function run(args) {
122122

123123
// display browserstack.json is not valid only if validation of browserstack.json field has failed, otherwise display just the error message
124124
// If parallels specified in arguments are invalid do not display browserstack.json is invalid message
125-
if (!(err === Constants.validationMessages.INVALID_PARALLELS_CONFIGURATION && !utils.isUndefined(args.parallels))) {
125+
if (utils.isJSONInvalid(err, args)) {
126126
logger.error(Constants.validationMessages.NOT_VALID);
127127
}
128128

bin/helpers/capabilityHelper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const validate = (bsConfig, args) => {
139139
cypressJson = JSON.parse(cypressJsonContent);
140140

141141
// Cypress Json Base Url & Local true check
142-
if (!Utils.isUndefined(cypressJson.baseUrl) && cypressJson.baseUrl.includes("localhost") && !Utils.getLocalFlag(bsConfig.connection_settings)) reject(Constants.validationMessages.LOCAL_NOT_SET);
142+
if (!Utils.isUndefined(cypressJson.baseUrl) && cypressJson.baseUrl.includes("localhost") && !Utils.getLocalFlag(bsConfig.connection_settings)) reject(Constants.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", cypressJson.baseUrl));
143143

144144
// Detect if the user is not using the right directory structure, and throw an error
145145
if (!Utils.isUndefined(cypressJson.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,cypressJson.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);

bin/helpers/constants.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const userMessages = {
1515
BUILD_INFO_FAILED: "Failed to get build info.",
1616
BUILD_STOP_FAILED: "Failed to stop build.",
1717
BUILD_REPORT_MESSAGE: "See the entire build report here:",
18-
ZIP_UPLOADER_NOT_REACHABLE: "Could not reach to zip uploader.",
18+
ZIP_UPLOADER_NOT_REACHABLE: "Could not reach BrowserStack APIs. Please check your network or see if you need to whitelist *.browserstack.com",
1919
ZIP_UPLOAD_FAILED: "Zip Upload failed.",
2020
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
2121
CONFIG_FILE_EXISTS: "File already exists, delete the browserstack.json file manually. skipping...",
@@ -56,7 +56,7 @@ const validationMessages = {
5656
CYPRESS_JSON_NOT_FOUND: "cypress.json file is not found at cypress_proj_dir path ",
5757
INVALID_CYPRESS_JSON: "cypress.json is not a valid json",
5858
INVALID_DEFAULT_AUTH_PARAMS: "Your username and access key are required to run your tests on BrowserStack. Learn more at https://www.browserstack.com/docs/automate/cypress/authentication",
59-
LOCAL_NOT_SET: "To test <baseUrl value> on BrowserStack, you will have to set up Local testing. Read more here: https://www.browserstack.com/docs/automate/cypress/local-testing",
59+
LOCAL_NOT_SET: "To test <baseUrlValue> on BrowserStack, you will have to set up Local testing. Read more here: https://www.browserstack.com/docs/automate/cypress/local-testing",
6060
INCORRECT_DIRECTORY_STRUCTURE: "No tests to run. Note that your Cypress tests should be in the same directory where the cypress.json exists."
6161
};
6262

bin/helpers/utils.js

+19
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,22 @@ exports.versionChangedMessage = (preferredVersion, actualVersion) => {
380380
message = message.replace("<actualVersion>", actualVersion);
381381
return message
382382
}
383+
384+
exports.isJSONInvalid = (err, args) => {
385+
let invalid = true
386+
387+
if (err === Constants.validationMessages.INVALID_PARALLELS_CONFIGURATION && !this.isUndefined(args.parallels)) {
388+
return false
389+
}
390+
391+
if (this.deleteBaseUrlFromError(err) === this.deleteBaseUrlFromError(Constants.validationMessages.LOCAL_NOT_SET)) {
392+
return false
393+
}
394+
395+
return invalid
396+
}
397+
398+
exports.deleteBaseUrlFromError = (err) => {
399+
return err.replace(/To test ([\s\S]*)on BrowserStack/g, 'To test on BrowserStack');
400+
}
401+

test/unit/bin/commands/runs.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe("runs", () => {
8282
beforeEach(() => {
8383
sandbox = sinon.createSandbox();
8484
validateBstackJsonStub = sandbox.stub();
85+
isJSONInvalidStub = sandbox.stub();
8586
setUsernameStub = sandbox.stub();
8687
setAccessKeyStub = sandbox.stub();
8788
setBuildNameStub = sandbox.stub();
@@ -127,7 +128,8 @@ describe("runs", () => {
127128
setLocal: setLocalStub,
128129
setLocalIdentifier: setLocalIdentifierStub,
129130
deleteResults: deleteResultsStub,
130-
setDefaults: setDefaultsStub
131+
setDefaults: setDefaultsStub,
132+
isJSONInvalid: isJSONInvalidStub
131133
},
132134
'../helpers/capabilityHelper': {
133135
validate: capabilityValidatorStub,

test/unit/bin/helpers/capabilityHelper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ describe("capabilityHelper.js", () => {
856856
.catch((error) => {
857857
chai.assert.equal(
858858
error,
859-
Constants.validationMessages.LOCAL_NOT_SET
859+
Constants.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", "http://localhost:3000")
860860
);
861861
fs.existsSync.restore();
862862
fs.readFileSync.restore();

test/unit/bin/helpers/utils.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('utils', () => {
145145
sandbox = sinon.createSandbox();
146146
sandbox.stub(utils,'getBrowserCombinations').returns(['a','b']);
147147
});
148-
148+
149149
afterEach(() => {
150150
sandbox.restore();
151151
sinon.restore();
@@ -1146,4 +1146,34 @@ describe('utils', () => {
11461146
expect(utils.versionChangedMessage(preferredVersion, actualVersion)).to.eq(message)
11471147
});
11481148
})
1149+
1150+
describe('#isJSONInvalid', () => {
1151+
it('JSON is valid when error is parallel misconfiguration', () => {
1152+
let error = constant.validationMessages.INVALID_PARALLELS_CONFIGURATION;
1153+
let args = {"parallels": 4}
1154+
expect(utils.isJSONInvalid(error, args)).to.eq(false)
1155+
});
1156+
1157+
it('JSON is valid when local is not set for localhost url', () => {
1158+
let error = constant.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", "localhost:4000");
1159+
expect(utils.isJSONInvalid(error, {})).to.eq(false)
1160+
});
1161+
1162+
it('JSON is invalid for errors apart from Local or Prallell misconfiguration', () => {
1163+
let error = constant.validationMessages.INCORRECT_AUTH_PARAMS;
1164+
expect(utils.isJSONInvalid(error, {})).to.eq(true)
1165+
});
1166+
})
1167+
1168+
describe('#deleteBaseUrlFromError', () => {
1169+
it('Replace baseUrl in Local error string', () => {
1170+
let error = constant.validationMessages.LOCAL_NOT_SET;
1171+
expect(utils.deleteBaseUrlFromError(error)).to.match(/To test on BrowserStack/)
1172+
});
1173+
1174+
it('should not replace baseUrl in other error string', () => {
1175+
let error = constant.validationMessages.NOT_VALID_JSON;
1176+
expect(utils.deleteBaseUrlFromError(error)).not.to.match(/To test on BrowserStack/)
1177+
});
1178+
});
11491179
});

0 commit comments

Comments
 (0)