From 51b8685a8c5fe39ba5fe1e43a97dbe0bc3ce8244 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 16 Apr 2020 18:09:25 -0700 Subject: [PATCH] feat(testrunner): support `--repeat` CLI flag to repeat tests (#1828) This allows you to run `npm run cunit -- --repeat 10` to run tests multiple times. --- test/test.js | 7 +++++++ utils/testrunner/TestCollector.js | 5 +++++ utils/testrunner/index.js | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/test/test.js b/test/test.js index b12dbe37bc..6e487be325 100644 --- a/test/test.js +++ b/test/test.js @@ -197,6 +197,13 @@ function collect(browserNames) { testRunner.focusMatchingTests(new RegExp(filter, 'i')); } + const repeatArgIndex = process.argv.indexOf('--repeat'); + if (repeatArgIndex !== -1) { + const repeat = parseInt(process.argv[repeatArgIndex + 1], 10); + if (!isNaN(repeat)) + testRunner.repeatAll(repeat); + } + return testRunner; } diff --git a/utils/testrunner/TestCollector.js b/utils/testrunner/TestCollector.js index 434d8cb5ff..3e7b3270a7 100644 --- a/utils/testrunner/TestCollector.js +++ b/utils/testrunner/TestCollector.js @@ -167,6 +167,7 @@ class TestCollector { this._api = {}; this._currentSuite = new Suite(null, '', new Location()); + this._rootSuite = this._currentSuite; this._api.describe = specBuilder(this._suiteModifiers, this._suiteAttributes, (specs, name, suiteCallback, ...suiteArgs) => { const location = Location.getCallerLocation(); @@ -223,6 +224,10 @@ class TestCollector { suites() { return this._suites; } + + rootSuite() { + return this._rootSuite; + } } module.exports = { TestCollector, specBuilder, FocusedFilter, Repeater }; diff --git a/utils/testrunner/index.js b/utils/testrunner/index.js index c757b8660d..fec946e103 100644 --- a/utils/testrunner/index.js +++ b/utils/testrunner/index.js @@ -89,6 +89,10 @@ class DefaultTestRunner { } } + repeatAll(repeatCount) { + this._repeater.repeat(this._collector.rootSuite(), repeatCount); + } + async run() { let reporter = null;