diff --git a/packages/runner/src/suite.ts b/packages/runner/src/suite.ts index 231048970e4f..0ab84ab18d72 100644 --- a/packages/runner/src/suite.ts +++ b/packages/runner/src/suite.ts @@ -67,11 +67,12 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m if (typeof options === 'number') options = { timeout: options } - // inherit repeats and retry from suite + // inherit repeats, retry, timeout from suite if (typeof suiteOptions === 'object') { options = { repeats: suiteOptions.repeats, retry: suiteOptions.retry, + timeout: suiteOptions.timeout, ...options, } } diff --git a/test/core/test/timeout.spec.ts b/test/core/test/timeout.spec.ts new file mode 100644 index 000000000000..321f01ea721b --- /dev/null +++ b/test/core/test/timeout.spec.ts @@ -0,0 +1,17 @@ +import { describe, expect, test } from 'vitest' + +describe('suite timeout', () => { + test('true is true after 5100ms', async () => { + await new Promise(resolve => setTimeout(resolve, 5100)) + expect(true).toBe(true) + }) +}, { + timeout: 6000, +}) + +describe('suite timeout simple input', () => { + test('true is true after 5100ms', async () => { + await new Promise(resolve => setTimeout(resolve, 5100)) + expect(true).toBe(true) + }) +}, 6000) diff --git a/test/fails/fixtures/test-timeout.test.ts b/test/fails/fixtures/test-timeout.test.ts index 8b90a52359ae..f67add79b8b4 100644 --- a/test/fails/fixtures/test-timeout.test.ts +++ b/test/fails/fixtures/test-timeout.test.ts @@ -1,5 +1,19 @@ -import { test } from 'vitest' +import { suite, test } from 'vitest' test('hi', async () => { await new Promise(resolve => setTimeout(resolve, 1000)) }, 10) + +suite('suite timeout', () => { + test('hi', async () => { + await new Promise(resolve => setTimeout(resolve, 500)) + }) +}, { + timeout: 100, +}) + +suite('suite timeout simple input', () => { + test('hi', async () => { + await new Promise(resolve => setTimeout(resolve, 500)) + }) +}, 200) diff --git a/test/fails/test/__snapshots__/runner.test.ts.snap b/test/fails/test/__snapshots__/runner.test.ts.snap index 867a4673307f..ac8c44666374 100644 --- a/test/fails/test/__snapshots__/runner.test.ts.snap +++ b/test/fails/test/__snapshots__/runner.test.ts.snap @@ -36,7 +36,11 @@ TypeError: failure TypeError: failure" `; -exports[`should fail test-timeout.test.ts > test-timeout.test.ts 1`] = `"Error: Test timed out in 10ms."`; +exports[`should fail test-timeout.test.ts > test-timeout.test.ts 1`] = ` +"Error: Test timed out in 200ms. +Error: Test timed out in 100ms. +Error: Test timed out in 10ms." +`; exports[`should fail unhandled.test.ts > unhandled.test.ts 1`] = ` "Error: some error