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

lambdatest-cypress-cli

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambdatest-cypress-cli - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

commands/build_stop.js

69

commands/run.js

@@ -1,16 +0,18 @@

const archive = require("./utils/archive.js");
const set_args = require("./utils/set_args.js")
const uploader = require("./utils/uploader.js")
const validate = require("./utils/validate")
const constants=require("./utils/constants.js")
const fs=require("fs")
const constants = require("./utils/constants.js")
const batcher = require("./utils/batch/batcher.js")
const fs = require("fs")
const batch_runner = require("./utils/batch/batch_runner.js")
var lambdaTunnel = require('@lambdatest/node-tunnel');
module.exports = function (args) {
if (!("lambdatest-config-file" in args)){
if (!("lambdatest-config-file" in args)) {
console.log("Checking Lambda Config in current directory")
if (fs.existsSync(constants.LAMBDA_CONFIG)) {
args["lambdatest-config-file"]=constants.LAMBDA_CONFIG
args["lambdatest-config-file"] = constants.LAMBDA_CONFIG
}
}
var env="prod"
var env = "prod"
if ("env" in args) {

@@ -33,23 +35,36 @@

validate(lt_config).then(function () {
//archive the files(config, spec)
archive.archive_files(lt_config).then(function (file_obj) {
file_name=file_obj["name"]
count=file_obj["count"]
if(count<2){
console.log("Spec not passed")
return
batcher.make_batches(lt_config).then(function (batches) {
if (lt_config["tunnel_settings"]["tunnel"]) {
var tunnelInstance = new lambdaTunnel();
var tunnelArguments = {
user: lt_config["lambdatest_auth"]["username"],
key: lt_config["lambdatest_auth"]["access_key"],
tunnelName: lt_config["tunnel_settings"]["tunnelName"],
v: true,
env: env
};
tunnelInstance
.start(tunnelArguments)
.then(status => {
batch_runner.run_batches(lt_config, batches, env).then(function () {
console.log("stopping tunnel")
tunnelInstance.stop()
}).catch(function (error) {
console.log("stopping tunnel failed")
console.log(error)
tunnelInstance.stop()
})
}).catch(error => {
console.log(error);
});
} else {
batch_runner.run_batches(lt_config, batches, env)
}
console.log("file archived", file_name)
//upload files to Lambdatest
uploader(lt_config, file_name,env).then(function (response) {
console.log("Uploaded", response)
//Synchronously delete the created Zip after Upload
archive.delete_archive(file_name)
}).catch(function (error) {
console.log(error)
archive.delete_archive(file_name)
})
}).catch(function (err) {
console.log(err)
})
}).catch(function (msg) {
console.log(msg)
}).catch(function (err) {
console.log(err)
})

@@ -61,5 +76,5 @@ }).catch(function (err) {

else {
console.log("Lambda Test config not present")
console.log("Lambda Test config not present")
}
};

@@ -1,48 +0,41 @@

const fs = require('fs');
const archiver = require('archiver');
const path = require('path');
const constants= require('./constants.js')
const path = require('path')
const fs = require('fs')
const archiver = require('archiver')
const constants = require('./constants.js')
const process = require("process")
function delete_archive(file_name) {
try {
fs.unlinkSync(file_name)
console.log("file removed")
} catch (err) {
console.error(err)
}
try {
fs.unlinkSync(file_name)
} catch (err) {
console.error(err)
}
}
function archive_files(lt_config) {
var count=0
return new Promise(function (resolve, reject) {
if (!'specs' in lt_config) {
throw "Specs not found"
}
files = lt_config['run_settings']['specs']
const output = fs.createWriteStream('test.zip');
function archive_project(ignore_files = []) {
return new Promise(function (resolve, reject) {
const output = fs.createWriteStream('project.zip');
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
output.on('close', function () {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
resolve({name:"test.zip",count:count})
resolve({ name: "project.zip" })
});
archive.on("progress", (progress) => {
count++
})
output.on('end', function () {
console.log('Data has been drained');
});
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
// log warning
console.log("WARN:",err)
console.log("WARN:", err)
reject(err)
} else {
// throw error
console.log("WARN:",err)
throw err;
console.log("WARN:", err)
reject(err)
}

@@ -52,3 +45,3 @@ });

archive.on('error', function (err) {
console.log("ERROR",err)
console.log("ERROR", err)
throw err;

@@ -59,28 +52,74 @@ });

archive.pipe(output);
ignore_files = ['cypress.json','node_modules', 'node_modules/**/*', 'test.zip', 'project.zip', 'mochawesome-report', 'cypress/screenshots', 'cypress/videos', 'cypress/results'].concat(ignore_files)
console.log("Ignoring files: ", ignore_files)
archive.glob('**/*', { cwd: process.cwd(), ignore: ignore_files }, { prefix: "project/" })
for (const property in files) {
archive.finalize();
})
console.log("archiving file...", path.basename(files[property]))
archive.glob(path.basename(files[property]), { cwd: path.dirname(files[property]), matchBase: true, dot: true }, { prefix: "test/" });
}
function archive_batch(lt_config, batch) {
return new Promise(function (resolve, reject) {
const output = fs.createWriteStream('test.zip');
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
output.on('close', function () {
resolve({ name: "test.zip" })
});
archive.on("progress", (progress) => {
})
output.on('end', function () {
});
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
// log warning
console.log("WARN:", err)
reject(err)
} else {
// throw error
console.log("WARN:", err)
reject(err)
}
});
archive.on('error', function (err) {
console.log("ERROR", err)
throw err;
});
// pipe archive data to the file
archive.pipe(output);
spec_files = []
for (i in batch) {
spec_files.push(batch[i]["spec_file"])
}
spec_files = Array.from(new Set(spec_files))
for (i in spec_files) {
console.log("Archiving --------- ", spec_files[i])
archive.file(spec_files[i], { name: "test/" + path.basename(spec_files[i]) });
}
if (lt_config["run_settings"]["cypress_config_file"] && fs.existsSync(lt_config["run_settings"]["cypress_config_file"])) {
let rawdata = fs.readFileSync(lt_config["run_settings"]["cypress_config_file"]);
archive.append(rawdata, { name: constants.CYPRESS_CONFIG_NAME });
} else if ((!lt_config["run_settings"]["cypress_config_file"])) {
archive.append("{}", { name: constants.CYPRESS_CONFIG_NAME });
}
let lt_config_string = JSON.stringify(lt_config, null, 4);
archive.append(lt_config_string, { name: constants.LT_CONFIG_NAME });
let cypressFolderPath = path.dirname(lt_config['run_settings']['cypress_config_file']);
if(lt_config["run_settings"]["cypress_config_file"] && fs.existsSync( lt_config["run_settings"]["cypress_config_file"] )){
archive.glob(path.basename(lt_config["run_settings"]["cypress_config_file"]), { cwd: path.dirname(lt_config["run_settings"]["cypress_config_file"]) })
count--
}
archive.finalize();
})
};
}
module.exports = {
archive_files: archive_files,
delete_archive: delete_archive
delete_archive: delete_archive,
archive_project: archive_project,
archive_batch: archive_batch
}

@@ -5,13 +5,21 @@

RUN_URL: "/cy/run",
RUN_WS_URL: "/cy/run/ws",
PROJECT_UPLOAD_URL:"/cy/upload",
LT_CONFIG_NAME: "lambdatest-config.json",
CYPRESS_CONFIG_NAME:"cypress.json",
DEFAULT_TEST_PATH: ".",
LAMBDA_CONFIG: "./lambdatest-config.json",
SUPPORTED_CYPRESS_VERSIONS:["5","6"],
prod: {
INTEGRATION_BASE_URL: "https://beta-api.lambdatest.com/liis",
INTEGRATION_BASE_URL: "https://lisa.lambdatest.com/liis",
BUILD_BASE_URL: "https://api.lambdatest.com/automation/api/v1/builds/",
BUILD_STOP_URL:"https://beta-api.lambdatest.com/api/v1/test/stop?buildId="
},
stage: {
INTEGRATION_BASE_URL: "https://stage-api.lambdatest.com/liis",
// INTEGRATION_BASE_URL: "https://stage-api.lambdatest.com/liis",
INTEGRATION_BASE_URL: "https://stage-lisa.lambdatest.com/liis",
BUILD_BASE_URL: "https://stage-api.lambdatest.com/automation/api/v1/builds/",
BUILD_STOP_URL:"https://stage-api.lambdatest.com/api/v1/test/stop?buildId="

@@ -23,2 +31,3 @@ },

BUILD_BASE_URL: "https://api.lambdatest.com/automation/api/v1/builds/",
BUILD_STOP_URL:"https://beta-api.lambdatest.com/api/v1/test/stop?buildId="

@@ -25,0 +34,0 @@

@@ -23,6 +23,8 @@ module.exports={

"run_settings": {
"cypress_config_file": "/path/to/<cypress config file>.json",
"cypress_config_file": "cypress.json",
"build_name": "build-name",
"parallels": 1,
"specs":"./*.spec.js"
"specs":"./*.spec.js",
"ignore_files":"",
"npm_dependencies": {"cypress": "6.1.0"},
},

@@ -29,0 +31,0 @@ "tunnel_settings": {

@@ -58,26 +58,50 @@ const constants = require("./constants.js")

}
if ("cypress-config-file" in args) {
lt_config["run_settings"]["cypress_config_file"] = args["cypress-config-file"]
} else if ((!lt_config["run_settings"]["cypress_config_file"]) && fs.existsSync(path.join(process.cwd(), "cypress.json"))) {
lt_config["run_settings"]["cypress_config_file"] = path.join(process.cwd() , "cypress.json")
}
//Set the env variables
let env_vars = undefined
if ("envs" in args) {
env_vars = args["envs"].split(",")
} else if (lt_config["run_settings"]['envs']) {
env_vars = lt_config["run_settings"]['envs'].split(",")
}
if ("env" in args) {
env_vars = args["env"].split(",")
envs = {}
if (env_vars) {
let envs = {}
for (env in env_vars) {
console.log(env_vars[env].split("="))
envs[env_vars[env].split("=")[0]] = env_vars[env].split("=")[1]
}
if (fs.existsSync('cypress.env.json')) {
let raw_env = fs.readFileSync('cypress.env.json');
let env_json = JSON.parse(raw_env);
envs = Object.assign(env_json, envs)
lt_config["run_settings"]["envs"] = envs
}
if ("cypress-env-file" in args) {
let env_json
if (fs.existsSync(args['cypress-env-file'])) {
let raw_env = fs.readFileSync(args['cypress-env-file']);
env_json = JSON.parse(raw_env);
if (lt_config["run_settings"]["envs"]) {
lt_config["run_settings"]["envs"] = Object.assign(lt_config["run_settings"]["envs"], env_json)
} else {
lt_config["run_settings"]["envs"] = env_json
}
} else {
reject("Cypress-env-file file not found but passed in command line")
}
lt_config["run_settings"]["env"] = envs
}
//set the build name on the basis of build identifier
if ("build-name" in args) {
lt_config["run_settings"]["build_name"] = args["build-name"]
}
if ("build-identifier" in args && lt_config["run_settings"]["build_name"]) {
lt_config["run_settings"]["build_name"] = lt_config["run_settings"]["build_name"] + args["build-identifier"]
} else if ("build-identifier" in args && !(lt_config["run_settings"]["build_name"])) {
lt_config["run_settings"]["build_name"] = args["build-identifier"]
} else if (lt_config["run_settings"]["build_name"] && lt_config["run_settings"]["build_identifier"]) {
lt_config["run_settings"]["build_name"] = lt_config["run_settings"]["build_name"] + lt_config["run_settings"]["build_identifier"]
}
if ("tags" in args) {

@@ -87,5 +111,63 @@ lt_config["run_settings"]["tags"] = args["tags"].split(",")

if ("parellels" in args) {
lt_config["run_settings"]["parellels"] = args["parellels"]
if ("parallels" in args) {
lt_config["run_settings"]["parallels"] = parseInt(args["parallels"])
} else if (!(lt_config["run_settings"]["parallels"])) {
lt_config["run_settings"]["parallels"] = 0
} else {
lt_config["run_settings"]["parallels"] = parseInt(lt_config["run_settings"]["parallels"])
}
//set tunnel options
if ("tunnel" in args) {
if (!("tunnel_settings" in lt_config)) {
lt_config["tunnel_settings"] = {}
}
lt_config["tunnel_settings"]["tunnel"] = true ? args["tunnel"] == "true" : false
} else if (!("tunnel_settings" in lt_config)) {
lt_config["tunnel_settings"] = {}
lt_config["tunnel_settings"]["tunnel"] = false
} else if (!("tunnel" in lt_config["tunnel_settings"])) {
lt_config["tunnel_settings"]["tunnel"] = false
}
if ("tunnelName" in args) {
if (!("tunnel_settings" in lt_config)) {
lt_config["tunnel_settings"] = {}
}
lt_config["tunnel_settings"]["tunnelName"] = args["tunnelName"]
} else if (!("tunnel_settings" in lt_config)) {
lt_config["tunnel_settings"] = {}
lt_config["tunnel_settings"]["tunnelName"] = ""
} else if (!("tunnelName" in lt_config["tunnel_settings"])) {
lt_config["tunnel_settings"]["tunnelName"] = ""
}
//add browsers from cli
if ("browsers" in args) {
browsers = args["browsers"].split(",")
browsers_formatted = []
for (browser in browsers) {
browsers_formatted.push({
"platform": browsers[browser].split(":")[0],
"browser": browsers[browser].split(":")[1],
"versions": [browsers[browser].split(":")[2]]
})
}
lt_config["browsers"] = browsers_formatted
}
if (!(lt_config["run_settings"]["ignore_files"])) {
lt_config["run_settings"]["ignore_files"] = []
} else {
lt_config["run_settings"]["ignore_files"] = lt_config["run_settings"]["ignore_files"].split(",")
}
if ("ignore_files" in args) {
lt_config["run_settings"]["ignore_files"] = args["ignore_files"].split(",")
}
if ("cypress_version" in args) {
lt_config["run_settings"]["cypress_version"] = args["cypress_version"]
} else if (lt_config["run_settings"]["cypress_version"]) {
lt_config["run_settings"]["cypress_version"] = String(lt_config["run_settings"]["cypress_version"])
}
//get specs from current directory if specs are not passed in config or cli

@@ -113,3 +195,3 @@ if ((lt_config["run_settings"]["specs"] == undefined || lt_config["run_settings"]["specs"].length == 0) && fs.existsSync(constants.DEFAULT_TEST_PATH)) {

files.push(path.join(dir_path, file))
}
}
});

@@ -116,0 +198,0 @@ resolve(files)

const fs = require('fs');
const { url } = require('inspector');
const request = require("request")

@@ -6,6 +7,4 @@ const constants = require("./constants.js")

function login(lt_config,env="prod") {
function login(lt_config, env = "prod") {
return new Promise(function (resolve, reject) {
console.log(constants[env].INTEGRATION_BASE_URL)
console.log("login function", lt_config["lambdatest_auth"]["username"],lt_config["lambdatest_auth"]["access_key"])
let options = {

@@ -18,3 +17,2 @@ url: constants[env].INTEGRATION_BASE_URL + constants.LOGIN_URL,

}
let responseData = null;

@@ -36,3 +34,2 @@ request.post(options, function (err, resp, body) {

} else {
console.log(responseData)
reject("error", responseData);

@@ -47,19 +44,19 @@ }

}
module.exports = uploadFile = function (lt_config, file_name,env="prod") {
function upload_project(lt_config, file_name, env = "prod") {
return new Promise(function (resolve, reject) {
login(lt_config,env).then(function (responseDataLogin) {
console.log("uploader function",responseDataLogin)
login(lt_config, env).then(function (responseDataLogin) {
console.log("Login Status:-",responseDataLogin)
let options = {
url: constants[env].INTEGRATION_BASE_URL + constants.RUN_URL,
url: constants[env].INTEGRATION_BASE_URL + constants.PROJECT_UPLOAD_URL,
formData: {
"test.zip": fs.createReadStream(file_name),
"project.zip": fs.createReadStream(file_name),
filetype: 'zip',
filename: "test.zip",
filename: "project.zip",
Username: lt_config["lambdatest_auth"]["username"],
token: lt_config["lambdatest_auth"]["access_key"],
}
},
timeout:"600000"
}
let responseData = null;

@@ -80,8 +77,6 @@ request.post(options, function (err, resp, body) {

} else {
console.log(responseData)
reject("error", responseData);
}
} else {
console.log(`Uploaded tests successfully )`);
//fileHelpers.deleteZip();
console.log(`Uploaded tests successfully`);
resolve(responseData);

@@ -91,7 +86,16 @@ }

});
}).catch(function(responseDataLogin){
reject("Not Authorized",responseDataLogin)
}).catch(function (err) {
console.log("upload projec")
reject("Not Authorized")
})
}).catch(function (err) {
console.log("Not Authorized")
// reject("Not Authorized")
})
};
}
module.exports={
upload_project:upload_project
}

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

const fs = require("fs")
const constants=require("./constants.js")
module.exports = validate_config = function (lt_config) {

@@ -5,3 +7,3 @@ return new Promise(function (resolve, reject) {

if (!("lambdatest_auth" in lt_config) || !("username" in lt_config["lambdatest_auth"]) || !("access_key" in lt_config["lambdatest_auth"])) {
reject("Error!!! Incompatible Config Auth not present")
reject("Error!!! Incompatible Config. Auth not present")
}

@@ -25,9 +27,15 @@

//validate parellel session
let parellels = lt_config["run_settings"]["parallels"]
if (parellels == undefined || parellels == null || isNaN(parellels) || (Number(parellels) && Number(parellels) % 1 !== 0) || parseInt(parellels, 10) <= 0 || parellels === "Here goes the number of parallels you want to run") {
reject("Error!! Parellels value not correct")
let parallels = lt_config["run_settings"]["parallels"]
if (parallels == undefined || parallels == null || isNaN(parallels) || (Number(parallels) && Number(parallels) % 1 !== 0) || parseInt(parallels, 10) <= 0 || parallels === "Here goes the number of parallels you want to run") {
reject("Error!! Parallels value not correct")
}
//validate if cypress config file is passed and exists
if (lt_config["run_settings"]["cypress_config_file"] && lt_config["run_settings"]["cypress_config_file"] != "") {
if (!fs.existsSync(lt_config["run_settings"]["cypress_config_file"])) {
reject("Error!! Cypress Config File does not exist")
}
}
resolve("Validated the Config")
})
}

@@ -26,3 +26,3 @@ #!/usr/bin/env node

alias: 'env',
describe: 'environment variables',
describe: 'environment',
type: 'string'

@@ -38,18 +38,45 @@ }).option('bn', {

}).option('p', {
alias: 'parellels',
alias: 'parallels',
describe: 'no of parellel sessions',
type: 'string'
}).option('env', {
alias: 'env',
describe: 'environment',
}).option('envs', {
alias: 'envs',
describe: 'environment variables',
type: 'string'
}).option('tun', {
alias: 'tunnel',
describe: 'tunnel',
type: 'string'
}).option('tname', {
alias: 'tunnelName',
describe: 'tunnel name',
type: 'string'
}).option('cef', {
alias: 'cypress-env-file',
describe: 'cypress environment file',
type: 'string'
}).option('brs', {
alias: 'browsers',
describe: 'browsers to run test format: platform:browser:version',
type: 'string'
}).option('bi', {
alias: 'build-identifier',
describe: 'Build Identifier / Build Counter',
type: 'string'
}).option('if', {
alias: 'ignore_files',
describe: 'Files to ignore in the project zip',
type: 'string'
}).option('cv', {
alias: 'cypress_version',
describe: 'Cypress Version',
type: 'string'
})
},
function (argv) {
console.log("In run command")
require("./commands/run")(argv);
}
).command('build-info', 'info about the build',
function(yargs) {
).command('build-info', 'info about the build',
function (yargs) {
return yargs.option('id', {

@@ -74,6 +101,31 @@ alias: 'build-id',

}
,
,
function (argv) {
require("./commands/build_info")(argv);
}
).command('build-stop', 'stop all tests in the build',
function (yargs) {
return yargs.option('id', {
alias: 'build-id',
describe: 'Build Identifier',
type: 'string',
demandOption: true
}).option('user', {
alias: 'user',
describe: 'username',
type: 'string'
}).option('access_key', {
alias: 'access_key',
describe: 'Access Key',
type: 'string'
}).option('env', {
alias: 'env',
describe: 'environment',
type: 'string'
})
}
,
function (argv) {
require("./commands/build_stop")(argv);
}
)

@@ -80,0 +132,0 @@ .help()

{
"name": "lambdatest-cypress-cli",
"version": "1.0.1",
"version": "2.0.0",
"description": "The lambdatest-cypress-cli is LambdaTest's command-line interface (CLI) aimed to help you run your Cypress tests on LambdaTest platform.",

@@ -20,7 +20,9 @@ "homepage": "https://github.com/LambdaTest/lambdatest-cypress-cli",

"dependencies": {
"@lambdatest/node-tunnel": "^3.0.0",
"archiver": "^5.1.0",
"glob": "^7.1.6",
"request": "^2.88.2",
"ws": "^7.4.3",
"yargs": "^16.1.0"
},
"devDependencies": {},
"license": "MIT",

@@ -27,0 +29,0 @@ "preferGlobal": true,

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