From 444a96e421ae533170e4856b0dc01aaeefe481df Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Mon, 23 Jan 2023 16:09:56 +0530 Subject: [PATCH 1/6] chore: add extra instrumentation for duration breakup --- bin/commands/runs.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 18d64936..a4bd0037 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -1,5 +1,6 @@ 'use strict'; const path = require('path'); +const { inspect } = require('util'); const archiver = require("../helpers/archiver"), zipUploader = require("../helpers/zipUpload"), @@ -24,6 +25,7 @@ const { getStackTraceUrl } = require('../helpers/sync/syncSpecsLogs'); module.exports = function run(args, rawArgs) { + markBlockStart('preBuild'); // set debug mode (--cli-debug) utils.setDebugMode(args); @@ -185,6 +187,8 @@ module.exports = function run(args, rawArgs) { logger.debug("Started build creation"); markBlockStart('createBuild'); return build.createBuild(bsConfig, zip).then(function (data) { + markBlockEnd('preBuild'); + markBlockStart('buildProcessing'); logger.debug("Completed build creation"); markBlockEnd('createBuild'); markBlockEnd('total'); @@ -216,6 +220,8 @@ module.exports = function run(args, rawArgs) { if (args.sync) { logger.debug("Started polling build status from BrowserStack"); syncRunner.pollBuildStatus(bsConfig, data, rawArgs, buildReportData).then(async (exitCode) => { + markBlockEnd('buildProcessing'); + markBlockStart('postBuild'); logger.debug("Completed polling of build status"); // stop the Local instance @@ -234,6 +240,7 @@ module.exports = function run(args, rawArgs) { // Generate custom report! reportGenerator(bsConfig, data.build_id, args, rawArgs, buildReportData, function(){ utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs); + markBlockEnd('postBuild'); utils.handleSyncExit(exitCode, data.dashboard_url); }); } else { From 0823dc9fc5f65502ddab5220d014d579e342a026 Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Tue, 24 Jan 2023 00:04:02 +0530 Subject: [PATCH 2/6] chore: add cypress to dependency if not present --- bin/helpers/checkUploaded.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bin/helpers/checkUploaded.js b/bin/helpers/checkUploaded.js index 5e580053..25495f1d 100644 --- a/bin/helpers/checkUploaded.js +++ b/bin/helpers/checkUploaded.js @@ -61,6 +61,17 @@ const checkPackageMd5 = (runSettings) => { } if (typeof runSettings.npm_dependencies === 'object') { + logger.debug(`---> checkMD5 NPM dependency:\n ${JSON.stringify(runSettings.npm_dependencies)}`) + logger.debug(`---> checkMD5 Cypress in: ${"cypress" in runSettings.npm_dependencies}`) + if (!("cypress" in runSettings.npm_dependencies)) { + logger.debug(`---> checkMD5 cypress not present`) + if ("cypress_version" in runSettings && !runSettings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)) { + logger.debug(`---> checkMD5 cypress in runsettings: ${runSettings.cypress_version}`) + runSettings.npm_dependencies.cypress = runSettings.cypress_version; + } else { + runSettings.npm_dependencies.cypress = "latest"; + } + } Object.assign(packageJSON, { devDependencies: utils.sortJsonKeys(runSettings.npm_dependencies), }); From 50008085f8524d68efce37d542381a50e39e05c6 Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Tue, 24 Jan 2023 11:31:17 +0530 Subject: [PATCH 3/6] chore: add reading cypress conf --- bin/helpers/utils.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 6616816f..1ab55845 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -309,6 +309,13 @@ exports.setCypressConfigFilename = (bsConfig, args) => { logger.debug(`Setting cypress config file path = ${bsConfig.run_settings.cypressConfigFilePath}`); logger.debug(`Setting cypress project dir = ${bsConfig.run_settings.cypressProjectDir}`); + let directoryPath = !this.isUndefined(bsConfig.run_settings.cypress_proj_dir) ? bsConfig.run_settings.cypress_proj_dir : process.cwd(); + if (directoryPath.endsWith("/")) { + directoryPath = directoryPath.slice(0,-1); + } + const bsconf_dir = path.join(directoryPath, bsConfig.run_settings.cypressConfigFilePath) + const bsconf_cypress = require(bsconf_dir) + logger.info(`---> bsconf: ${JSON.stringify(bsconf_cypress.e2e)}`) } exports.setCypressTestSuiteType = (bsConfig) => { From 2038881bfc8bbdfe51d420d398b1107f7980ea87 Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Tue, 24 Jan 2023 11:36:04 +0530 Subject: [PATCH 4/6] chore: cleanup commit --- bin/helpers/checkUploaded.js | 4 ---- bin/helpers/utils.js | 17 +++++++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/helpers/checkUploaded.js b/bin/helpers/checkUploaded.js index 25495f1d..65180041 100644 --- a/bin/helpers/checkUploaded.js +++ b/bin/helpers/checkUploaded.js @@ -61,12 +61,8 @@ const checkPackageMd5 = (runSettings) => { } if (typeof runSettings.npm_dependencies === 'object') { - logger.debug(`---> checkMD5 NPM dependency:\n ${JSON.stringify(runSettings.npm_dependencies)}`) - logger.debug(`---> checkMD5 Cypress in: ${"cypress" in runSettings.npm_dependencies}`) if (!("cypress" in runSettings.npm_dependencies)) { - logger.debug(`---> checkMD5 cypress not present`) if ("cypress_version" in runSettings && !runSettings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)) { - logger.debug(`---> checkMD5 cypress in runsettings: ${runSettings.cypress_version}`) runSettings.npm_dependencies.cypress = runSettings.cypress_version; } else { runSettings.npm_dependencies.cypress = "latest"; diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 1ab55845..19915f7a 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -309,13 +309,18 @@ exports.setCypressConfigFilename = (bsConfig, args) => { logger.debug(`Setting cypress config file path = ${bsConfig.run_settings.cypressConfigFilePath}`); logger.debug(`Setting cypress project dir = ${bsConfig.run_settings.cypressProjectDir}`); - let directoryPath = !this.isUndefined(bsConfig.run_settings.cypress_proj_dir) ? bsConfig.run_settings.cypress_proj_dir : process.cwd(); - if (directoryPath.endsWith("/")) { - directoryPath = directoryPath.slice(0,-1); + try { + let directoryPath = !this.isUndefined(bsConfig.run_settings.cypress_proj_dir) ? bsConfig.run_settings.cypress_proj_dir : process.cwd(); + if (directoryPath.endsWith("/")) { + directoryPath = directoryPath.slice(0,-1); + } + const bsconf_dir = path.join(directoryPath, bsConfig.run_settings.cypressConfigFilePath) + const bsconf_cypress = require(bsconf_dir) + logger.info(`---> bsconf: ${JSON.stringify(bsconf_cypress.e2e)}`) + } catch (error) { + logger.debug(`Got error reading cypress config file: ${error.message}`) } - const bsconf_dir = path.join(directoryPath, bsConfig.run_settings.cypressConfigFilePath) - const bsconf_cypress = require(bsconf_dir) - logger.info(`---> bsconf: ${JSON.stringify(bsconf_cypress.e2e)}`) + } exports.setCypressTestSuiteType = (bsConfig) => { From 4edd544ec300f56761bf671669597df4d2c53c38 Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Tue, 24 Jan 2023 11:36:46 +0530 Subject: [PATCH 5/6] chore: fix the exception --- bin/helpers/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 19915f7a..60e712e2 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -318,7 +318,7 @@ exports.setCypressConfigFilename = (bsConfig, args) => { const bsconf_cypress = require(bsconf_dir) logger.info(`---> bsconf: ${JSON.stringify(bsconf_cypress.e2e)}`) } catch (error) { - logger.debug(`Got error reading cypress config file: ${error.message}`) + logger.debug(`Got error reading cypress config file: ${JSON.stringify(error)}`) } } From 43938cc31bdf4bfb588155dc2f3c283d937f86ff Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Wed, 1 Feb 2023 11:46:28 +0530 Subject: [PATCH 6/6] chore: add ts file compilation steps --- bin/helpers/readCypressConfigUtil.js | 84 ++++++++++++++++++++++++++++ bin/helpers/utils.js | 14 +---- 2 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 bin/helpers/readCypressConfigUtil.js diff --git a/bin/helpers/readCypressConfigUtil.js b/bin/helpers/readCypressConfigUtil.js new file mode 100644 index 00000000..57e8ea61 --- /dev/null +++ b/bin/helpers/readCypressConfigUtil.js @@ -0,0 +1,84 @@ +"use strict"; +const path = require("path"); +const fs = require("fs"); +const exec = require("child_process").exec; +const execSync = require("child_process").execSync; + +const isUndefined = value => (value === undefined || value === null); + +exports.getCypressConfigDir = (bsConfig) => { + let directoryPath; + try { + directoryPath = !isUndefined(bsConfig.run_settings.cypress_proj_dir) ? bsConfig.run_settings.cypress_proj_dir : process.cwd(); + console.log(`--> dir_path: ${directoryPath}`) + if (directoryPath.endsWith("/")) { + directoryPath = directoryPath.slice(0,-1); + } + } catch (error) { + console.log(`---> Error: ${error}`) + } + return path.join(directoryPath, bsConfig.run_settings.cypressConfigFilePath) +} + +exports.readCypressConfig = (bsConfig) => { + try { + let cypress_conf_dir = this.getCypressConfigDir(bsConfig) + console.log(`---> Cypress conf dir: ${cypress_conf_dir}`) + const conf_lang = this.detectLanguage(path.dirname(cypress_conf_dir)) + console.log(`---> Detected lang: ${conf_lang}`) + if (conf_lang == 'ts') { + cypress_conf_dir = this.convertTsConfig(cypress_conf_dir) + // cypress_conf_dir = path.join(path.dirname(cypress_conf_dir), 'cypress.config.js') + } + console.log(`---> Got cypress converted conf dir: ${cypress_conf_dir}`) + // Perform actions + const cypress_config = require(cypress_conf_dir) + console.log(`---> bsconf: ${JSON.stringify(cypress_config)}`) + } catch (error) { + console.log(`---> Got error reading cypress config file: ${JSON.stringify(error)}`) + } +} + +exports.detectLanguage = (projectRoot) => { + for (let extension of ['ts', 'mts']) { + if (fs.existsSync(path.join(projectRoot, `cypress.config.${extension}`))) { + return 'ts' + } + } + for (let extension of ['js', 'cjs', 'mjs']) { + if (fs.existsSync(path.join(projectRoot, `cypress.config.${extension}`))) { + return 'js' + } + } + return 'js' // Default to js +} + +exports.convertTsConfig = (cypress_conf_dir) => { + const working_dir = path.dirname(cypress_conf_dir); + const ts_working_dir = path.join(working_dir, 'tsWorkingDir') + const tsconfig_path = path.join(working_dir, 'tsconfig.json') // TODO: find tsconfig if cypress.config.ts and tsconfig not in same location + execSync('rm -rf tsWorkingDir', {cwd: working_dir}) + execSync('mkdir tsWorkingDir', {cwd: working_dir}) + console.log(`---> 123: ${working_dir}`) + let tsc_command = `npx tsc --outDir ${ts_working_dir} --listEmittedFiles true`; + if (!fs.existsSync(tsconfig_path)) { + tsc_command = `${tsc_command} cypress.config.ts` + } + try { + let stdout = execSync(tsc_command, { cwd: working_dir }).toString() + console.log(stdout) + const lines = stdout.split('\n'); + let foundLine = null; + for(let i =0; i < lines.length; i++) { + if(lines[i].indexOf("cypress.config.") > -1){ + foundLine = lines[i] + break; + } + } + console.log(foundLine) + return foundLine.split('TSFILE: ').pop() + } catch (err) { + console.log("output",err) + console.log("sdterr",err.stderr.toString()) + } +} diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 60e712e2..3645d453 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -20,6 +20,7 @@ const usageReporting = require("./usageReporting"), transports = require('./logger').transports; const request = require('request'); +const { readCypressConfig } = require("./readCypressConfigUtil"); exports.validateBstackJson = (bsConfigPath) => { return new Promise(function (resolve, reject) { @@ -309,18 +310,7 @@ exports.setCypressConfigFilename = (bsConfig, args) => { logger.debug(`Setting cypress config file path = ${bsConfig.run_settings.cypressConfigFilePath}`); logger.debug(`Setting cypress project dir = ${bsConfig.run_settings.cypressProjectDir}`); - try { - let directoryPath = !this.isUndefined(bsConfig.run_settings.cypress_proj_dir) ? bsConfig.run_settings.cypress_proj_dir : process.cwd(); - if (directoryPath.endsWith("/")) { - directoryPath = directoryPath.slice(0,-1); - } - const bsconf_dir = path.join(directoryPath, bsConfig.run_settings.cypressConfigFilePath) - const bsconf_cypress = require(bsconf_dir) - logger.info(`---> bsconf: ${JSON.stringify(bsconf_cypress.e2e)}`) - } catch (error) { - logger.debug(`Got error reading cypress config file: ${JSON.stringify(error)}`) - } - + console.log(readCypressConfig(bsConfig)) } exports.setCypressTestSuiteType = (bsConfig) => {