-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit.js
40 lines (31 loc) · 966 Bytes
/
split.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
const glob = require('glob');
if (!process.env.CI_NODE_TOTAL) {
console.error('No envrionment variable CI_NODE_TOTAL defined');
process.exit(1);
}
if (!process.env.CI_NODE_INDEX) {
console.error('No envrionment variable CI_NODE_INDEX defined');
process.exit(1);
}
function splitChunks(items, total) {
let chunks = [];
let currentChunk = 1;
for (let currentItem = 0; currentItem < items.length; currentItem++) {
if (!chunks[currentChunk]) {
chunks[currentChunk] = [];
}
chunks[currentChunk].push(items[currentItem]);
currentChunk++;
if (currentChunk > total) {
currentChunk = 1;
}
}
return chunks;
}
const files = glob.sync('tests/**/*.js');
const chunks = splitChunks(files, process.env.CI_NODE_TOTAL);
if (chunks[process.env.CI_NODE_INDEX]) {
for (file of chunks[process.env.CI_NODE_INDEX]) {
process.stdout.write(file + "\n");
}
}