Skip to content

Commit d9e8c02

Browse files
Add instrumentation if cypress config read fails
1 parent 844c9a9 commit d9e8c02

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

bin/helpers/readCypressConfigUtil.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const cp = require('child_process');
55

66
const config = require('./config');
77
const constants = require("./constants");
8+
const utils = require("./utils");
89
const logger = require('./logger').winstonLogger;
910

1011
exports.detectLanguage = (cypress_config_filename) => {
@@ -78,9 +79,18 @@ exports.readCypressConfigFile = (bsConfig) => {
7879
return this.loadJsFile(compiled_cypress_config_filepath, bstack_node_modules_path)
7980
}
8081
} catch (error) {
81-
logger.error(`Error while reading cypress config: ${error.message}`)
82-
83-
// TODO: Add instrumention if error occurred
82+
const errorMessage = `Error while reading cypress config: ${error.message}`
83+
const errorCode = 'cypress_config_file_read_failed'
84+
logger.error(errorMessage)
85+
utils.sendUsageReport(
86+
bsConfig,
87+
null,
88+
errorMessage,
89+
constants.messageTypes.WARNING,
90+
errorCode,
91+
null,
92+
null
93+
)
8494
} finally {
8595
const working_dir = path.dirname(cypress_config_filepath);
8696
cp.execSync(`rm -rf ${config.compiledConfigJsDirName}`, { cwd: working_dir })

test/unit/bin/helpers/readCypressConfigUtil.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const logger = require("../../../../bin/helpers/logger").winstonLogger;
88

99
const cp = require("child_process");
1010
const fs = require("fs");
11-
const rewire = require("rewire");
11+
const utils = require("../../../../bin/helpers/utils");
1212
const readCypressConfigUtil = require("../../../../bin/helpers/readCypressConfigUtil");
1313

1414
logger.transports["console.info"].silent = true;
@@ -134,5 +134,27 @@ describe("readCypressConfigUtil", () => {
134134

135135
expect(result).to.eql({ e2e: {} });
136136
});
137+
138+
it('should handle error if any error occurred', () => {
139+
const bsConfig = {
140+
run_settings: {
141+
cypressConfigFilePath: 'path/to/cypress.config.js',
142+
cypress_config_filename: 'cypress.config.js'
143+
}
144+
};
145+
sandbox.stub(readCypressConfigUtil, 'loadJsFile').throws(new Error("Some error"));
146+
const sendUsageReportStub = sandbox.stub(utils, 'sendUsageReport');
147+
sandbox.stub(cp, 'execSync');
148+
149+
const result = readCypressConfigUtil.readCypressConfigFile(bsConfig);
150+
151+
expect(result).to.eql(undefined);
152+
sinon.assert.calledWithExactly(sendUsageReportStub, {
153+
run_settings: {
154+
cypressConfigFilePath: 'path/to/cypress.config.js',
155+
cypress_config_filename: 'cypress.config.js'
156+
}
157+
}, null, 'Error while reading cypress config: Some error', 'warning','cypress_config_file_read_failed', null, null)
158+
});
137159
});
138160
});

0 commit comments

Comments
 (0)