-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(runner): async assertion auto await should timeout #6391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f48a02c
6722c0a
3e89020
c8e96fd
029edf4
6f68621
ae99539
6b41abd
e18261c
ff8a67b
13ed041
ed3a95b
e7d5597
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,8 @@ export function withTimeout<T extends (...args: any[]) => any>( | |
|
|
||
| const { setTimeout, clearTimeout } = getSafeTimers() | ||
|
|
||
| return ((...args: T extends (...args: infer A) => any ? A : never) => { | ||
| // this function name is used to filter error in test/cli/test/fails.test.ts | ||
| return (function runWithTimeout(...args: T extends (...args: infer A) => any ? A : never) { | ||
|
Comment on lines
+44
to
+45
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure but I needed to add this filter for stderr | unhandled.test.ts > unhandled exception
Error: Uncaught [Error: some error]
...
at file:///home/hiroshi/code/others/vitest/packages/runner/dist/index.js:146:14
at file:///home/hiroshi/code/others/vitest/packages/runner/dist/index.js:529:11
at runWithTimeout (file:///home/hiroshi/code/others/vitest/packages/runner/dist/index.js:61:7) Error: some error
at /home/hiroshi/code/others/vitest/test/cli/fixtures/fails/unhandled.test.ts:8:11
... |
||
| return Promise.race([ | ||
| fn(...args), | ||
| new Promise((resolve, reject) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,16 +224,6 @@ export async function runTest(test: Test | Custom, runner: VitestRunner): Promis | |
| } | ||
| await fn() | ||
| } | ||
| // some async expect will be added to this array, in case user forget to await theme | ||
| if (test.promises) { | ||
| const result = await Promise.allSettled(test.promises) | ||
| const errors = result | ||
| .map(r => (r.status === 'rejected' ? r.reason : undefined)) | ||
| .filter(Boolean) | ||
| if (errors.length) { | ||
| throw errors | ||
| } | ||
|
Comment on lines
-229
to
-235
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously it was waiting for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I copied |
||
| } | ||
|
|
||
| await runner.onAfterTryTask?.(test, { | ||
| retry: retryCount, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { test, expect } from "vitest" | ||
|
|
||
| test('multiple errors', () => { | ||
| expect(new Promise((r) => r("xx"))).resolves.toBe("yy"); | ||
| expect(new Promise((r) => setTimeout(() => r("xx"), 10))).resolves.toBe("zz"); | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand now. When returning promise from
async () => { return somePromise }andsomePromiserejects, even if we handle rejections ofsomePromise(e.g. bysomePromise.catchorPromise.allSettlled([somePromise]),somePromiserejection still leaks to the promise returned fromasyncfunction calls.