Skip to content

style: re-order imports; use const instead of var where applicable #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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();
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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
)}%)`
Expand Down
14 changes: 6 additions & 8 deletions lib/json-stream.reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*/
Expand All @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions lib/simple-spec.reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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);
Expand Down Expand Up @@ -70,8 +68,8 @@ function JSONStreamCustom(runner, options) {
})
} else {
consoleLog(format, getTestDescription(test));
}
});
}
});

runner.on(EVENT_TEST_PASS, function (test) {
const format =
Expand Down
6 changes: 3 additions & 3 deletions lib/test-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/thread.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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 {
Expand Down