-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp4-importantViolate documented behavior or significantly improves performance (priority)Violate documented behavior or significantly improves performance (priority)
Description
Describe the bug
If a test case will make an unhandled rejection just after one test and before the next test, the cases in the other files will not be tested.
After debugging, there will post a "done" message included all test files. And It will break the next test process.
| channel.postMessage({ |
async function reportUnexpectedError(
type,
error,
) {
const processedError = serializeError(error)
await client.waitForConnection().then(() => {
return client.rpc.onUnhandledError(processedError, type)
}).catch(console.error)
const state = __vitest_browser_runner__
if (state.type === 'orchestrator') {
return
}
// `state.runTests` and `__vitest_worker__.current` will both be `null`
if (!state.runTests || !__vitest_worker__.current) {
channel.postMessage({
type: 'done',
filenames: state.files,
id: state.iframeId,
})
}
}Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-ceqdspje
This issue can also be reproduced by following steps.
mkdirto create a new folder, and npm init.npx vitest init browserto init the test with browser mode.- modify test command in
package.jsonto runvitest run. - make two test files as following.
import { it } from "vitest";
// Import some source file. It's necessary, but I don't know why.
import { add } from "../src/add";
it("should add two numbers", () => {
new Promise((resolve, reject) => {
reject("test");
});
});- run
npm test:browser.
The result will show that only one file is tested.
RUN v2.1.8 /Users/<username>/Developer/vitest-playground
✓ test/add.test.ts (1)
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Unknown Error: test
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Test Files 1 passed (1)
Tests 1 passed (1)
Errors 1 error
Start at 18:22:47
Duration 842ms (transform 0ms, setup 0ms, collect 4ms, tests 1ms, environment 0ms, prepare 191ms)
ELIFECYCLE Command failed with exit code 1.
System Info
System:
OS: macOS 15.2
CPU: (8) arm64 Apple M2
Memory: 111.73 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.15.1 - ~/Library/pnpm/node
npm: 10.7.0 - ~/Library/pnpm/npm
pnpm: 9.15.0 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 131.0.6778.110
Chrome Canary: 133.0.6890.0
Safari: 18.2
npmPackages:
@vitest/browser: ^2.1.8 => 2.1.8
vitest: ^2.1.8 => 2.1.8Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp4-importantViolate documented behavior or significantly improves performance (priority)Violate documented behavior or significantly improves performance (priority)