Skip to content

Instantly share code, notes, and snippets.

@apiv
Last active May 28, 2019 01:45
Show Gist options
  • Save apiv/8995f51ca5314fc1085e62d07a957b61 to your computer and use it in GitHub Desktop.
Save apiv/8995f51ca5314fc1085e62d07a957b61 to your computer and use it in GitHub Desktop.
/* @flow */
import glob from 'glob'
/**
* writes a list of files matching the glob pattern to stdout
* runs only the subset of files which fall within the job, set
* in the environment variables.
*
* JOB_COUNT is the number of jobs we will be splitting across, 1-indexed
* JOB_INDEX is the index of the job (subset of files) we should be running, 0-indexed
*/
const {
JOB_COUNT = 1,
JOB_INDEX = 0
}: any = process.env
/**
* gets a list of files matching the given glob
* @returns {string}
*/
function getFiles (): string[] {
const allFiles = glob.sync('src/**/*.test.js')
const filesPerJob = Math.ceil(allFiles.length / JOB_COUNT)
const startIndex = filesPerJob * JOB_INDEX
return allFiles
.slice(startIndex, startIndex + filesPerJob)
}
const files = getFiles()
/**
* Join the array of files is into a single string,
* a new glob pattern which will match all of the
* selected files, exclusively.
*/
process.stdout.write(files.map((str) => '**/' + str).join('|'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment