diff --git a/packages/runner/src/suite.ts b/packages/runner/src/suite.ts index 15050880ce50..2c8fa8ecfef4 100644 --- a/packages/runner/src/suite.ts +++ b/packages/runner/src/suite.ts @@ -53,7 +53,7 @@ export function createSuiteHooks() { } // implementations -function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, mode: RunMode, concurrent?: boolean, shuffle?: boolean, suiteOptions?: number | TestOptions) { +function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, mode: RunMode, concurrent?: boolean, shuffle?: boolean, suiteOptions?: TestOptions) { const tasks: (Test | TaskCustom | Suite | SuiteCollector)[] = [] const factoryQueue: (Test | Suite | SuiteCollector)[] = [] @@ -61,7 +61,7 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m initSuite() - const test = createTest(function (name: string, fn = noop, options = suiteOptions) { + const test = createTest(function (name: string, fn = noop, options) { const mode = this.only ? 'only' : this.skip ? 'skip' : this.todo ? 'todo' : 'run' if (typeof options === 'number') @@ -70,7 +70,8 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m // inherit repeats and retry from suite if (typeof suiteOptions === 'object') { options = { - ...suiteOptions, + repeats: suiteOptions.repeats, + retry: suiteOptions.retry, ...options, } } @@ -122,6 +123,7 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m type: 'collector', name, mode, + options: suiteOptions, test, tasks, collect, @@ -186,6 +188,16 @@ function createSuite() { function suiteFn(this: Record, name: string, factory?: SuiteFactory, options?: number | TestOptions) { checkVersion() const mode: RunMode = this.only ? 'only' : this.skip ? 'skip' : this.todo ? 'todo' : 'run' + const currentSuite = getCurrentSuite() + + if (typeof options === 'number') + options = { timeout: options } + + if (currentSuite && typeof currentSuite.options?.repeats === 'number') { + // inherit repeats from current suite + options = { repeats: currentSuite.options.repeats, ...options } + } + return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle, options) } diff --git a/packages/runner/src/types/tasks.ts b/packages/runner/src/types/tasks.ts index 5c548d87240d..194189ba60e2 100644 --- a/packages/runner/src/types/tasks.ts +++ b/packages/runner/src/types/tasks.ts @@ -168,9 +168,11 @@ export interface TestOptions { */ retry?: number /** - * How many times the test will repeat. + * How many times the test will run. + * Only inner tests will repeat if set on `describe()`, nested `describe()` will inherit parent's repeat by default. + * + * @default 1 * - * @default 5 */ repeats?: number } @@ -211,6 +213,7 @@ export interface SuiteHooks { export interface SuiteCollector { readonly name: string readonly mode: RunMode + options?: TestOptions type: 'collector' test: TestAPI tasks: (Suite | TaskCustom | Test | SuiteCollector)[] diff --git a/test/core/test/repeats.test.ts b/test/core/test/repeats.test.ts index 7542ceada924..711319440bab 100644 --- a/test/core/test/repeats.test.ts +++ b/test/core/test/repeats.test.ts @@ -48,3 +48,33 @@ describe('testing repeats with retry', () => { expect(retryNumbers).toStrictEqual(result) }) }) + +const nestedDescribeNumbers: number[] = [] + +describe('testing nested describe', () => { + test ('test 1', () => { + nestedDescribeNumbers.push(1) + }) + + describe('nested 1', () => { + test('test 2', () => { + nestedDescribeNumbers.push(2) + }) + + describe('nested 2', () => { + test('test 3', () => { + nestedDescribeNumbers.push(3) + }) + + describe('nested 3', () => { + test('test 4', () => { + nestedDescribeNumbers.push(4) + }) + }, 100) + }, { repeats: 3 }) + }) + + afterAll(() => { + expect(nestedDescribeNumbers).toStrictEqual([1, 1, 2, 2, 3, 3, 3, 4, 4, 4]) + }) +}, { repeats: 2 })