Skip to content

Commit

Permalink
Merge pull request #80 from tnicola/feat/adding-strict-mode
Browse files Browse the repository at this point in the history
feat: adding strict mode
  • Loading branch information
tnicola authored Jan 24, 2022
2 parents 497ce3d + 512738a commit 1f993c9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 26 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ Sample:
npm run cy:parallel
```

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>\"'
```

### Scripts options

| Option | Alias | Description | Type |
Expand All @@ -73,6 +81,17 @@ npm run cy:parallel
| --reporterOptions | -o | Reporter options | 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:

```typescript
"scripts" :{
...
"cy:parallel" : "cypress-parallel -s cy:run -t 4 -m false"
...
}
```

# Contributors

Expand Down
81 changes: 58 additions & 23 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
[![npm version](https://badge.fury.io/js/cypress-parallel.svg)](https://badge.fury.io/js/cypress-parallel)

# cypress-parallel

Reduce up to 40% your Cypress suite execution time parallelizing the test run on the same machine.

# Run your Cypress test in parallel (locally)

| cypress | cypress-parallel |
| :-----------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------: |
| ![cy-serial-small](https://user-images.githubusercontent.com/38537547/114301114-92600a80-9ac3-11eb-9166-e95ae9cd5178.gif) | ![cy-parallel_small](https://user-images.githubusercontent.com/38537547/114301127-9db33600-9ac3-11eb-9bfc-c2096023bba7.gif) |

# Run your Cypress tests in parallel (locally)

## How it works

🔍 - Search for existing Cypress tests\
📄 - Read (if exists) a weight file\
⚖️ - Split spec files into different threads\
Expand All @@ -14,27 +21,29 @@ Reduce up to 40% your Cypress suite execution time parallelizing the test run on
# How to use

## Install
```
npm i cypress-parallel
```

or
```
npm i cypress-parallel
```

or

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

## Add a new script
In your `package.json` add a new script:

```typescript
In your `package.json` add a new script:

```typescript
"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: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>\"'"
...
}
```
```

### With Arguments

Expand All @@ -50,18 +59,44 @@ Sample:
npm run cy:parallel
```

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>\"'
```

### 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 |
| 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 |
| --reporter | -r | Reporter to pass to Cypress. | string |
| --reporterOptions | -o | Reporter options | 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:

```typescript
"scripts" :{
...
"cy:parallel" : "cypress-parallel -s cy:run -t 4 -m false"
...
}
```

# Contributors

Looking for contributors.

# License
MIT

MIT
3 changes: 2 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Table = require('cli-table3');
const colors = require('colors/safe');
const path = require('path');
const fs = require('fs-extra');
const { settings } = require('./settings');

const { getTestSuitePaths, distributeTestsByWeight } = require('./test-suites');
const {
Expand Down Expand Up @@ -86,7 +87,7 @@ async function start() {
console.log(table.toString());

// fail on missing results (had some issues with missing test results, prevent that from slipping past again)
if (timeMap.size !== testSuitePaths.length) {
if (settings.strictMode && timeMap.size !== testSuitePaths.length) {
console.error(`Found test suites does not match results.`);
console.error(`Test suites found: ${testSuitePaths.length}`);
console.error(`Test suite results: ${timeMap.size}`);
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cypress-parallel",
"version": "0.8.3",
"version": "0.8.4",
"description": "Reduce up to 40% your Cypress suite execution time parallelizing the test run on the same machine.",
"main": "cli.js",
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const argv = yargs
alias: 'p',
type: 'string',
description: 'Reporter options path'
})
.option('strictMode', {
alias: 'm',
type: 'boolean',
default: true,
description: 'Strict mode checks'
}).argv;

if (!argv.script) {
Expand Down Expand Up @@ -73,6 +79,7 @@ const settings = {
reporterOptions: argv.reporterOptions,
reporterOptionsPath: argv.reporterOptionsPath,
script: argv.script,
strictMode: argv.strictMode,
scriptArguments: argv.args ? argv.args.split(' ') : []
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "npm start --prefix demo-app",
"cy:open": "cypress open",
"cy:run": "cypress run --browser chrome --headless",
"cy:parallel": "node_modules/.bin/cypress-parallel -s cy:run -t 4 -d 'cypress/integration/1/*.js'",
"cy:parallel": "node_modules/.bin/cypress-parallel -s cy:run -t 4 -d 'cypress/integration/1/*.js' -m false",
"cy:parallel:many": "node_modules/.bin/cypress-parallel -s cy:run -t 8 -d 'cypress/integration/**/*.js'",
"cy:parallel:spec": "node_modules/.bin/cypress-parallel -s cy:run -t 2 -d cypress/integration/1 -r spec",
"cy:parallel:junit": "node_modules/.bin/cypress-parallel -s cy:run -t 2 -d cypress/integration/1 -r mocha-junit-reporter -o 'mochaFile=demo-app/reporting/junit/e2e-junit-[hash].xml'",
Expand Down

0 comments on commit 1f993c9

Please sign in to comment.