diff --git a/README.md b/README.md index 60f59a6..6f55e96 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ In your `package.json` add a new script: "scripts" :{ ... "cy:run": "cypress run", // It can be any cypress command with any argument - "cy:parallel" : "cypress-parallel -s cy:run -t 2 -d '' -a '\"\"'" + "cy:parallel" : "cypress-parallel -s cy:run -t 2 --spec '' -a '\"\"'" ... } ``` @@ -64,33 +64,32 @@ or Run with npx (no package installation needed) ``` -npx cy:parallel -s cy:run -t 2 -d '' -a '""' +npx cy:parallel -s cy:run -t 2 --spec '' -a '""' ``` -## Passing Specs +## Passing Multiple Specs ``` -cypress-parallel -s cy:run -t 2 -a '\"\"' --spec path/to/spec1.spec.js path/to/spec2.spec.js +cypress-parallel -s cy:run -t 2 -a '\"\"' --spec path/to/spec1.spec.js path/to/spec2.spec.js path/to/more/specs/**/*.js ``` ### Scripts options -| Option | Alias | Description | Type | -| ----------------- | ----- | ---------------------------------- | ------ | -| --help | | Show help | | -| --version | | Show version number | | -| --script | -s | Your npm Cypress command | string | -| --args | -a | Your npm Cypress command arguments | string | -| --threads | -t | Number of threads | number | -| --specsDir | -d | Cypress specs directory | string | -| --spec | | Cypress spec file paths | string | -| --weightsJson | -w | Parallel weights json file | string | -| --reporter | -r | Reporter to pass to Cypress. | string | -| --reporterOptions | -o | Reporter options | string | -| --reporterModulePath | -n | Specify the reporter module path | string | -| --bail | -b | Exit on first failing thread | string | -| --verbose | -v | Some additional logging | string | -| --strictMode | -m | Add stricter checks after running the tests | boolean | +| Option | Alias | Description | Type | +| -------------------- | ----- | --------------------------------------------------------------------- | ------- | +| --help | | Show help | | +| --version | | Show version number | | +| --script | -s | Your npm Cypress command | string | +| --args | -a | Your npm Cypress command arguments | string | +| --threads | -t | Number of threads | number | +| --spec | -d | Cypress spec file path(s), or glob pattern(s). Can be one, or a list. | string | +| --weightsJson | -w | Parallel weights json file | string | +| --reporter | -r | Reporter to pass to Cypress. | string | +| --reporterOptions | -o | Reporter options | string | +| --reporterModulePath | -n | Specify the reporter module path | string | +| --bail | -b | Exit on first failing thread | string | +| --verbose | -v | Some additional logging | string | +| --strictMode | -m | Add stricter checks after running the tests | boolean | **NB**: If you use *cypress-cucumber-preprocesor*, please **disable** the *strictMode* to avoid possible errors: diff --git a/lib/README.md b/lib/README.md index 823a107..6f55e96 100644 --- a/lib/README.md +++ b/lib/README.md @@ -23,13 +23,13 @@ Reduce up to 40% your Cypress suite execution time parallelizing the test run on ## Install ``` -npm i cypress-parallel +npm i cypress-parallel -D ``` or ``` -yarn add cypress-parallel +yarn add cypress-parallel -D ``` ## Add a new script @@ -40,7 +40,7 @@ In your `package.json` add a new script: "scripts" :{ ... "cy:run": "cypress run", // It can be any cypress command with any argument - "cy:parallel" : "cypress-parallel -s cy:run -t 2 -d -a '\"\"'" + "cy:parallel" : "cypress-parallel -s cy:run -t 2 --spec '' -a '\"\"'" ... } ``` @@ -64,26 +64,32 @@ or Run with npx (no package installation needed) ``` -npx cy:parallel -s cy:run -t 2 -d -a '\"\"' +npx cy:parallel -s cy:run -t 2 --spec '' -a '""' +``` + +## Passing Multiple Specs + +``` +cypress-parallel -s cy:run -t 2 -a '\"\"' --spec path/to/spec1.spec.js path/to/spec2.spec.js path/to/more/specs/**/*.js ``` ### Scripts options -| Option | Alias | Description | Type | -| ----------------- | ----- | ---------------------------------- | ------ | -| --help | | Show help | | -| --version | | Show version number | | -| --script | -s | Your npm Cypress command | string | -| --args | -a | Your npm Cypress command arguments | string | -| --threads | -t | Number of threads | number | -| --specsDir | -d | Cypress specs directory | string | -| --weightsJson | -w | Parallel weights json file | string | -| --reporter | -r | Reporter to pass to Cypress. | string | -| --reporterOptions | -o | Reporter options | string | -| --reporterModulePath | -n | Specify the reporter module path | string | -| --bail | -b | Exit on first failing thread | string | -| --verbose | -v | Some additional logging | string | -| --strictMode | -m | Add stricter checks after running the tests | boolean | +| Option | Alias | Description | Type | +| -------------------- | ----- | --------------------------------------------------------------------- | ------- | +| --help | | Show help | | +| --version | | Show version number | | +| --script | -s | Your npm Cypress command | string | +| --args | -a | Your npm Cypress command arguments | string | +| --threads | -t | Number of threads | number | +| --spec | -d | Cypress spec file path(s), or glob pattern(s). Can be one, or a list. | string | +| --weightsJson | -w | Parallel weights json file | string | +| --reporter | -r | Reporter to pass to Cypress. | string | +| --reporterOptions | -o | Reporter options | string | +| --reporterModulePath | -n | Specify the reporter module path | string | +| --bail | -b | Exit on first failing thread | string | +| --verbose | -v | Some additional logging | string | +| --strictMode | -m | Add stricter checks after running the tests | boolean | **NB**: If you use *cypress-cucumber-preprocesor*, please **disable** the *strictMode* to avoid possible errors: @@ -105,10 +111,21 @@ npx cy:parallel -s cy:run -t 2 -d -a '\" - fs.readdirSync(dir).reduce((files, file) => { - const name = path.join(dir, file); - const isDirectory = fs.statSync(name).isDirectory(); - if (isDirectory) return [...files, ...getFilePathsByPath(name)]; - return [...files, name]; - }, []); - async function getTestSuitePaths() { - const isPattern = settings.testSuitesPath.includes('*'); - - let fileList; - if (settings.testSuitesPaths) { - fileList = settings.testSuitesPaths; - } else if (isPattern) { - console.log(`Using pattern ${settings.testSuitesPath} to find test suites`); - fileList = await glob(settings.testSuitesPath, { ignore: 'node_modules/**' }); - } else { - console.log( - 'DEPRECATED: using path is deprecated and will be removed, switch to glob pattern' - ); - fileList = getFilePathsByPath(settings.testSuitesPath); + let fileList = []; + for (const suitePath of settings.testSuitesPaths) { + let globPattern = undefined + if (suitePath.includes('*')) { + globPattern = suitePath + } else if (fs.existsSync(suitePath) && fs.lstatSync(suitePath).isDirectory()) { + console.log( + 'DEPRECATED: using directory path is deprecated and will be removed, switch to glob pattern' + ); + globPattern = `${suitePath}/**/*` + } + + if (globPattern) { + if (settings.isVerbose) { + console.log(`Using pattern ${globPattern} to find test suites`); + } + const thisFileList = await glob(globPattern, { ignore: 'node_modules/**' }) + fileList.concat(thisFileList); + } else { + fileList.append(suitePath) + } } console.log(`${fileList.length} test suite(s) found.`); @@ -36,19 +36,21 @@ async function getTestSuitePaths() { // We can't run more threads than suites if (fileList.length < settings.threadCount) { - console.log( - `Thread setting is ${settings.threadCount}, but only ${fileList.length} test suite(s) were found. Adjusting configuration accordingly.` - ); + if (settings.isVerbose) { + console.log( + `Thread setting is ${settings.threadCount}, but only ${fileList.length} test suite(s) were found. Adjusting configuration accordingly.` + ); + } settings.threadCount = fileList.length; } return fileList; } -function getMaxPathLenghtFrom(testSuitePaths) { +function getMaxPathLengthFrom(testSuitePaths) { let maxLength = 10; - for(let path of testSuitePaths){ + for (let path of testSuitePaths) { maxLength = Math.max(maxLength, path.length); } @@ -99,5 +101,5 @@ function distributeTestsByWeight(testSuitePaths) { module.exports = { getTestSuitePaths, distributeTestsByWeight, - getMaxPathLenghtFrom + getMaxPathLengthFrom };