Skip to content

Instantly share code, notes, and snippets.

@gyandeeps
Last active April 17, 2018 13:56
Show Gist options
  • Save gyandeeps/61aab150e38d4d0c545fecd5d13b24b4 to your computer and use it in GitHub Desktop.
Save gyandeeps/61aab150e38d4d0c545fecd5d13b24b4 to your computer and use it in GitHub Desktop.
Parallel run test for ESLint
const workerFarm = require("worker-farm");
const FARM_OPTIONS = {
maxConcurrentWorkers : require('os').cpus().length
, maxCallsPerWorker : Infinity
, maxConcurrentCallsPerWorker : 1
};
const workers = workerFarm(FARM_OPTIONS, require.resolve("./worker"));
let ret = 0;
const isMulti = process.argv[2] && parseInt(process.argv[2], 10) === 1;
if (isMulti) {
console.log("Multi");
const patterns = [
["lib/**/*.js"],
["lib1/**/*.js"],
["lib2/**/*.js"],
["lib3/**/*.js"],
["lib4/**/*.js"],
["lib5/**/*.js"],
["tests/**/*.js"],
["tests1/**/*.js"],
["tests2/**/*.js"],
["tests3/**/*.js"],
["tests4/**/*.js"],
["tests5/**/*.js"]
];
const maxRet = patterns.length;
for (var i = 0; i < maxRet; i++) {
workers(patterns[i], function (err, outp) {
console.log("done");
if (++ret === maxRet)
workerFarm.end(workers)
})
}
}
else {
console.log("Single");
const workerMod = require("./worker");
const maxRet = 1;
const patterns = [
["lib/**/*.js", "lib1/**/*.js", "lib2/**/*.js", "lib3/**/*.js", "lib4/**/*.js", "lib5/**/*.js", "tests/**/*.js", "tests1/**/*.js", "tests2/**/*.js", "tests3/**/*.js", "tests4/**/*.js", "tests5/**/*.js"]
];
for (var i = 0; i < maxRet; i++) {
workerMod(patterns[0], function (err, outp) {
//console.log("done");
console.log("done", outp.results.length);
if (++ret === maxRet)
workerFarm.end(workers)
})
}
}

Setup

  1. Clone ESLint and run npm install
  2. Copy above 2 files inside the ESLint folder
  3. create 5 copies of the lib folder
  4. create 5 copies of tests folder
    • Makesure you remove bench, fixtures and performance folders from tests<1 to 5> folders.
  5. Single Run: time node run.js
  6. Parallel run: time node run.js 1
    • for other runs just comment out different globs
const CLIEngine = require("./lib/cli-engine");
const engine = new CLIEngine({});
module.exports = (pattern, callback) => {
const fileConfig = engine.executeOnFiles(pattern);
callback(null, fileConfig);
};
@gyandeeps
Copy link
Author

gyandeeps commented Jun 30, 2017

My machine: Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz, 8gb ram

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment