diff --git a/bin/codecept.js b/bin/codecept.js index 5a4752129..8a5d65b20 100755 --- a/bin/codecept.js +++ b/bin/codecept.js @@ -164,6 +164,7 @@ program .option('--tests', 'run only JS test files and skip features') .option('--no-timeouts', 'disable all timeouts') .option('-p, --plugins ', 'enable plugins, comma-separated') + .option('--shuffle', 'Shuffle the order in which test files run') // mocha options .option('--colors', 'force enabling of colors') diff --git a/docs/commands.md b/docs/commands.md index 57bfd523e..c90595641 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -47,6 +47,12 @@ Run single test with steps printed npx codeceptjs run github_test.js --steps ``` +Run test files in shuffled order + +```sh +npx codeceptjs run --shuffle +``` + Run single test in debug mode (see more in [debugging](#Debugging) section) ```sh diff --git a/lib/codecept.js b/lib/codecept.js index 7953b20a0..06752f593 100644 --- a/lib/codecept.js +++ b/lib/codecept.js @@ -1,5 +1,6 @@ const { existsSync, readFileSync } = require('fs') const { globSync } = require('glob') +const shuffle = require('lodash.shuffle') const fsPath = require('path') const { resolve } = require('path') @@ -180,6 +181,10 @@ class Codecept { }) } } + + if (this.opts.shuffle) { + this.testFiles = shuffle(this.testFiles) + } } /** diff --git a/package.json b/package.json index 3aad984ea..4277b9c01 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "joi": "17.13.3", "js-beautify": "1.15.4", "lodash.clonedeep": "4.5.0", + "lodash.shuffle": "4.2.0", "lodash.merge": "4.6.2", "mkdirp": "3.0.1", "mocha": "11.6.0",