Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ cypress-parallel -s cy:run -t 2 -a '\"<your-cypress-cmd-args>\"' --spec path/to/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added defaults to table.

### 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 | Default |
| -------------------- | ----- | ------------------------------------------- | ------- | ------------------------------------------------------------------------ |
| --help | | Show help | |
| --version | | Show version number | |
| --script | -s | Your npm Cypress command (required) | string |
| --args | -a | Your npm Cypress command arguments | string |
| --threads | -t | Number of threads | number | 2 |
| --specsDir | -d | Cypress specs directory | string | 'cypress/e2e' (cy version 10+) or 'cypress/integration' (cy version <10) |
| --spec | | Cypress spec file paths | string |
| --weightsJson | -w | Parallel weights json file | string | 'cypress/parallel-weights.json' |
| --reporter | -r | Reporter to pass to Cypress. | string |
| --reporterOptions | -o | Reporter options | string |
| --reporterModulePath | -n | Specify the reporter module path | string | 'cypress-multi-reporters' |
| --bail | -b | Exit on first failing thread | string | false |
| --verbose | -v | Some additional logging | string | false |
| --strictMode | -m | Add stricter checks after running the tests | boolean | true |

**NB**: If you use *cypress-cucumber-preprocesor*, please **disable** the *strictMode* to avoid possible errors:

Expand Down
58 changes: 38 additions & 20 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Reduce up to 40% your Cypress suite execution time parallelizing the test run on
## Install
Copy link
Author

@bvandercar-vt bvandercar-vt Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just copied this from ./README.md to match.


```
npm i cypress-parallel
npm i cypress-parallel -D
```

or

```
yarn add cypress-parallel
yarn add cypress-parallel -D
```

## Add a new script
Expand All @@ -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 <your-cypress-specs-folder> -a '\"<your-cypress-cmd-args>\"'"
"cy:parallel" : "cypress-parallel -s cy:run -t 2 -d '<your-cypress-specs-folder>' -a '\"<your-cypress-cmd-args>\"'"
...
}
```
Expand All @@ -64,26 +64,33 @@ or
Run with npx (no package installation needed)

```
npx cy:parallel -s cy:run -t 2 -d <your-cypress-specs-folder> -a '\"<your-cypress-cmd-args>\"'
npx cy:parallel -s cy:run -t 2 -d '<your-cypress-specs-folder>' -a '"<your-cypress-cmd-args>"'
```

## Passing Specs

```
cypress-parallel -s cy:run -t 2 -a '\"<your-cypress-cmd-args>\"' --spec path/to/spec1.spec.js path/to/spec2.spec.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 | Default |
| -------------------- | ----- | ------------------------------------------- | ------- | ------------------------------------------------------------------------ |
| --help | | Show help | |
| --version | | Show version number | |
| --script | -s | Your npm Cypress command (required) | string |
| --args | -a | Your npm Cypress command arguments | string |
| --threads | -t | Number of threads | number | 2 |
| --specsDir | -d | Cypress specs directory | string | 'cypress/e2e' (cy version 10+) or 'cypress/integration' (cy version <10) |
| --spec | | Cypress spec file paths | string |
| --weightsJson | -w | Parallel weights json file | string | 'cypress/parallel-weights.json' |
| --reporter | -r | Reporter to pass to Cypress. | string |
| --reporterOptions | -o | Reporter options | string |
| --reporterModulePath | -n | Specify the reporter module path | string | 'cypress-multi-reporters' |
| --bail | -b | Exit on first failing thread | string | false |
| --verbose | -v | Some additional logging | string | false |
| --strictMode | -m | Add stricter checks after running the tests | boolean | true |

**NB**: If you use *cypress-cucumber-preprocesor*, please **disable** the *strictMode* to avoid possible errors:

Expand All @@ -105,10 +112,21 @@ npx cy:parallel -s cy:run -t 2 -d <your-cypress-specs-folder> -a '\"<your-cypres
}
```

## Env variables

### CYPRESS_THREAD

You can get the current thread index by reading the `CYPRESS_THREAD` variable.

```javascript
const threadIndex = process.env.CYPRESS_THREAD;
// return 1, 2, 3, 4, ...
```

# Contributors

Looking for contributors.

# License

MIT
This project is licensed under the MIT license. See [LICENSE](LICENSE).
44 changes: 33 additions & 11 deletions lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
const yargs = require('yargs');

const cypressVersion = require('cypress/package.json').version;
const cypressMajorVersion = parseInt(cypressVersion.split('.')[0], 10);

const argv = yargs
.parserConfiguration({ 'duplicate-arguments-array': false })
.option('script', {
alias: 's',
type: 'string',
requiresArg: true,
description: 'Your npm Cypress command'
})
.option('threads', {
alias: 't',
type: 'number',
default: 2,
description: 'Number of threads'
})
.option('verbose', {
alias: 'v',
type: 'boolean',
default: false,
description: 'Execute with verbose logging'
})
.option('bail', {
alias: 'b',
type: 'boolean',
default: false,
description: 'Exit on first suite finishing with errors'
})
.option('specsDir', {
alias: 'd',
type: 'string',
default: cypressMajorVersion >= 10 ? 'cypress/e2e' : 'cypress/integration',
description: 'Cypress specs directory'
})
.option('spec', {
type: 'array',
default: undefined,
description: 'List of Cypress spec paths'
})
.option('args', {
Expand All @@ -44,6 +53,7 @@ const argv = yargs
.option('reporterModulePath', {
alias: 'n',
type: 'string',
default: 'cypress-multi-reporters',
description: 'Reporter module path'
})
.option('reporterOptions', {
Expand All @@ -65,6 +75,7 @@ const argv = yargs
.option('weightsJson', {
alias: 'w',
type: 'string',
default: 'cypress/parallel-weights.json',
description: 'Parallel weights json file'
}).argv;

Expand All @@ -83,20 +94,31 @@ const COLORS = [
'\x1b[40m'
];

/** @type {{
threadCount: number
testSuitesPaths: string[]
shouldBail: boolean
isVerbose: boolean
weightsJSON: string
defaultWeight: number
reporter?: string
reporterModulePath: string
reporterOptions?: string
reporterOptionsPath?: string
script: string
strictMode: boolean
scriptArguments: string[]
}} */
const settings = {
threadCount: argv.threads ? argv.threads : 2,
testSuitesPath: argv.specsDir ? argv.specsDir : 'cypress/integration',
testSuitesPaths: argv.spec ? argv.spec : undefined,
shouldBail: argv.bail ? argv.bail : false,
isVerbose: argv.verbose ? argv.verbose : false,
weightsJSON: argv.weightsJson
? argv.weightsJson
: 'cypress/parallel-weights.json',
threadCount: argv.threads,
testSuitesPath: argv.specsDir,
testSuitesPaths: argv.spec,
shouldBail: argv.bail,
isVerbose: argv.verbose,
weightsJSON: argv.weightsJson,
defaultWeight: 1,
reporter: argv.reporter,
reporterModulePath: argv.reporterModulePath
? argv.reporterModulePath
: 'cypress-multi-reporters',
reporterModulePath: argv.reporterModulePath,
reporterOptions: argv.reporterOptions,
reporterOptionsPath: argv.reporterOptionsPath,
script: argv.script,
Expand Down