Skip to content

Instantly share code, notes, and snippets.

@devpie
Last active February 19, 2021 15:04
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 devpie/3f37ee7f26e2eae66e4ee85196393ffd to your computer and use it in GitHub Desktop.
Save devpie/3f37ee7f26e2eae66e4ee85196393ffd to your computer and use it in GitHub Desktop.
Get a chunk of spec files. Use it like 'cypress run --spec $(node scripts/cypress-spec-chunk.js 4 0)'.
#!/usr/bin/env node
/* tslint:disable:no-console */
const find = require("find");
const path = require("path");
const projectDirectory = path.resolve(__dirname, ".."); // because it is in ./scripts
const printChunk = (testFiles, totalChunks, chunkIndex) => {
const chunkSize = Math.ceil(testFiles.length/totalChunks);
const chunk = testFiles.slice(chunkIndex * chunkSize, chunkIndex * chunkSize + chunkSize);
console.log(chunk.join(','));
};
const main = (dir) => {
const totalChunks = process.argv[2];
const chunkIndex = process.argv[3];
const files = find.fileSync(/\.spec.ts$/, `${dir}/cypress/integration`).sort();
printChunk(files, totalChunks, chunkIndex);
};
main(projectDirectory);
{
"scripts": {
"cy:parallel": "concurrently -n 'cy1,cy2' -p '{time}|{name}' 'cypress run --spec $(node scripts/cypress-spec-chunk.js 2 0)' 'cypress run --spec $(node scripts/cypress-spec-chunk.js 2 1)'"
},
"dev-dependencies": {
"find": "xxx",
"concurrently": "xxx"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment