···41414242 const { setTimeout, clearTimeout } = getSafeTimers()
43434444- return ((...args: T extends (...args: infer A) => any ? A : never) => {
4444+ // this function name is used to filter error in test/cli/test/fails.test.ts
4545+ return (function runWithTimeout(...args: T extends (...args: infer A) => any ? A : never) {
4546 return Promise.race([
4647 fn(...args),
4748 new Promise((resolve, reject) => {
-10
packages/runner/src/run.ts
···224224 }
225225 await fn()
226226 }
227227- // some async expect will be added to this array, in case user forget to await theme
228228- if (test.promises) {
229229- const result = await Promise.allSettled(test.promises)
230230- const errors = result
231231- .map(r => (r.status === 'rejected' ? r.reason : undefined))
232232- .filter(Boolean)
233233- if (errors.length) {
234234- throw errors
235235- }
236236- }
237227238228 await runner.onAfterTryTask?.(test, {
239229 retry: retryCount,
+18-1
packages/runner/src/suite.ts
···2020 SuiteHooks,
2121 Task,
2222 TaskCustomOptions,
2323+ TaskPopulated,
2324 Test,
2425 TestAPI,
2526 TestFunction,
···346347 setFn(
347348 task,
348349 withTimeout(
349349- withFixtures(handler, context),
350350+ withAwaitAsyncAssetions(withFixtures(handler, context), task),
350351 options?.timeout ?? runner.config.testTimeout,
351352 ),
352353 )
···479480480481 collectTask(collector)
481482 return collector
483483+}
484484+485485+function withAwaitAsyncAssetions<T extends (...args: any[]) => any>(fn: T, task: TaskPopulated): T {
486486+ return (async (...args: any[]) => {
487487+ await fn(...args)
488488+ // some async expect will be added to this array, in case user forget to await them
489489+ if (task.promises) {
490490+ const result = await Promise.allSettled(task.promises)
491491+ const errors = result
492492+ .map(r => (r.status === 'rejected' ? r.reason : undefined))
493493+ .filter(Boolean)
494494+ if (errors.length) {
495495+ throw errors
496496+ }
497497+ }
498498+ }) as T
482499}
483500484501function createSuite() {
···11-import { suite, test } from 'vitest'
11+import { expect, suite, test } from 'vitest'
2233test('hi', async () => {
44 await new Promise(resolve => setTimeout(resolve, 1000))
···1717 await new Promise(resolve => setTimeout(resolve, 500))
1818 })
1919}, 200)
2020+2121+test('auto await async assertion', { timeout: 20 }, () => {
2222+ expect(new Promise(() => {})).resolves.toBe(0)
2323+})
+7-1
test/cli/test/__snapshots__/fails.test.ts.snap
···2233exports[`should fail .dot-folder/dot-test.test.ts > .dot-folder/dot-test.test.ts 1`] = `"AssertionError: expected true to be false // Object.is equality"`;
4455+exports[`should fail async-assertion.test.ts > async-assertion.test.ts 1`] = `
66+"AssertionError: expected 'xx' to be 'zz' // Object.is equality
77+AssertionError: expected 'xx' to be 'yy' // Object.is equality"
88+`;
99+510exports[`should fail concurrent-suite-deadlock.test.ts > concurrent-suite-deadlock.test.ts 1`] = `"Error: Test timed out in 500ms."`;
611712exports[`should fail concurrent-test-deadlock.test.ts > concurrent-test-deadlock.test.ts 1`] = `"Error: Test timed out in 500ms."`;
···8590exports[`should fail test-extend/test-without-destructuring.test.ts > test-extend/test-without-destructuring.test.ts 1`] = `"Error: The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "context"."`;
86918792exports[`should fail test-timeout.test.ts > test-timeout.test.ts 1`] = `
8888-"Error: Test timed out in 200ms.
9393+"Error: Test timed out in 20ms.
9494+Error: Test timed out in 200ms.
8995Error: Test timed out in 100ms.
9096Error: Test timed out in 10ms."
9197`;