diff --git a/lib/cli.js b/lib/cli.js index f616e8c..eae041d 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,9 +1,10 @@ #!/usr/bin/env node -const Table = require('cli-table3'); -const colors = require('@colors/colors/safe'); const path = require('path'); const fs = require('fs-extra'); +const Table = require('cli-table3'); +const colors = require('@colors/colors/safe'); + const { settings } = require('./settings'); const { getTestSuitePaths, distributeTestsByWeight, getMaxPathLenghtFrom } = require('./test-suites'); @@ -15,18 +16,18 @@ 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.error(err); + for (const file of files) { + fs.unlink(path.join(resultsPath, file), err => { if (err) console.error(err); }); + } + }); } +} async function start() { cleanResultsPath(); @@ -45,7 +46,7 @@ async function start() { // should split below into calculateStatistics and presentResult methods resultMaps.forEach((m, t) => { let totTimeThread = 0; - for (let [name, test] of m) { + for (const [name, test] of m) { totTimeThread += test.duration; } @@ -66,7 +67,7 @@ async function start() { let totalWeight = timeMap.size * 10; let specWeights = {}; - for (let [name, suite] of timeMap) { + for (const [name, suite] of timeMap) { //The value of suite.tests is not what we expect. const nbTests = suite.passes + suite.pending + suite.failures; totalDuration += suite.duration; @@ -119,8 +120,7 @@ async function start() { const timeSaved = totalDuration - timeTaken; console.log( - `Total run time: ${totalDuration / 1000}s, executed in: ${ - timeTaken / 1000 + `Total run time: ${totalDuration / 1000}s, executed in: ${timeTaken / 1000 }, saved ${timeSaved / 1000} (~${Math.round( (timeSaved / totalDuration) * 100 )}%)` diff --git a/lib/json-stream.reporter.js b/lib/json-stream.reporter.js index 14dea14..37135f5 100644 --- a/lib/json-stream.reporter.js +++ b/lib/json-stream.reporter.js @@ -5,15 +5,13 @@ /** * Module dependencies. */ -var Base = require('mocha/lib/reporters/base'); -var constants = require('mocha/lib/runner').constants; -var path = require('path'); -var fs = require('fs'); +const path = require('path'); +const fs = require('fs'); +const Base = require('mocha/lib/reporters/base'); +const { EVENT_SUITE_END } = require('mocha/lib/runner').constants; const { resultsPath } = require('./shared-config'); -const { EVENT_SUITE_END } = constants; - /** * Expose `JSONStream`. */ @@ -26,8 +24,8 @@ exports = module.exports = JSONStreamCustom; * @class * @memberof Mocha.reporters * @extends Mocha.reporters.Base - * @param {Runner} runner - Instance triggers reporter actions. - * @param {Object} [options] - runner options + * @param {Mocha.Runner} runner - Instance triggers reporter actions. + * @param {Mocha.RunnerOptions} [options] - runner options */ function JSONStreamCustom(runner, options) { Base.call(this, runner, options); diff --git a/lib/simple-spec.reporter.js b/lib/simple-spec.reporter.js index fbc346e..6449509 100644 --- a/lib/simple-spec.reporter.js +++ b/lib/simple-spec.reporter.js @@ -5,17 +5,15 @@ /** * Module dependencies. */ -var Base = require('mocha/lib/reporters/base'); -var constants = require('mocha/lib/runner').constants; - -const settings = JSON.parse(process.env.CY_PARALLEL_SETTINGS); - +const Base = require('mocha/lib/reporters/base'); const { EVENT_TEST_PENDING, EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_SUITE_BEGIN -} = constants; +} = require('mocha/lib/runner').constants; + +const settings = JSON.parse(process.env.CY_PARALLEL_SETTINGS); /** * Expose `JSONStream`. @@ -29,8 +27,8 @@ exports = module.exports = JSONStreamCustom; * @class * @memberof Mocha.reporters * @extends Mocha.reporters.Base - * @param {Runner} runner - Instance triggers reporter actions. - * @param {Object} [options] - runner options + * @param {Mocha.Runner} runner - Instance triggers reporter actions. + * @param {Mocha.RunnerOptions} [options] - runner options */ function JSONStreamCustom(runner, options) { Base.call(this, runner, options); @@ -70,8 +68,8 @@ function JSONStreamCustom(runner, options) { }) } else { consoleLog(format, getTestDescription(test)); - } - }); + } + }); runner.on(EVENT_TEST_PASS, function (test) { const format = diff --git a/lib/test-suites.js b/lib/test-suites.js index 4bdb2fc..e5fe724 100644 --- a/lib/test-suites.js +++ b/lib/test-suites.js @@ -22,7 +22,7 @@ async function getTestSuitePaths() { console.log(`Using pattern ${settings.testSuitesPath} to find test suites`); fileList = await glob(settings.testSuitesPath, { ignore: 'node_modules/**' }); } else { - console.log( + console.warn( 'DEPRECATED: using path is deprecated and will be removed, switch to glob pattern' ); fileList = getFilePathsByPath(settings.testSuitesPath); @@ -48,7 +48,7 @@ async function getTestSuitePaths() { function getMaxPathLenghtFrom(testSuitePaths) { let maxLength = 10; - for(let path of testSuitePaths){ + for(const path of testSuitePaths){ maxLength = Math.max(maxLength, path.length); } @@ -64,7 +64,7 @@ function distributeTestsByWeight(testSuitePaths) { } let map = new Map(); - for (let f of testSuitePaths) { + for (const f of testSuitePaths) { let specWeight = settings.defaultWeight; Object.keys(specWeights).forEach((spec) => { if (f.endsWith(spec)) { diff --git a/lib/thread.js b/lib/thread.js index 70db2bd..bdf15fe 100644 --- a/lib/thread.js +++ b/lib/thread.js @@ -1,7 +1,7 @@ -const spawn = require('cross-spawn'); -const { isYarn } = require('is-npm'); const path = require('path'); const fs = require('fs'); +const spawn = require('cross-spawn'); +const { isYarn } = require('is-npm'); const camelCase = require('lodash.camelcase'); const globEscape = require('glob-escape'); @@ -32,7 +32,7 @@ function createReporterOptions(string) { function createReporterConfigFile(path) { const reporterEnabled = ['cypress-parallel/json-stream.reporter.js']; - let reporterName = settings.reporter; + const reporterName = settings.reporter; if (settings.reporter) { reporterEnabled.push(reporterName); } else {