Last active
February 19, 2021 15:04
-
-
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)'.
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
#!/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); |
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
{ | |
"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