-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Labels
Description
Describe the bug
Currently when inner aroundEach/All throws, outer aroundEach/All also get affected. This means proper outer teardown would require try/catching runTest/Suite. I don't think this is good for composability. Also when outer catches inner, inner error is not reported at all.
Here is an example:
import { test, expect, aroundEach } from 'vitest';
aroundEach(async (runTest) => {
console.log('outer start');
try {
await runTest();
} catch (e) {
console.log('outer caught error', e);
}
console.log('outer end');
});
aroundEach(async (runTest) => {
console.log('inner start');
await runTest();
console.log('inner end');
throw new Error('inner error');
});
test('repro', () => {
console.log('test start');
expect(1).toBe(1);
console.log('test end');
});$ vitest
RUN v4.1.0-beta.3 /home/projects/vitest-dev-vitest-jhjt6dyf
stdout | test/repro.test.ts > repro
🔵 outer start
🟠 inner start
stdout | test/repro.test.ts > repro
🟢 test start
🟢 test end
stdout | test/repro.test.ts > repro
🟠 inner end
stdout | test/repro.test.ts > repro
🔵 outer caught error Error: 🟠 inner error
at /home/projects/vitest-dev-vitest-jhjt6dyf/test/repro.test.ts:17:9
at eval (file:///home/projects/vitest-dev-vitest-jhjt6dyf/node_modules/.pnpm/@pkg.pr.new+vitest-dev+vitest+@vitest@runner@3a2f34c/node_modules/@vitest/runner/dist/index.js:2081:5)
🔵 outer endReproduction
https://stackblitz.com/edit/vitest-dev-vitest-jhjt6dyf?file=test%2Frepro.test.ts
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
vitest: https://pkg.pr.new/vitest@3a2f34c => 4.1.0-beta.3Used 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.
Reactions are currently unavailable