forked from fusionjs/fusion-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-test-files.js
46 lines (39 loc) · 1.32 KB
/
get-test-files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* @flow */
/* eslint-env node */
// Based off https://labs.contactually.com/parallelizing-jest-across-multiple-ci-containers-551e7d3e4cb0
const glob = require('globby');
const {testPathIgnorePatterns} = require('./jest.config.js');
/**
* 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() /*: Array<string> */ {
const allFiles = glob.sync(
[
'**/test.js',
'**/*.spec.js',
'**/*.test.js',
...testPathIgnorePatterns.map(pattern => `!${pattern}`),
],
{gitignore: true}
);
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('|'));