Skip to content

Commit f0e8992

Browse files
07souravkundafrancisf
authored andcommitted
add verbose logs
1 parent 5c9f475 commit f0e8992

File tree

11 files changed

+142
-18
lines changed

11 files changed

+142
-18
lines changed

bin/commands/runs.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ const archiver = require("../helpers/archiver"),
2222
const { getStackTraceUrl } = require('../helpers/sync/syncSpecsLogs');
2323

2424
module.exports = function run(args, rawArgs) {
25+
26+
// set debug mode (--cli-debug)
27+
utils.setDebugMode(args);
28+
2529
let bsConfigPath = utils.getConfigPath(args.cf);
30+
logger.debug(`browserstack.json path : ${bsConfigPath}`);
2631
//Delete build_results.txt from log folder if already present.
2732
initTimeComponents();
2833
instrumentEventTime("cliStart")
@@ -31,9 +36,12 @@ module.exports = function run(args, rawArgs) {
3136
markBlockEnd('deleteOldResults');
3237

3338
markBlockStart('validateBstackJson');
39+
logger.debug('Started browserstack.json validation');
3440
return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
3541
markBlockEnd('validateBstackJson');
42+
logger.debug('Completed browserstack.json validation');
3643
markBlockStart('setConfig');
44+
logger.debug('Started setting the configs');
3745
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
3846

3947
utils.setDefaults(bsConfig, args);
@@ -95,12 +103,16 @@ module.exports = function run(args, rawArgs) {
95103
// set other cypress configs e.g. reporter and reporter-options
96104
utils.setOtherConfigs(bsConfig, args);
97105
markBlockEnd('setConfig');
106+
logger.debug("Completed setting the configs");
98107

99108
// Validate browserstack.json values and parallels specified via arguments
100109
markBlockStart('validateConfig');
110+
logger.debug("Started configs validation");
101111
return capabilityHelper.validate(bsConfig, args).then(function (cypressJson) {
102112
markBlockEnd('validateConfig');
113+
logger.debug("Completed configs validation");
103114
markBlockStart('preArchiveSteps');
115+
logger.debug("Started pre-archive steps");
104116
//get the number of spec files
105117
let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson);
106118

@@ -115,36 +127,51 @@ module.exports = function run(args, rawArgs) {
115127
// warn if specFiles cross our limit
116128
utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs);
117129
markBlockEnd('preArchiveSteps');
130+
logger.debug("Completed pre-archive steps");
118131
markBlockStart('zip');
132+
logger.debug("Checking if test suite zip and dependencies is already available on browserstack");
119133
markBlockStart('zip.checkAlreadyUploaded');
120134
return checkUploaded.checkUploadedMd5(bsConfig, args, {markBlockStart, markBlockEnd}).then(function (md5data) {
121135
markBlockEnd('zip.checkAlreadyUploaded');
136+
logger.debug("Completed checking if test suite zip and dependencies already uploaded");
122137

138+
logger.debug("Started caching npm dependencies.");
123139
markBlockStart('zip.packageInstaller');
124140
return packageInstaller.packageWrapper(bsConfig, config.packageDirName, config.packageFileName, md5data, {markBlockStart, markBlockEnd}).then(function (packageData) {
141+
logger.debug("Completed caching npm dependencies.")
125142
markBlockEnd('zip.packageInstaller');
126143

127144
// Archive the spec files
145+
logger.debug("Started archiving test suite");
128146
markBlockStart('zip.archive');
129147
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
148+
logger.debug("Completed archiving test suite");
130149
markBlockEnd('zip.archive');
131150

132151
let test_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.fileName));
133152
let npm_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.packageFileName));
134153

135154
// Uploaded zip file
155+
logger.debug("Started uploading the test suite zip");
156+
logger.debug("Started uploading the node_module zip");
136157
markBlockStart('zip.zipUpload');
137158
return zipUploader.zipUpload(bsConfig, md5data, packageData).then(async function (zip) {
159+
logger.debug("Completed uploading the test suite zip");
160+
logger.debug("Completed uploading the node_module zip");
138161
markBlockEnd('zip.zipUpload');
139162
markBlockEnd('zip');
140163

141164
// Create build
142165
//setup Local Testing
143166
markBlockStart('localSetup');
167+
logger.debug("Started setting up BrowserStack Local connection");
144168
let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs);
169+
logger.debug('Completed setting up BrowserStack Local connection');
145170
markBlockEnd('localSetup');
171+
logger.debug("Started build creation");
146172
markBlockStart('createBuild');
147173
return build.createBuild(bsConfig, zip).then(function (data) {
174+
logger.debug("Completed build creation");
148175
markBlockEnd('createBuild');
149176
markBlockEnd('total');
150177
utils.setProcessHooks(data.build_id, bsConfig, bs_local, args);
@@ -177,7 +204,9 @@ module.exports = function run(args, rawArgs) {
177204

178205

179206
if (args.sync) {
207+
logger.debug("Started polling build status from BrowserStack");
180208
syncRunner.pollBuildStatus(bsConfig, data, rawArgs).then(async (exitCode) => {
209+
logger.debug("Completed polling of build status");
181210

182211
// stop the Local instance
183212
await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
@@ -188,6 +217,7 @@ module.exports = function run(args, rawArgs) {
188217
// download build artifacts
189218
if (exitCode != Constants.BUILD_FAILED_EXIT_CODE) {
190219
if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
220+
logger.debug("Downloading build artifacts");
191221
await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs);
192222
}
193223

bin/helpers/archiver.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const archiver = require("archiver"),
1010
const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
1111
return new Promise(function (resolve, reject) {
1212
if (md5data.zipUrlPresent) {
13+
logger.debug("Skipping test suite upload since BrowserStack already has your test suite that has not changed since the last run.");
1314
return resolve('Zipping not required');
1415
}
1516
var output = fs.createWriteStream(filePath);
@@ -55,6 +56,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
5556
archive.pipe(output);
5657

5758
let ignoreFiles = utils.getFilesToIgnore(runSettings, excludeFiles);
59+
logger.debug(`Patterns ignored during zip ${ignoreFiles}`);
5860
archive.glob(`**/*.+(${Constants.allowedFileTypes.join("|")})`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles, dot:true });
5961

6062
let packageJSON = {};

bin/helpers/capabilityHelper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ const addCypressZipStartLocation = (runSettings) => {
146146
let resolvedCypressConfigFilePath = path.resolve(runSettings.cypressConfigFilePath);
147147
runSettings.cypressZipStartLocation = path.dirname(resolvedCypressConfigFilePath.split(resolvedHomeDirectoryPath)[1]);
148148
runSettings.cypressZipStartLocation = runSettings.cypressZipStartLocation.substring(1);
149+
logger.debug(`Setting cypress zip start location = ${runSettings.cypressZipStartLocation}`);
149150
}
150151

151152
const validate = (bsConfig, args) => {
@@ -190,8 +191,10 @@ const validate = (bsConfig, args) => {
190191
let cypressConfigFilePath = bsConfig.run_settings.cypressConfigFilePath;
191192
let cypressJson = {};
192193

194+
logger.debug(`Checking for cypress config file at ${cypressConfigFilePath}`);
193195
if (!fs.existsSync(cypressConfigFilePath) && bsConfig.run_settings.cypress_config_filename !== 'false') reject(Constants.validationMessages.INVALID_CYPRESS_CONFIG_FILE);
194196

197+
logger.debug("Validating cypress.json");
195198
try {
196199
if (bsConfig.run_settings.cypress_config_filename !== 'false') {
197200
let cypressJsonContent = fs.readFileSync(cypressConfigFilePath);
@@ -210,6 +213,7 @@ const validate = (bsConfig, args) => {
210213
//check if home_directory is present or not in user run_settings
211214
if (!Utils.isUndefined(bsConfig.run_settings.home_directory)) {
212215
// check if home_directory exists or not
216+
logger.debug(`Validating home_directory at ${bsConfig.run_settings.home_directory}`);
213217
if (!fs.existsSync(bsConfig.run_settings.home_directory)) {
214218
reject(Constants.validationMessages.HOME_DIRECTORY_NOT_FOUND);
215219
}

bin/helpers/checkUploaded.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const crypto = require('crypto'),
77
config = require('./config'),
88
path = require('path'),
99
fs = require("fs"),
10-
utils = require('./utils');
10+
utils = require('./utils'),
11+
logger = require('./logger').winstonLogger;
1112

1213

1314
const checkSpecsMd5 = (runSettings, args, instrumentBlocks) => {
@@ -83,6 +84,7 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
8384
packageUrlPresent: false,
8485
};
8586
if (args["force-upload"]) {
87+
logger.debug("force-upload set to true. Uploading tests and npm packages.");
8688
return resolve(obj);
8789
}
8890

bin/helpers/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ const cliMessages = {
155155
NO_NPM_WARNING: "No NPM warning if npm_dependencies is empty",
156156
CONFIG_DEMAND: "config file is required",
157157
CONFIG_FILE_PATH: "Path to BrowserStack config",
158+
DEBUG: "Use this option to get debug logs on the CLI console.",
158159
},
159160
GENERATE_REPORT: {
160161
INFO: "Generates the build report"

bin/helpers/fileHelpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ exports.deletePackageArchieve = (logging = true) => {
4545
return 0;
4646
} catch (err) {
4747
if (logging) logger.info(Constants.userMessages.NPM_DELETE_FAILED);
48+
logger.debug("Could not delete the dependency packages with error :", err);
4849
return 1;
4950
}
5051
};

bin/helpers/logger.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,47 @@ if (!fs.existsSync(logDir)) {
88
fs.mkdirSync(logDir);
99
}
1010

11+
// Save transports to change log level dynamically
12+
const transports = {
13+
loggerConsole: new winston.transports.Console({
14+
name: 'console.info',
15+
colorize: true,
16+
timestamp: function () {
17+
return `[${new Date().toLocaleString()}]`;
18+
},
19+
prettyPrint: true,
20+
}),
21+
syncLoggerConsole: new (winston.transports.Console)({
22+
formatter: (options) => {
23+
return (options.message ? options.message : '');
24+
}
25+
}),
26+
loggerFile: new winston.transports.File({
27+
filename: path.join(logDir, "/usage.log"),
28+
}),
29+
}
30+
1131
const winstonLoggerParams = {
1232
transports: [
13-
new winston.transports.Console({
14-
name: 'console.info',
15-
colorize: true,
16-
timestamp: function () {
17-
return `[${new Date().toLocaleString()}]`;
18-
},
19-
prettyPrint: true,
20-
}),
33+
transports.loggerConsole,
2134
],
2235
};
2336

2437
const winstonSyncCliLoggerParams = {
2538
transports: [
26-
new (winston.transports.Console)({
27-
formatter: (options) => {
28-
return (options.message ? options.message : '');
29-
}
30-
}),
39+
transports.syncLoggerConsole,
3140
]
3241
}
3342

3443
const winstonFileLoggerParams = {
3544
transports: [
36-
new winston.transports.File({
37-
filename: path.join(logDir, "/usage.log"),
38-
}),
45+
transports.loggerFile,
3946
],
4047
};
4148

4249
exports.winstonLogger = new winston.Logger(winstonLoggerParams);
4350
exports.fileLogger = new winston.Logger(winstonFileLoggerParams);
4451
exports.syncCliLogger = new winston.Logger(winstonSyncCliLoggerParams);
52+
53+
//Export transports to change log level
54+
exports.transports = transports;

bin/helpers/packageInstaller.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ let nodeProcess;
1515
const setupPackageFolder = (runSettings, directoryPath) => {
1616
return new Promise(function (resolve, reject) {
1717
fileHelpers.deletePackageArchieve(false);
18+
logger.debug(`Started creating ${directoryPath} folder`);
1819
fs.mkdir(directoryPath, function (err) {
1920
try {
2021
if (err) {
2122
return reject(err);
2223
}
24+
logger.debug(`Completed creating ${directoryPath}`);
2325
let packageJSON = {};
2426
if (typeof runSettings.package_config_options === 'object') {
2527
Object.assign(packageJSON, runSettings.package_config_options);
@@ -39,12 +41,16 @@ const setupPackageFolder = (runSettings, directoryPath) => {
3941
let sourceNpmrc = path.join(cypressFolderPath, ".npmrc");
4042
let destNpmrc = path.join(directoryPath, ".npmrc");
4143
if (fs.existsSync(sourceNpmrc)) {
44+
logger.debug(`Copying .npmrc file from ${sourceNpmrc} to ${destNpmrc}`);
4245
fs.copyFileSync(sourceNpmrc, destNpmrc);
4346
}
47+
logger.debug(`${packagePath} file created with ${packageJSONString}`);
4448
return resolve("Package file created");
4549
}
50+
logger.debug("Nothing in package file");
4651
return reject("Nothing in package file");
4752
} catch(error) {
53+
logger.debug(`Creating ${directoryPath} failed with error ${error}`);
4854
return reject(error);
4955
}
5056
})
@@ -82,6 +88,7 @@ const packageArchiver = (packageDir, packageFile) => {
8288
if (err.code === 'ENOENT') {
8389
logger.info(err);
8490
} else {
91+
logger.debug(`Archiving of node_modules failed with error ${err}`);
8592
reject(err);
8693
}
8794
});
@@ -95,6 +102,7 @@ const packageArchiver = (packageDir, packageFile) => {
95102
});
96103

97104
archive.on('error', function (err) {
105+
logger.debug(`Archiving of node_modules failed with error ${err}`);
98106
reject(err);
99107
});
100108

@@ -110,24 +118,32 @@ const packageWrapper = (bsConfig, packageDir, packageFile, md5data, instrumentBl
110118
packageArchieveCreated: false
111119
};
112120
if (md5data.packageUrlPresent || !utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
121+
logger.debug("Skipping the caching of npm packages since BrowserStack has already cached your npm dependencies that have not changed since the last run.")
113122
return resolve(obj);
114123
}
115124
logger.info(Constants.userMessages.NPM_INSTALL_AND_UPLOAD);
116125
instrumentBlocks.markBlockStart("packageInstaller.folderSetup");
126+
logger.debug("Started setting up package folder");
117127
return setupPackageFolder(bsConfig.run_settings, packageDir).then((_result) => {
128+
logger.debug("Completed setting up package folder");
118129
process.env.CYPRESS_INSTALL_BINARY = 0
119130
instrumentBlocks.markBlockEnd("packageInstaller.folderSetup");
120131
instrumentBlocks.markBlockStart("packageInstaller.packageInstall");
132+
logger.debug("Started installing dependencies specified in browserstack.json");
121133
return packageInstall(packageDir);
122134
}).then((_result) => {
135+
logger.debug("Completed installing dependencies");
123136
instrumentBlocks.markBlockEnd("packageInstaller.packageInstall");
124137
instrumentBlocks.markBlockStart("packageInstaller.packageArchive");
138+
logger.debug("Started archiving node_modules")
125139
return packageArchiver(packageDir, packageFile);
126140
}).then((_result) => {
141+
logger.debug("Archiving of node_modules completed");
127142
instrumentBlocks.markBlockEnd("packageInstaller.packageArchive");
128143
Object.assign(obj, { packageArchieveCreated: true });
129144
return resolve(obj);
130145
}).catch((err) => {
146+
logger.warn(`Error occured while caching npm dependencies. Dependencies will be installed in runtime. This will have a negative impact on performance. Reach out to browserstack.com/contact, if you persistantly face this issue.`);
131147
obj.error = err.stack ? err.stack.toString().substring(0,100) : err.toString().substring(0,100);
132148
return resolve(obj);
133149
})

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ let setNoWrapParams = () => {
8989
noWrap = (process.env.SYNC_NO_WRAP && (process.env.SYNC_NO_WRAP === 'true'));
9090
// Do not show the separator based on terminal width if no-wrap provided.
9191
if (noWrap) {
92+
winstonLogger.debug("no-wrap is set to true, showing the default line separator irrespective of terminal width");
9293
lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
94+
} else {
95+
winstonLogger.debug("no-wrap set to false, showing line separator based on terminal width.");
9396
}
9497
};
9598

@@ -109,6 +112,7 @@ let printSpecsStatus = (bsConfig, buildDetails, rawArgs) => {
109112
},
110113
function(err, result) { // when loop ends
111114
if (err) {
115+
winstonLogger.debug(`Error while fetching spec status :`, err);
112116
if(err.status == 204) {
113117
reject(specSummary.exitCode);
114118
} else {

0 commit comments

Comments
 (0)