-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix(runner): async assertion auto await should timeout #6391
Changes from 11 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 |
---|---|---|
|
@@ -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
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 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, 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"); | ||
}) |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,13 @@ | |||||||||||||
|
||||||||||||||
exports[`should fail .dot-folder/dot-test.test.ts > .dot-folder/dot-test.test.ts 1`] = `"AssertionError: expected true to be false // Object.is equality"`; | ||||||||||||||
|
||||||||||||||
exports[`should fail async-assertion.test.ts > async-assertion.test.ts 1`] = ` | ||||||||||||||
"AssertionError: expected 'xx' to be 'zz' // Object.is equality | ||||||||||||||
AssertionError: expected 'xx' to be 'yy' // Object.is equality | ||||||||||||||
AssertionError: expected 'xx' to be 'zz' // Object.is equality | ||||||||||||||
AssertionError: expected 'xx' to be 'yy' // Object.is equality" | ||||||||||||||
`; | ||||||||||||||
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. Errors are doubled since they also treated as unhandled rejections. This is the entire test output: ❯ test/async-assertion.test.ts (1)
× multiple errors
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL test/async-assertion.test.ts > multiple errors
AssertionError: expected 'xx' to be 'yy' // Object.is equality
Expected: "yy"
Received: "xx"
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
FAIL test/async-assertion.test.ts > multiple errors
AssertionError: expected 'xx' to be 'zz' // Object.is equality
Expected: "zz"
Received: "xx"
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest caught 2 unhandled errors during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
AssertionError: expected 'xx' to be 'yy' // Object.is equality
Expected: "yy"
Received: "xx"
❯ ../../packages/expect/dist/index.js:1774:31
❯ processTicksAndRejections node:internal/process/task_queues:95:5
This error originated in "test/async-assertion.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "multiple errors". It might mean one of the following:
- The error was thrown, while Vitest was running this test.
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
AssertionError: expected 'xx' to be 'zz' // Object.is equality
Expected: "zz"
Received: "xx"
❯ ../../packages/expect/dist/index.js:1774:31
This error originated in "test/async-assertion.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "test/async-assertion.test.ts". It might mean one of the following:
- The error was thrown, while Vitest was running this test.
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Test Files 1 failed (1)
Tests 1 failed (1)
Errors 2 errors
Start at 16:50:11
Duration 161ms (transform 19ms, setup 0ms, collect 14ms, tests 11ms, environment 0ms, prepare 37ms) 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. They should be treated as unhandled rejections tho? We are catching them Were they treated as unhandled rejections before? 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. Yeah, this is not ideal but the behavior hasn't changed. It looks like hasn't been tested, so I just added tests. There is a similar test here vitest/test/core/test/jest-expect.test.ts Lines 790 to 795 in 85fb94a
but it turned out this is failing for a different reason:
If I rewrite this test into what's probably intended, then this causes an unhandled rejection so the entire test fails. 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 don't quite understand, but removing |
||||||||||||||
|
||||||||||||||
exports[`should fail concurrent-suite-deadlock.test.ts > concurrent-suite-deadlock.test.ts 1`] = `"Error: Test timed out in 500ms."`; | ||||||||||||||
|
||||||||||||||
exports[`should fail concurrent-test-deadlock.test.ts > concurrent-test-deadlock.test.ts 1`] = `"Error: Test timed out in 500ms."`; | ||||||||||||||
|
@@ -85,7 +92,8 @@ exports[`should fail test-extend/test-rest-props.test.ts > test-extend/test-rest | |||||||||||||
exports[`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"."`; | ||||||||||||||
|
||||||||||||||
exports[`should fail test-timeout.test.ts > test-timeout.test.ts 1`] = ` | ||||||||||||||
"Error: Test timed out in 200ms. | ||||||||||||||
"Error: Test timed out in 20ms. | ||||||||||||||
Error: Test timed out in 200ms. | ||||||||||||||
Error: Test timed out in 100ms. | ||||||||||||||
Error: Test timed out in 10ms." | ||||||||||||||
`; | ||||||||||||||
|
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'm not sure but I needed to add this filter for
fails.test.ts
snapshot sincetest/cli/fixtures/fails/unhandled.test.ts
's stacktrace moved a little and now it points to here