Last active
May 28, 2019 01:45
-
-
Save apiv/8995f51ca5314fc1085e62d07a957b61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @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