From 512738a793d57151907dfd7b2095b4d4565f2306 Mon Sep 17 00:00:00 2001 From: Nicola Tommasi Date: Mon, 24 Jan 2022 10:32:44 +0100 Subject: [PATCH] feat: adding strict mode --- README.md | 19 ++++++++++++ lib/README.md | 81 ++++++++++++++++++++++++++++++++++-------------- lib/cli.js | 3 +- lib/package.json | 2 +- lib/settings.js | 7 +++++ package.json | 2 +- 6 files changed, 88 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index fa59f4b..a062a04 100644 --- a/README.md +++ b/README.md @@ -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 -a '\"\"' +``` + ### Scripts options | Option | Alias | Description | Type | @@ -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 diff --git a/lib/README.md b/lib/README.md index 65fdf71..a062a04 100644 --- a/lib/README.md +++ b/lib/README.md @@ -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\ @@ -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 -a '\"\"'" - ... + ... + "cy:run": "cypress run", // It can be any cypress command with any argument + "cy:parallel" : "cypress-parallel -s cy:run -t 2 -d -a '\"\"'" + ... } - ``` +``` ### With Arguments @@ -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 -a '\"\"' +``` + ### 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 diff --git a/lib/cli.js b/lib/cli.js index 14ce890..2a65d20 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -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 { @@ -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}`); diff --git a/lib/package.json b/lib/package.json index 71aea24..11ce3d8 100644 --- a/lib/package.json +++ b/lib/package.json @@ -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": { diff --git a/lib/settings.js b/lib/settings.js index b78ae65..bca512c 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -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) { @@ -73,6 +79,7 @@ const settings = { reporterOptions: argv.reporterOptions, reporterOptionsPath: argv.reporterOptionsPath, script: argv.script, + strictMode: argv.strictMode, scriptArguments: argv.args ? argv.args.split(' ') : [] }; diff --git a/package.json b/package.json index 9d3501a..125a0ce 100644 --- a/package.json +++ b/package.json @@ -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'",