-
-
Save tsh-code/a1bae3b61b4639c05460022b5112bcf4 to your computer and use it in GitHub Desktop.
Chunk tests
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
import _ from 'lodash'; | |
export const chunkSpecs = (commandArgs, allSpecs, expectedArrayLength, numberOfInstances) => { | |
if (commandArgs.pattern !== undefined && typeof commandArgs.pattern !== 'boolean') { | |
const patterns = commandArgs.pattern.split(','); | |
const chunkedSpecs = []; | |
if (patterns.length !== numberOfInstances) { | |
throw new Error('Number of the specified patterns is different than number of instances!'); | |
} | |
for (const pattern of patterns) { | |
chunkedSpecs.push(allSpecs.filter(spec => spec.match(new RegExp(pattern)))); | |
} | |
return chunkedSpecs; | |
} | |
return _.chunk(allSpecs, expectedArrayLength); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment