From 65778dfbc4ac377d7e27b0e8d81b9d140bdb1c54 Mon Sep 17 00:00:00 2001 From: Jeremiah Snee <113928685+jeremiah-snee-openx@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:04:21 -0500 Subject: [PATCH] remaining conflicts & misc fixes --- lib/cli.js | 30 ++++++++++++++++++------------ lib/json-stream.reporter.js | 11 +++++++++++ lib/settings.js | 8 +++++++- lib/test-suites.js | 9 +++++---- lib/thread.js | 1 + 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index f616e8c..0a48b63 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -6,7 +6,11 @@ const path = require('path'); const fs = require('fs-extra'); const { settings } = require('./settings'); -const { getTestSuitePaths, distributeTestsByWeight, getMaxPathLenghtFrom } = require('./test-suites'); +const { + getTestSuitePaths, + distributeTestsByWeight, + getMaxPathLengthFrom +} = require('./test-suites'); const { formatTime, generateWeightsFile, @@ -15,18 +19,20 @@ const { const { executeThread } = require('./thread'); const { resultsPath } = require('./shared-config'); -function cleanResultsPath() { - if(!fs.existsSync(resultsPath)) { - fs.mkdirSync(resultsPath, { recursive: true }) +function cleanResultsPath() { + if (!fs.existsSync(resultsPath)) { + fs.mkdirSync(resultsPath, { recursive: true }); } else { fs.readdir(resultsPath, (err, files) => { - if (err) console.log(err); - for (const file of files) { - fs.unlink(path.join(resultsPath, file), err => { if (err) console.log(err); }); - } - }); - } + if (err) console.log(err); + for (const file of files) { + fs.unlink(path.join(resultsPath, file), (err) => { + if (err) console.log(err); + }); + } + }); } +} async function start() { cleanResultsPath(); @@ -37,7 +43,7 @@ async function start() { const end = new Date(); const timeTaken = end.getTime() - start.getTime(); - const resultsPath = path.join(process.cwd(), 'runner-results'); + const resultsPath = path.join(process.cwd(), settings.runnerResults); const resultMaps = [collectResults(resultsPath)]; let timeMap = new Map(); @@ -55,7 +61,7 @@ async function start() { let table = new Table({ head: ['Spec', 'Time', 'Tests', 'Passing', 'Failing', 'Pending'], style: { head: ['blue'] }, - colWidths: [getMaxPathLenghtFrom(testSuitePaths), 10, 10, 10, 10, 10] + colWidths: [getMaxPathLengthFrom(testSuitePaths), 10, 10, 10, 10, 10] }); let totalTests = 0; diff --git a/lib/json-stream.reporter.js b/lib/json-stream.reporter.js index 14dea14..30d91c1 100644 --- a/lib/json-stream.reporter.js +++ b/lib/json-stream.reporter.js @@ -13,6 +13,7 @@ var fs = require('fs'); const { resultsPath } = require('./shared-config'); const { EVENT_SUITE_END } = constants; +let resultsPath; /** * Expose `JSONStream`. @@ -30,6 +31,16 @@ exports = module.exports = JSONStreamCustom; * @param {Object} [options] - runner options */ function JSONStreamCustom(runner, options) { + const reporterConfigPath = path.join( + process.cwd(), + options.reporterOptions.config + ? options.reporterOptions.config + : 'multi-reporter-config.json' + ); + resultsPath = JSON.parse( + fs.readFileSync(reporterConfigPath, 'utf8') + ).runnerResults; + Base.call(this, runner, options); var self = this; var total = runner.total; diff --git a/lib/settings.js b/lib/settings.js index b49e41e..37b71c0 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -66,6 +66,11 @@ const argv = yargs alias: 'w', type: 'string', description: 'Parallel weights json file' + }) + .option('runnerResults', { + alias: 'x', + type: 'string', + description: 'Path where cypress results will be located' }).argv; if (!argv.script) { @@ -103,7 +108,8 @@ const settings = { reporterOptionsPath: argv.reporterOptionsPath, script: argv.script, strictMode: argv.strictMode, - scriptArguments: argv.args ? argv.args.split(' ') : [] + scriptArguments: argv.args ? argv.args.split(' ') : [], + runnerResults: argv.runnerResults ? argv.runnerResults : 'runner-results' }; process.env.CY_PARALLEL_SETTINGS = JSON.stringify(settings); diff --git a/lib/test-suites.js b/lib/test-suites.js index af73aca..6897747 100644 --- a/lib/test-suites.js +++ b/lib/test-suites.js @@ -3,6 +3,7 @@ const path = require('path'); const glob = require('glob'); const { settings } = require('./settings'); +const { resultsPath } = require('./shared-config'); const getFilePathsByPath = (dir) => fs.readdirSync(dir).reduce((files, file) => { @@ -27,7 +28,7 @@ const getFilePathsByGlob = (pattern) => { async function getTestSuitePaths() { const isPattern = settings.testSuitesPath.includes('*'); - + console.log(`Cleaning results path ${resultsPath}`); let fileList; if (settings.testSuitesPaths) { fileList = settings.testSuitesPaths; @@ -58,10 +59,10 @@ async function getTestSuitePaths() { return fileList; } -function getMaxPathLenghtFrom(testSuitePaths) { +function getMaxPathLengthFrom(testSuitePaths) { let maxLength = 10; - for(let path of testSuitePaths){ + for (let path of testSuitePaths) { maxLength = Math.max(maxLength, path.length); } @@ -112,5 +113,5 @@ function distributeTestsByWeight(testSuitePaths) { module.exports = { getTestSuitePaths, distributeTestsByWeight, - getMaxPathLenghtFrom + getMaxPathLengthFrom: getMaxPathLengthFrom }; diff --git a/lib/thread.js b/lib/thread.js index d884093..143afdf 100644 --- a/lib/thread.js +++ b/lib/thread.js @@ -46,6 +46,7 @@ function createReporterConfigFile(path) { const optionName = `${camelCase(reporterName)}ReporterOptions`; content[optionName] = createReporterOptions(settings.reporterOptions); } + content['runnerResults'] = settings.runnerResults; fs.writeFileSync(path, JSON.stringify(content, null, 2)); }