Skip to content

Commit

Permalink
fix(runner): suite timeout does not take effect (#3455)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed May 30, 2023
1 parent 1988fcb commit 8254737
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/runner/src/suite.ts
Expand Up @@ -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,
}
}
Expand Down
17 changes: 17 additions & 0 deletions 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)
16 changes: 15 additions & 1 deletion 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)
6 changes: 5 additions & 1 deletion test/fails/test/__snapshots__/runner.test.ts.snap
Expand Up @@ -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
Expand Down

0 comments on commit 8254737

Please sign in to comment.