Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created April 9, 2019 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsh-code/a1bae3b61b4639c05460022b5112bcf4 to your computer and use it in GitHub Desktop.
Save tsh-code/a1bae3b61b4639c05460022b5112bcf4 to your computer and use it in GitHub Desktop.
Chunk tests
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