Skip to content

Commit

Permalink
remaining conflicts & misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiah-snee-openx committed Jul 3, 2024
1 parent 59ff696 commit 65778df
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
30 changes: 18 additions & 12 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions lib/json-stream.reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var fs = require('fs');
const { resultsPath } = require('./shared-config');

const { EVENT_SUITE_END } = constants;
let resultsPath;

/**
* Expose `JSONStream`.
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions lib/test-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -112,5 +113,5 @@ function distributeTestsByWeight(testSuitePaths) {
module.exports = {
getTestSuitePaths,
distributeTestsByWeight,
getMaxPathLenghtFrom
getMaxPathLengthFrom: getMaxPathLengthFrom
};
1 change: 1 addition & 0 deletions lib/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 65778df

Please sign in to comment.