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 { diff --git a/bin/helpers/checkUploaded.js b/bin/helpers/checkUploaded.js index 5e580053..65180041 100644 --- a/bin/helpers/checkUploaded.js +++ b/bin/helpers/checkUploaded.js @@ -61,6 +61,13 @@ const checkPackageMd5 = (runSettings) => { } if (typeof runSettings.npm_dependencies === 'object') { + if (!("cypress" in runSettings.npm_dependencies)) { + if ("cypress_version" in runSettings && !runSettings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)) { + runSettings.npm_dependencies.cypress = runSettings.cypress_version; + } else { + runSettings.npm_dependencies.cypress = "latest"; + } + } Object.assign(packageJSON, { devDependencies: utils.sortJsonKeys(runSettings.npm_dependencies), }); 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 6616816f..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,6 +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}`); + console.log(readCypressConfig(bsConfig)) } exports.setCypressTestSuiteType = (bsConfig) => {