Skip to content
Permalink
Browse files

Use chunkd to compute files to test in parallel CI runs

  • Loading branch information...
jamiebuilds authored and novemberborn committed Sep 30, 2018
1 parent 6d12abf commit 2ff668429c7cc55a445d96ec37f04b755d6b41ef
Showing with 17 additions and 13 deletions.
  1. +6 −8 api.js
  2. +10 −5 package-lock.json
  3. +1 −0 package.json
14 api.js
@@ -13,6 +13,7 @@ const getPort = require('get-port');
const arrify = require('arrify');
const makeDir = require('make-dir');
const ms = require('ms');
const chunkd = require('chunkd');
const babelPipeline = require('./lib/babel-pipeline');
const Emittery = require('./lib/emittery');
const RunStatus = require('./lib/run-status');
@@ -84,18 +85,15 @@ class Api extends Emittery {
return new AvaFiles({cwd: apiOptions.resolveTestsFrom, files, extensions: this._allExtensions}).findTestFiles()
.then(files => {
if (this.options.parallelRuns) {
// The files must be in the same order across all runs, so sort them.
files = files.sort((a, b) => a.localeCompare(b, [], {numeric: true}));

const {currentIndex, totalRuns} = this.options.parallelRuns;
const fileCount = files.length;
const each = Math.floor(fileCount / totalRuns);
const remainder = fileCount % totalRuns;

const offset = Math.min(currentIndex, remainder) + (currentIndex * each);
const currentFileCount = each + (currentIndex < remainder ? 1 : 0);
// The files must be in the same order across all runs, so sort them.
files = files.sort((a, b) => a.localeCompare(b, [], {numeric: true}));
files = chunkd(files, currentIndex, totalRuns);

const currentFileCount = files.length;

files = files.slice(offset, offset + currentFileCount);
runStatus = new RunStatus(fileCount, {currentFileCount, currentIndex, totalRuns});
} else {
runStatus = new RunStatus(files.length, null);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -76,6 +76,7 @@
"bluebird": "^3.5.1",
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"chunkd": "^1.0.0",
"ci-parallel-vars": "^1.0.0",
"clean-stack": "^1.1.1",
"clean-yaml-object": "^0.1.0",

0 comments on commit 2ff6684

Please sign in to comment.
You can’t perform that action at this time.