Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browserstack-cypress-cli

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserstack-cypress-cli - npm Package Compare versions

Comparing version 1.1.2 to 1.1.4

bin/helpers/usageReporting.js

117

bin/commands/info.js
'use strict';
var config = require('../helpers/config');
var request = require('request')
var logger = require("../helpers/logger");
var Constant = require("../helpers/constants")
const request = require('request');
const config = require("../helpers/config"),
logger = require("../helpers/logger").winstonLogger,
Constants = require("../helpers/constants"),
util = require("../helpers/util");
module.exports = function info(args) {

@@ -13,44 +15,81 @@ return buildInfo(args)

let bsConfigPath = process.cwd() + args.cf;
logger.log(`Reading config from ${args.cf}`);
var bsConfig = require(bsConfigPath);
let buildId = args._[1]
util.validateBstackJson(bsConfigPath).then(function (bsConfig) {
util.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
let options = {
url: config.buildUrl + buildId,
method: 'GET',
auth: {
user: bsConfig.auth.username,
password: bsConfig.auth.access_key
}
}
let buildId = args._[1];
request(options, function (err, resp, body) {
if (err) {
logger.log(Constant.userMessages.BUILD_INFO_FAILED);
} else {
let build = null
try {
build = JSON.parse(body)
} catch (error) {
build = null
}
if (resp.statusCode != 200) {
if (build) {
logger.error(`${Constant.userMessages.BUILD_INFO_FAILED} with error: \n${JSON.stringify(build, null, 2)}`);
} else {
logger.error(Constant.userMessages.BUILD_INFO_FAILED);
let options = {
url: config.buildUrl + buildId,
method: "GET",
auth: {
user: bsConfig.auth.username,
password: bsConfig.auth.access_key,
},
headers: {
"User-Agent": util.getUserAgent(),
},
};
request(options, function (err, resp, body) {
let message = null;
let messageType = null;
let errorCode = null;
if (err) {
message = Constants.userMessages.BUILD_INFO_FAILED;
messageType = Constants.messageTypes.ERROR;
errorCode = 'api_failed_build_info';
logger.info(message);
} else {
let build = null;
try {
build = JSON.parse(body);
} catch (error) {
build = null;
}
} else if(resp.statusCode == 299) {
if(build) {
logger.log(build.message);
if (resp.statusCode == 299) {
messageType = Constants.messageTypes.INFO;
errorCode = "api_deprecated";
if (build) {
message = build.message;
logger.info(message);
} else {
message = Constants.userMessages.API_DEPRECATED;
logger.info(message);
}
} else if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = "api_failed_build_info";
if (build) {
message = `${
Constants.userMessages.BUILD_INFO_FAILED
} with error: \n${JSON.stringify(build, null, 2)}`;
logger.error(message);
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
} else {
message = Constants.userMessages.BUILD_INFO_FAILED;
logger.error(message);
}
} else {
logger.log(Constants.userMessages.API_DEPRECATED);
messageType = Constants.messageTypes.SUCCESS;
message = `Build info for build id: \n ${JSON.stringify(
build,
null,
2
)}`;
logger.info(message);
}
} else {
logger.log(`Build info for build id: \n ${JSON.stringify(build, null, 2)}`)
}
}
})
util.sendUsageReport(bsConfig, args, message, messageType, errorCode);
})
}).catch(function (err) {
logger.error(err);
util.setUsageReportingFlag(null, args.disableUsageReporting);
util.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, util.getErrorCodeFromErr(err));
})
}
'use strict';
var fileHelpers = require('../helpers/fileHelpers');
const Constants = require('../helpers/constants');
var logger = require("../helpers/logger");
const fileHelpers = require("../helpers/fileHelpers"),
Constants = require("../helpers/constants"),
logger = require("../helpers/logger").winstonLogger,
util = require("../helpers/util");

@@ -24,3 +25,5 @@ module.exports = function init(args) {

function allDone() {
logger.log(Constants.userMessages.CONFIG_FILE_CREATED);
let message = Constants.userMessages.CONFIG_FILE_CREATED
logger.info(message);
util.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
}

@@ -30,3 +33,5 @@

if (exists) {
logger.error(Constants.userMessages.CONFIG_FILE_EXISTS);
let message = Constants.userMessages.CONFIG_FILE_EXISTS;
logger.error(message);
util.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists');
} else {

@@ -33,0 +38,0 @@ fileHelpers.write(config, null, allDone);

'use strict';
<<<<<<< HEAD
var archiver = require("../helpers/archiver");

@@ -10,3 +11,16 @@ var zipUploader = require("../helpers/zipUpload");

const Constants = require('../helpers/constants');
const fileHelpers = require('../helpers/fileHelpers');
=======
const fs = require('fs');
const archiver = require("../helpers/archiver"),
zipUploader = require("../helpers/zipUpload"),
build = require("../helpers/build"),
logger = require("../helpers/logger").winstonLogger,
config = require("../helpers/config"),
capabilityHelper = require("../helpers/capabilityHelper"),
Constants = require("../helpers/constants"),
util = require("../helpers/util");
>>>>>>> 11a63ce498033cc6a3814730eb9300f28f8c007a
module.exports = function run(args) {

@@ -19,6 +33,6 @@ return runCypress(args);

if(err) {
logger.log(Constants.userMessages.ZIP_DELETE_FAILED);
logger.info(Constants.userMessages.ZIP_DELETE_FAILED);
} else {
logger.log(Constants.userMessages.ZIP_DELETED);
}
logger.info(Constants.userMessages.ZIP_DELETED);
}
});

@@ -29,37 +43,58 @@ }

let bsConfigPath = process.cwd() + args.cf;
logger.log(`Reading config from ${args.cf}`);
var bsConfig = require(bsConfigPath);
// Validate browserstack.json
capabilityHelper.validate(bsConfig).then(function (validated) {
logger.log(validated);
// Archive the spec files
archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
// Uploaded zip file
zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
// Create build
build.createBuild(bsConfig, zip).then(function (data) {
return;
util.validateBstackJson(bsConfigPath).then(function (bsConfig) {
util.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
// Validate browserstack.json values
capabilityHelper.validate(bsConfig).then(function (validated) {
logger.info(validated);
// Archive the spec files
archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
// Uploaded zip file
zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
// Create build
build.createBuild(bsConfig, zip).then(function (message) {
logger.info(message);
util.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null);
return;
}).catch(function (err) {
// Build creation failed
logger.error(err);
util.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
});
}).catch(function (err) {
// Build creation failed
logger.error(Constants.userMessages.BUILD_FAILED)
// Zip Upload failed
logger.error(err)
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED)
util.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
}).finally(function () {
deleteZip();
});
}).catch(function (err) {
// Zip Upload failed
logger.error(err)
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED)
}).finally(function () {
deleteZip();
// Zipping failed
logger.error(err);
logger.error(Constants.userMessages.FAILED_TO_ZIP);
util.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
try {
deleteZip();
} catch (err) {
util.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
}
});
}).catch(function (err) {
// Zipping failed
logger.error(err)
logger.error(Constants.userMessages.FAILED_TO_ZIP)
deleteZip();
// browerstack.json is not valid
logger.error(err);
logger.error(Constants.validationMessages.NOT_VALID);
let error_code = util.getErrorCodeFromMsg(err);
util.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code);
});
}).catch(function (err) {
// browerstack.json is not valid
logger.error(err)
logger.error(Constants.validationMessages.NOT_VALID)
});
logger.error(err);
util.setUsageReportingFlag(null, args.disableUsageReporting);
util.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, util.getErrorCodeFromErr(err));
})
}
'use strict';
var config = require('../helpers/config');
var request = require('request')
var logger = require("../helpers/logger");
var Constant = require("../helpers/constants")
const request = require('request');
const config = require("../helpers/config"),
logger = require("../helpers/logger").winstonLogger,
Constants = require("../helpers/constants"),
util = require("../helpers/util");
module.exports = function stop(args) {

@@ -13,44 +15,77 @@ return buildStop(args)

let bsConfigPath = process.cwd() + args.cf;
logger.log(`Reading config from ${args.cf}`);
var bsConfig = require(bsConfigPath);
let buildId = args._[1]
util.validateBstackJson(bsConfigPath).then(function (bsConfig) {
util.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
let options = {
url: config.buildStopUrl + buildId,
method: 'POST',
auth: {
user: bsConfig.auth.username,
password: bsConfig.auth.access_key
}
}
let buildId = args._[1];
request(options, function (err, resp, body) {
if (err) {
logger.log(Constant.userMessages.BUILD_STOP_FAILED);
} else {
let build = null
try {
build = JSON.parse(body)
} catch (error) {
build = null
}
let options = {
url: config.buildStopUrl + buildId,
method: "POST",
auth: {
user: bsConfig.auth.username,
password: bsConfig.auth.access_key,
},
headers: {
"User-Agent": util.getUserAgent(),
},
};
if (resp.statusCode != 200) {
if (build) {
logger.error(`${Constant.userMessages.BUILD_STOP_FAILED} with error: \n${JSON.stringify(build, null, 2)}`);
} else {
logger.error(Constant.userMessages.BUILD_STOP_FAILED);
request(options, function (err, resp, body) {
let message = null;
let messageType = null;
let errorCode = null;
if (err) {
message = Constants.userMessages.BUILD_STOP_FAILED;
messageType = Constants.messageTypes.ERROR;
errorCode = 'api_failed_build_stop';
logger.info(message);
} else {
let build = null
try {
build = JSON.parse(body)
} catch (error) {
build = null
}
} else if (resp.statusCode == 299) {
if (build) {
logger.log(build.message);
if (resp.statusCode == 299) {
messageType = Constants.messageTypes.INFO;
errorCode = "api_deprecated";
if (build) {
message = build.message;
logger.info(message);
} else {
message = Constants.userMessages.API_DEPRECATED;
logger.info(message);
}
} else if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = "api_failed_build_stop";
if (build) {
message = `${
Constants.userMessages.BUILD_STOP_FAILED
} with error: \n${JSON.stringify(build, null, 2)}`;
logger.error(message);
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
} else {
message = Constants.userMessages.BUILD_STOP_FAILED;
logger.error(message);
}
} else {
logger.log(Constants.userMessages.API_DEPRECATED);
messageType = Constants.messageTypes.SUCCESS;
message = `${JSON.stringify(build, null, 2)}`;
logger.info(message);
}
} else {
logger.log(`${JSON.stringify(build, null, 2)}`)
}
}
util.sendUsageReport(bsConfig, args, message, messageType, errorCode);
})
}).catch(function (err) {
logger.error(err);
util.setUsageReportingFlag(null, args.disableUsageReporting);
util.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, util.getErrorCodeFromErr(err));
})
}

@@ -0,5 +1,6 @@

'use strict';
const fs = require("fs");
const fs = require('fs'),
archiver = require('archiver'),
logger = require("./logger");
const archiver = require("archiver"),
logger = require("./logger").winstonLogger;

@@ -18,5 +19,5 @@ const archiveSpecs = (runSettings, filePath) => {

if (err.code === 'ENOENT') {
logger.log(err)
logger.info(err);
} else {
reject(err)
reject(err);
}

@@ -26,11 +27,11 @@ });

output.on('close', function () {
resolve("Zipping completed")
resolve("Zipping completed");
});
output.on('end', function () {
logger.log('Data has been drained');
logger.info('Data has been drained');
});
archive.on('error', function (err) {
reject(err)
reject(err);
});

@@ -37,0 +38,0 @@

@@ -1,7 +0,9 @@

var request = require('request')
var logger = require("./logger")
var config = require('./config');
var capabilityHelper = require("../helpers/capabilityHelper");
const Constants = require('../helpers/constants');
'use strict';
const request = require('request');
const config = require('./config'),
capabilityHelper = require("../helpers/capabilityHelper"),
Constants = require('../helpers/constants'),
util =require('../helpers/util');
const createBuild = (bsConfig, zip) => {

@@ -17,3 +19,4 @@ return new Promise(function (resolve, reject) {

headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
"User-Agent": util.getUserAgent(),
},

@@ -25,25 +28,25 @@ body: data

if (err) {
reject(err)
reject(err);
} else {
let build = null
let build = null;
try {
build = JSON.parse(body)
build = JSON.parse(body);
} catch (error) {
build = null
build = null;
}
if (resp.statusCode != 201) {
if (resp.statusCode == 299) {
if (build) {
logger.error(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
resolve(build.message);
} else {
logger.error(Constants.userMessages.BUILD_FAILED);
reject(Constants.userMessages.API_DEPRECATED);
}
} else if(resp.statusCode == 299){
if(build) {
logger.log(build.message);
} else if (resp.statusCode != 201) {
if (build) {
reject(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
} else {
logger.log(Constants.userMessages.API_DEPRECATED);
reject(Constants.userMessages.BUILD_FAILED);
}
} else {
logger.log(build.message)
logger.log(`${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`);
resolve(`${build.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`);
}

@@ -50,0 +53,0 @@ resolve(build);

@@ -1,4 +0,3 @@

const logger = require("./logger"),
Constants = require('./constants'),
glob = require("glob");
const logger = require("./logger").winstonLogger,
Constants = require("./constants");

@@ -24,3 +23,3 @@ const caps = (bsConfig, zip) => {

if (obj.devices.length == 0) reject(Constants.validationMessages.EMPTY_BROWSER_LIST);
logger.log(`Browser list: ${osBrowserArray.toString()}`);
logger.info(`Browser list: ${osBrowserArray.toString()}`);

@@ -30,3 +29,3 @@ // Test suite

if (!obj.test_suite || 0 === obj.test_suite.length) reject("Test suite is empty");
logger.log(`Test suite: bs://${obj.test_suite}`);
logger.info(`Test suite: bs://${obj.test_suite}`);

@@ -36,9 +35,9 @@ // Local

if (bsConfig.connection_settings.local === true) obj.local = true;
logger.log(`Local is set to: ${obj.local}`);
logger.info(`Local is set to: ${obj.local}`);
// Local Identifier
obj.localIdentifier = null;
if (obj.local === true && bsConfig.connection_settings.localIdentifier)
if (obj.local === true && (bsConfig.connection_settings.localIdentifier || bsConfig.connection_settings.local_identifier))
{
obj.localIdentifier = bsConfig.connection_settings.localIdentifier;
obj.localIdentifier = bsConfig.connection_settings.localIdentifier || bsConfig.connection_settings.local_identifier;
logger.log(`Local Identifier is set to: ${obj.localIdentifier}`);

@@ -48,11 +47,7 @@ }

// Project name
obj.project = bsConfig.run_settings.project
obj.project = bsConfig.run_settings.project || bsConfig.run_settings.project_name;
if (!obj.project) logger.log(`Project name is: ${obj.project}`);
// Base url
obj.base_url = bsConfig.run_settings.baseUrl
if (obj.base_url) logger.log(`Base url is : ${obj.base_url}`);
// Build name
obj.customBuildName = bsConfig.run_settings.customBuildName
obj.customBuildName = bsConfig.run_settings.customBuildName || bsConfig.run_settings.build_name;
if (obj.customBuildName) logger.log(`Build name is: ${obj.customBuildName}`);

@@ -62,7 +57,7 @@

obj.callbackURL = bsConfig.run_settings.callback_url
if (obj.callbackURL) logger.log(`callback url is : ${obj.callbackURL}`);
if (obj.callbackURL) logger.info(`callback url is : ${obj.callbackURL}`);
//projectNotifyURL
obj.projectNotifyURL = bsConfig.run_settings.project_notify_URL
if (obj.projectNotifyURL) logger.log(`Project notify URL is: ${obj.projectNotifyURL}`);
if (obj.projectNotifyURL) logger.info(`Project notify URL is: ${obj.projectNotifyURL}`);

@@ -69,0 +64,0 @@ var data = JSON.stringify(obj);

@@ -14,3 +14,5 @@ var config = {};

config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
config.usageReportingUrl = `https://eds.browserstack.com:443/send_event_cy_internal`;
config.fileName = "tests.zip";
module.exports = config;

@@ -11,3 +11,3 @@ const userMessages = {

ZIP_DELETE_FAILED: "Could not delete local file.",
ZIP_DELETED: "File deleted successfully.",
ZIP_DELETED: "Zip file deleted successfully.",
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",

@@ -18,12 +18,14 @@ FAILED_TO_ZIP: "Failed to zip files."

const validationMessages = {
INCORRECT_AUTH_PARAMS: "Incorrect auth params.",
EMPTY_BROWSER_LIST: "Browser list is empty",
EMPTY_TEST_SUITE: "Test suite is empty",
EMPTY_BROWSERSTACK_JSON: "Empty browserstack.json",
EMPTY_RUN_SETTINGS: "Empty run settings",
EMPTY_SPEC_FILES: "No spec files specified in run_settings",
VALIDATED: "browserstack.json file is validated",
NOT_VALID: "browerstack.json is not valid",
INVALID_EXTENSION: "Invalid files, please remove these files and try again."
INCORRECT_AUTH_PARAMS: "Incorrect auth params.",
EMPTY_BROWSER_LIST: "Browser list is empty",
EMPTY_TEST_SUITE: "Test suite is empty",
EMPTY_BROWSERSTACK_JSON: "Empty browserstack.json",
EMPTY_RUN_SETTINGS: "Empty run settings",
EMPTY_SPEC_FILES: "No spec files specified in run_settings",
VALIDATED: "browserstack.json file is validated",
NOT_VALID: "browerstack.json is not valid",
NOT_VALID_JSON: "browerstack.json is not a valid json",
INVALID_EXTENSION: "Invalid files, please remove these files and try again.",
};
const cliMessages = {

@@ -52,9 +54,22 @@ VERSION: {

CONFIG_DEMAND: "config file is required"
},
COMMON: {
DISABLE_USAGE_REPORTING: "Disable usage reporting"
}
}
const messageTypes = {
SUCCESS: "success",
ERROR: "error",
INFO: "info",
WARNING: "warning",
UNKNOWN: "unknown",
NULL: null
}
module.exports = Object.freeze({
userMessages,
cliMessages,
validationMessages
})
userMessages,
cliMessages,
validationMessages,
messageTypes,
});
'use strict';
var fs = require('fs-extra');
var path = require('path');
var mkdirp = require('mkdirp')
const fs = require('fs-extra'),
path = require('path'),
mkdirp = require('mkdirp');
const logger = require('./logger').winstonLogger;
exports.isEmpty = function(path, cb) {

@@ -36,3 +38,3 @@ fs.readdir(path, function(err, files) {

if (err) throw err;
console.log('Creating directory: ./' + path.relative(process.cwd(), dir))
logger.info("Creating directory: ./" + path.relative(process.cwd(), dir));
cb && cb()

@@ -45,3 +47,3 @@ })

fs.writeFile(f.path, f.file, function() {
console.log(message + ' file: ./' + path.relative(process.cwd(), f.path));
logger.info(message + " file: ./" + path.relative(process.cwd(), f.path));
cb && cb()

@@ -48,0 +50,0 @@ });

@@ -1,12 +0,32 @@

function log(message) {
var timestamp = '[' + new Date().toLocaleString() + '] ';
console.log(timestamp + " " + message);
}
const winston = require('winston'),
fs = require("fs"),
path = require("path");
function error(message) {
var timestamp = '[' + new Date().toLocaleString() + '] ';
console.log(timestamp + " [ERROR] " + message);
const logDir = "log"; // directory path for logs
if (!fs.existsSync(logDir)) {
// Create the directory if it does not exist
fs.mkdirSync(logDir);
}
exports.log = log
exports.error = error
const winstonLoggerParams = {
transports: [
new winston.transports.Console({
colorize: true,
timestamp: function () {
return `[${new Date().toLocaleString()}]`;
},
prettyPrint: true,
}),
],
};
const winstonFileLoggerParams = {
transports: [
new winston.transports.File({
filename: path.join(logDir, "/usage.log"),
}),
],
};
exports.winstonLogger = new winston.Logger(winstonLoggerParams);
exports.fileLogger = new winston.Logger(winstonFileLoggerParams);

@@ -1,6 +0,8 @@

var config = require('./config');
var request = require('request')
var fs = require('fs');
var logger = require("./logger")
const Constants = require("./constants")
'use strict';
const config = require("./config"),
request = require("request"),
fs = require("fs"),
logger = require("./logger").winstonLogger,
Constants = require("./constants"),
util = require("./util");

@@ -19,5 +21,9 @@ const uploadCypressZip = (bsConfig, filePath) => {

filename: 'tests'
},
headers: {
"User-Agent": util.getUserAgent(),
}
}
let responseData = null;
request.post(options, function (err, resp, body) {

@@ -39,3 +45,3 @@ if (err) {

} else {
logger.log(`Zip uploaded with url: ${responseData.zip_url}`);
logger.info(`Zip uploaded with url: ${responseData.zip_url}`);
resolve(responseData);

@@ -42,0 +48,0 @@ }

#!/usr/bin/env node
'use strict';
const yargs = require('yargs'),
logger = require("./helpers/logger").winstonLogger,
Constants = require('./helpers/constants');
const yargs = require('yargs')
var logger = require("./helpers/logger");
const Constants = require('./helpers/constants');
function checkCommands(yargs, argv, numRequired) {

@@ -25,12 +25,18 @@ if (argv._.length < numRequired) {

argv = yargs
.usage('usage: $0 init [options]')
.options('p', {
alias: 'path',
default: false,
description: Constants.cliMessages.INIT.DESC,
type: 'string'
.usage("usage: $0 init [options]")
.options({
'p': {
alias: "path",
default: false,
description: Constants.cliMessages.INIT.DESC,
type: "string",
},
'disable-usage-reporting': {
default: undefined,
description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING,
type: "boolean"
},
})
.help('help')
.wrap(null)
.argv
.help("help")
.wrap(null).argv;

@@ -45,10 +51,17 @@ if (checkCommands(yargs, argv, 1)) {

.demand(1, Constants.cliMessages.BUILD.DEMAND)
.options('cf', {
alias: 'config-file',
describe: Constants.cliMessages.BUILD.DESC,
default: '/browserstack.json',
type: 'string',
nargs: 1,
demand: true,
demand: Constants.cliMessages.BUILD.CONFIG_DEMAND
.options({
'cf': {
alias: 'config-file',
describe: Constants.cliMessages.BUILD.DESC,
default: '/browserstack.json',
type: 'string',
nargs: 1,
demand: true,
demand: Constants.cliMessages.BUILD.CONFIG_DEMAND
},
'disable-usage-reporting': {
default: undefined,
description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING,
type: "boolean"
},
})

@@ -59,3 +72,3 @@ .help('help')

if (checkCommands(yargs, argv, 1)) {
logger.log(Constants.cliMessages.BUILD.INFO_MESSAGE + argv._[1]);
logger.info(Constants.cliMessages.BUILD.INFO_MESSAGE + argv._[1]);
return require('./commands/info')(argv);

@@ -68,10 +81,17 @@ }

.demand(1, Constants.cliMessages.BUILD.DEMAND)
.options('cf', {
alias: 'config-file',
describe: Constants.cliMessages.BUILD.DESC,
default: '/browserstack.json',
type: 'string',
nargs: 1,
demand: true,
demand: Constants.cliMessages.BUILD.CONFIG_DEMAND
.options({
'cf': {
alias: 'config-file',
describe: Constants.cliMessages.BUILD.DESC,
default: '/browserstack.json',
type: 'string',
nargs: 1,
demand: true,
demand: Constants.cliMessages.BUILD.CONFIG_DEMAND
},
'disable-usage-reporting': {
default: undefined,
description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING,
type: "boolean"
},
})

@@ -82,3 +102,3 @@ .help('help')

if (checkCommands(yargs, argv, 1)) {
logger.log(Constants.cliMessages.BUILD.STOP_MESSAGE + argv._[1]);
logger.info(Constants.cliMessages.BUILD.STOP_MESSAGE + argv._[1]);
return require('./commands/stop')(argv);

@@ -90,10 +110,17 @@ }

.usage('usage: $0 build')
.options('cf', {
alias: 'config-file',
describe: Constants.cliMessages.RUN.DESC,
default: '/browserstack.json',
type: 'string',
nargs: 1,
demand: true,
demand: Constants.cliMessages.RUN.CONFIG_DEMAND
.options({
'cf': {
alias: 'config-file',
describe: Constants.cliMessages.RUN.DESC,
default: '/browserstack.json',
type: 'string',
nargs: 1,
demand: true,
demand: Constants.cliMessages.RUN.CONFIG_DEMAND
},
'disable-usage-reporting': {
default: undefined,
description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING,
type: "boolean"
},
})

@@ -100,0 +127,0 @@ .help('help')

@@ -16,9 +16,10 @@ module.exports = function () {

"cypress_proj_dir" : "/path/to/cypress.json",
"project": "project-name",
"customBuildName": "build-name"
"project_name": "project-name",
"build_name": "build-name"
},
"connection_settings": {
"local": false,
"localIdentifier": null
}
"local_identifier": null
},
"disable_usage_reporting": false
}

@@ -25,0 +26,0 @@ var EOL = require('os').EOL

{
"name": "browserstack-cypress-cli",
"version": "1.1.2",
"version": "1.1.4",
"description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",

@@ -19,2 +19,4 @@ "main": "index.js",

"request": "^2.88.0",
"requestretry": "^4.1.0",
"winston": "^2.3.1",
"yargs": "^14.2.2"

@@ -21,0 +23,0 @@ },

@@ -1,32 +0,29 @@

- [BrowserStack Cypress CLI](#browserstack-cypress-cli)
- [Using BrowserStack-Cypress CLI:](#using-browserstack-cypress-cli)
- [Installing browserstack-cypress](#installing-browserstack-cypress)
- [Configuring your tests](#configuring-your-tests)
- [Running the tests](#running-the-tests)
- [Getting build information](#getting-build-information)
- [Limitations](#limitations)
- [Accessing test results](#accessing-test-results)
- [License](#license)
# BrowserStack Cypress CLI
You can now run your Cypress tests in BrowserStack using our `browserstack-cypress-cli`. BrowserStack currently supports Cypress 4 and you can start testing on the following browser combinations:
[![npm version](https://badge.fury.io/js/browserstack-cypress-cli.svg)](https://badge.fury.io/js/browserstack-cypress-cli)
| Windows 10 | OS X Mojave | OS X Catalina |
|:---------------------:|:---------------------:|:--------------------:|
| Chrome 66.0 to 79.0 | Chrome 66.0 to 79.0 | Chrome 66.0 to 79.0 |
| Edge 80.0 | Edge 80.0 | Edge 80.0 |
| Firefox 60.0 to 72.0| Firefox 60.0 to 72.0 | Firefox 60.0 to 72.0|
The `browserstack-cypress-cli` is BrowserStack's command-line interface (CLI) which
allows you to run your Cypress tests on BrowserStack.
- [Quick Start](#quick-start)
- [Configuration Options](#configuration-options)
- [Authentication](#authentication)
- [Specify Browsers](#specify-browsers)
- [Configure Test Runs](#configure-test-runs)
- [Configure Connection Settings](#configure-connection-settings)
- [Disable Usage Reporting](#disable-usage-reporting)
- [Deprecated Options](#deprecated-options)
- [CLI Arguments & Flags](#cli-arguments--flags)
- [Run the Tests](#run-the-tests)
- [Get the Build Information](#get-the-build-information)
- [Stop a Running Build](#stop-a-running-build)
- [Disable CLI Usage Reporting](#disable-cli-usage-reporting)
- [Limitations](#limitations)
- [License](#license)
We are actively working on supporting other browsers and will start adding other browsers to this list.
## Quick Start
## Using BrowserStack-Cypress CLI:
First, install the CLI:
### Installing browserstack-cypress
```bash
# Install cypress (ignore if already done)
$ npm install -g cypress@4.0.2
# Install the BrowserStack Cypress CLI

@@ -36,10 +33,38 @@ $ npm install -g browserstack-cypress-cli

### Configuring your tests
Note that we run tests that are written using Cypress 4.0 and above. Update to
a newer version if you are using an older version of Cypress and update your
tests if required.
Next, set up your BrowserStack credentials and configure the browsers that you
want to run your tests on. Use the `init` command to generate a sample
`browserstack.json` file, or alternatively create one from scratch.
```bash
# create a sample configuration file for configurations and capabilities
# Create a sample configuration file for configurations and capabilities
$ browserstack-cypress init
```
This will create a sample `browserstack.json` file. This file can be used to configure your test runs on BrowserStack. Below is the sample file that is generated for your reference.
Fill in the `auth`, `browsers`, `run_settings` values to be able to run your
tests. Refer to the [configuration options](#configuration-options) to learn
more about all the options you can use in `browserstack.json` and the possible
values.
Then, run your tests on BrowserStack:
```bash
$ browserstack-cypress run
```
You can access the test results on the [BrowserStack Automate dashboard](https://automate.browserstack.com/).
## Configuration Options
The `init` command will create a sample `browserstack.json` file. This file can
be used to configure your test runs on BrowserStack. Below is the sample file
that is generated for your reference.
You can also specify `--path <path-to-folder-where-you-need-init-to-run>` flag
along with the `init` command to generate `browserstack.json` file in the
specified folder.
```json

@@ -60,30 +85,150 @@ {

"cypress_proj_dir": "/path/to/directory-that-contains-<cypress.json>-file",
"project": "my first project",
"customBuildName": "build 1"
"project_name": "my first project",
"build_name": "build 1"
},
"connection_settings": {
"local": false,
"localIdentifier": null
"local_identifier": null
},
"disable_usage_reporting": "false"
}
```
Here are all the options that you can provide in the `browserstack.json`:
### Authentication
You can use the `auth` option to specify your username and access keys. You
can find them in your [Automate dashboard](https://automate.browserstack.com/)
| Option | Description | Possible values |
| ------------ | ----------------------------- | --------------- |
| `username` | Your BrowserStack username. | - |
| `access_key` | Your BrowserStack access key. | - |
Example:
```json
{
"auth": {
"username": "<your-browserstack-username>",
"access_key": "<your-browserstack-access-key>"
}
}
```
### Specify Browsers
You can use the `browsers` option to specify the list of OS, browser and browser
versions. Each browser combination should contain the following details:
| Option | Description | Possible values |
| ---------- | ---------------------------------------------- | -------------------------------------------------------------- |
| `os` | Operating system you want to run the tests on. | `Windows 10`, `OS X Mojave` and `OS X Catalina` |
| `browser` | Browser you want to run the tests on. | `chrome`, `firefox` and `edge` |
| `versions` | A list of supported browser versions. | Chrome: `66` to `80` <br/>Firefox: `60` to `72`<br/>Edge: `80` |
Example:
```json
{
"browsers": [{
"os": "Windows 10",
"browser": "chrome",
"versions": ["69", "66"]
},
{
"os": "OS X Mojave",
"browser": "firefox",
"versions": ["69", "66"]
}
]
}
```
The following table provides a reference for all the options that can be provided in `browserstack.json` shown above.
### Configure Test Runs
You can use `run_settings` option to specify the settings to run your tests on
BrowserStack.
| Option | Description | Possible values |
|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `username` | This is your BrowserStack username. You can find this in your [Automate dashboard](https://automate.browserstack.com/) | - |
| `access_key` | This is your BrowserStack access key. You can find this in your [Automate dashboard](https://automate.browserstack.com/) | - |
| `os` <br/> (_case-sensitive_) | The operating system on which you want to run your test. | `OS X Mojave`, <br/> `OS X Catalina`, and <br/> `Windows 10` |
| `browser` <br/> (case-sensitive) | The browser on which you want to run your tests. | `chrome`, <br/> `firefox`, and <br/> `edge` |
| `versions` | A list of browser versions that you want to run your tests on. <br/><br/> **Example:** To run on versions 69, 67 and 65 provide `["69", "67", "65"]` | Right now edge 80 and all chrome versions from 66 to 78 are supported |
| `specs` <br/> (_deprecated_) | This param is deprecated in favour of a more complete `cypress_proj_dir` param. The path to the spec files that need to be run on BrowserStack | Takes a list of strings that point to location of the spec files |
| `cypress_proj_dir` | Path to the folder which contains `cypress.json` file. This path will be considered as the root path of the project. |- |
| `project` | Name of your project. This will be displayed in your Automate dashboard, and you'll be able to search & filter your tests based on the project name. | A string providing the name of the project |
| `customBuildName` | Helps in providing a custom name for the build. This will be displayed in your Automate dashboard, and you'll be able to search & filter your tests based on the build name. | A string providing the name of the build |
| `local` | Helps in testing websites that cannot be accessed in public network. If you set this to `true`, please download the Local binary and establish a local connection first (you can learn how to do so [here](https://www.browserstack.com/local-testing/automate#command-line)) | Boolean: `true` / `false`. Set this to `true` if you need to test a local website. Set this to `false` if the website is accessible publicly. |
| `localIdentifier` | The BrowserStack Local tunnel that should be used to resolve requests. This is applicable only when you start a Local binary with a local identifier. Your tests might fail if you use an invalid local identifier. This option will be ignored if `local` option is set to `false`. | A string if a tunnel identified by the Local identifier should be used (should be same as the one used to start the Local binary). Set this to `null` (default value) to resolve requests using Local without a Local identifier. |
| Option | Description | Possible values |
| ------------------ | ---------------------------------------------------------------------------------------------------------------- | --------------- |
| `cypress_proj_dir` | Path to the folder which contains `cypress.json` file. | - |
| `project_name` | Name of your project. You'll be able to search & filter your tests on the dashboard using this. | - |
| `build_name` | Name of your build / CI run. You'll be able to search & filter your tests on the dashboard using this. username. | - |
### Running the tests
Example:
```json
{
"run_settings": {
"cypress_proj_dir": "/path/to/directory-that-contains-<cypress.json>-file",
"project_name": "my first project",
"build_name": "build 1"
}
}
```
### Configure Connection Settings
You can use the `connection_settings` option to specify the Local connection
settings. This helps you in testing websites that cannot be accessed on the
public network. You can download the Local Testing binary and establish a local
connection first before you run the tests (you can learn how to do so
[here](https://www.browserstack.com/local-testing/automate#command-line))
| Option | Description | Possible values |
| ------------------ | ---------------------------------------------------------------------- | --------------- |
| `local` | Helps in testing private web applications. | - |
| `local_identifier` | The BrowserStack Local tunnel that should be used to resolve requests. | - |
Note that the `local_identifier` is applicable only when you start a Local
binary with a local identifier. Your tests might fail if you use an invalid
local identifier. This option will be ignored if `local` option is set to
`false`.
Example:
```json
{
"connection_settings": {
"local": false,
"local_identifier": null
}
}
```
### Disable Usage Reporting
The CLI collects anonymized usage data including the command-line arguments
used, system details and errors that you get so that we can improve the way
you run your Cypress tests on BrowserStack. Usage reporting is enabled by
default - you can disable usage reporting by using the `disable_usage_reporting`
option as follows:
Example:
```json
{
"disable_usage_reporting": "false"
}
```
### Deprecated Options
The following options are deprecated in favour of the new improved options to
make your testing better, flexible and have a consistent way of specifying
options.
| Deprecated option | New favoured option | Remarks |
| ----------------- | ------------------- | ----------------------------- |
| `specs` | `cypress_proj_dir` | Used in `run_settings` |
| `project` | `project_name` | Used in `run_settings` |
| `customBuildName` | `build_name` | Used in `run_settings` |
| `localIdentifier` | `local_identifier` | Used in `connection_settings` |
## CLI Arguments & Flags
### Run the Tests
You can start running your test build using the following command.

@@ -95,2 +240,14 @@

By default, the CLI uses the `browserstack.json` in the directory where the
`run` command is issued. If you need to use a different config file, or are
running from a different directory, you can use the `--cf` or the `--config-file`
option while using `run`. For example,
```bash
$ browserstack-cypress --cf <path-to-browserstack.json> run
# Or
$ browserstack-cypress --config-file <path-to-browserstack.json> run
```
Sample output :

@@ -113,16 +270,30 @@

### Getting build information
In case you want to get information on the build you can use the following command
### Get the Build Information
In case you want to get information on the build you can use the following
command
```bash
browserstack-cypress build-info <buildId>
$ browserstack-cypress build-info <buildId>
```
By default, the CLI uses the `browserstack.json` in the directory where the
`build-info` command is issued. If you need to use a different config file, or
are running the command from a different directory, you can use the `--cf` or
the `--config-file` option while using `build-info`. For example,
```bash
$ browserstack-cypress --cf <path-to-browserstack.json> build-info <buildId>
# Or
$ browserstack-cypress --config-file <path-to-browserstack.json> build-info <buildId>
```
Example
```bash
browserstack-cypress build-info 06f28ce423d10314b32e98bb6f68e10b0d02a49a
$ browserstack-cypress build-info 06f28ce423d10314b32e98bb6f68e10b0d02a49a
```
Output:
Sample output:

@@ -189,18 +360,32 @@ ```bash

**Note:** Each browser version represents a session. It is advised to validate your account's parallel limit before running multiple versions.
**Note:** Each browser version represents a session. It is advised to validate
your account's parallel limit before running multiple versions.
### Stopping a running build
### Stop a Running Build
In case you want to stop a running build, you can use the following command
```bash
browserstack-cypress build-stop <buildId>
$ browserstack-cypress build-stop <buildId>
```
By default, the CLI uses the `browserstack.json` in the directory where the
`build-stop` command is issued. If you need to use a different config file, or
are running the command from a different directory, you can use the `--cf` or
the `--config-file` option while using `build-stop`. For example,
```bash
$ browserstack-cypress --cf <path-to-browserstack.json> build-stop <buildId>
# Or
$ browserstack-cypress --config-file <path-to-browserstack.json> build-stop <buildId>
```
Example
```bash
browserstack-cypress build-stop 06f28ce423d10314b32e98bb6f68e10b0d02a49a
$ browserstack-cypress build-stop 06f28ce423d10314b32e98bb6f68e10b0d02a49a
```
Output:
Sample output:

@@ -216,14 +401,27 @@ ```bash

### Limitations
### Disable CLI Usage Reporting
- `exec` and `task` are not allowed.
- While using local, please make sure to create `/etc/hosts` entry pointing to some URL, and use that URL in the tests. The `localhost` URI doesn't work at the moment.
- Installing custom npm packages are not supported at this moment.
The CLI collects anonymized usage data including the command-line arguments
used, system details and errors that you get so that we can improve the way
you run your Cypress tests on BrowserStack. Usage reporting is enabled by
default - you can disable usage reporting by using the
`--disable-usage-reporting` flag. You can also do this by setting the
`disable_usage_reporting` option to `"true"` in `browserstack.json`.
# Accessing test results
```bash
$ browserstack-cypress --disable-usage-reporting <your-commands>
```
You can access your test results in [BrowserStack Automate dashboard](https://automate.browserstack.com/). The dashboard provides test details along with video, console logs and screenshots to help you debug any issues.
## Limitations
# License
- `exec` and `task` are not allowed.
- While using local, please make sure to create `/etc/hosts` entry pointing to
some URL, and use that URL in the tests. The `localhost` URI doesn't work at
the moment. You can use `http://bs-local.com` instead, to replace `localhost`
- Installing npm packages that your tests might require to run the tests are
not supported at this moment.
This project is released under MIT License. Please refer the [LICENSE.md](LICENSE.md) for more details.
## License
This project is released under MIT License. Please refer the
[LICENSE.md](LICENSE.md) for more details.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc