-
Notifications
You must be signed in to change notification settings - Fork 9k
Description
Describe the bug
Vitest reports an “Unhandled Errors” warning for a test that intentionally throws an error ("should throw error for non-existent entity").
The test itself passes correctly using .rejects.toThrow(), but Vitest incorrectly surfaces the expected rejection as an unhandled error.
This causes the TypeScript / Test memory CI job to fail even though there is no bug in the memory server implementation.
To Reproduce
Steps to reproduce the behavior:
Run the memory server tests using:
pnpm test:memory
Look for the test:
"should throw error for non-existent entity"
Observe that the test passes but Vitest outputs an “Unhandled Errors” warning.
In GitHub Actions, this warning results in a failing test job.
Expected behavior
Vitest should correctly treat .rejects.toThrow() as a handled and expected error, and should not report the intentionally thrown error as an unhandled rejection.
CI should pass when the test succeeds, without false-positive warnings.
Logs
Example output:
Unhandled Errors:
❯ Error: Entity does not exist
at ...
The test reports PASS
The warning appears only in the "Unhandled Errors" summary
No runtime errors or implementation failures occur
Additional context
This behavior is a Vitest testing quirk, not a bug in the memory server code.
All locking, file serialization, and race condition tests pass successfully.
The new lock implementation is functioning as expected.
The false warning appears because Vitest sometimes logs expected async errors as “unhandled” even when wrapped in .rejects.toThrow().
Possible mitigations (optional):
Rewrite the test using assert.rejects(...)
Wrap error tests to avoid Vitest’s unhandled rejection reporting
Add scoped process.on("unhandledRejection", () => {}); for this file (not recommended except for CI cleanliness)
If you want, I can also rewrite the test file for a clean CI run.