diff --git a/packages/runner/src/fixture.ts b/packages/runner/src/fixture.ts index 2a710dcda4c7..d85cd6e3fbd7 100644 --- a/packages/runner/src/fixture.ts +++ b/packages/runner/src/fixture.ts @@ -118,7 +118,7 @@ export function withFixtures(fn: Function, testContext?: TestContext) { return isFn ? value(context, use) : use(value) } - const setupFixturePromise = next() + const setupFixturePromise = next().catch(reject) cleanupFnArray.unshift(() => setupFixturePromise) }) } diff --git a/test/fails/fixtures/test-extend/fixture-error.test.ts b/test/fails/fixtures/test-extend/fixture-error.test.ts new file mode 100644 index 000000000000..70fd35d436c6 --- /dev/null +++ b/test/fails/fixtures/test-extend/fixture-error.test.ts @@ -0,0 +1,40 @@ +import { afterEach, beforeEach, describe, expectTypeOf, test } from 'vitest' + +describe('error thrown in beforeEach fixtures', () => { + const myTest = test.extend<{ a: never }>({ + a: async () => { + throw new Error('Error thrown in beforeEach fixture') + }, + }) + + // eslint-disable-next-line unused-imports/no-unused-vars + beforeEach<{ a: never }>(({ a }) => {}) + + myTest('error is handled', () => {}) +}) + +describe('error thrown in afterEach fixtures', () => { + const myTest = test.extend<{ a: never }>({ + a: async () => { + throw new Error('Error thrown in afterEach fixture') + }, + }) + + // eslint-disable-next-line unused-imports/no-unused-vars + afterEach<{ a: never }>(({ a }) => {}) + + myTest('fixture errors', () => { + expectTypeOf(1).toEqualTypeOf() + }) +}) + +describe('error thrown in test fixtures', () => { + const myTest = test.extend<{ a: never }>({ + a: async () => { + throw new Error('Error thrown in test fixture') + }, + }) + + // eslint-disable-next-line unused-imports/no-unused-vars + myTest('fixture errors', ({ a }) => {}) +}) diff --git a/test/fails/test/__snapshots__/runner.test.ts.snap b/test/fails/test/__snapshots__/runner.test.ts.snap index ef329d02b91b..7c060bad49dc 100644 --- a/test/fails/test/__snapshots__/runner.test.ts.snap +++ b/test/fails/test/__snapshots__/runner.test.ts.snap @@ -42,6 +42,12 @@ TypeError: failure" exports[`should fail test-extend/circular-dependency.test.ts > test-extend/circular-dependency.test.ts 1`] = `"Error: circular fixture dependency"`; +exports[`should fail test-extend/fixture-error.test.ts > test-extend/fixture-error.test.ts 1`] = ` +"Error: Error thrown in test fixture +Error: Error thrown in afterEach fixture +Error: Error thrown in beforeEach fixture" +`; + exports[`should fail test-extend/fixture-rest-params.test.ts > test-extend/fixture-rest-params.test.ts 1`] = `"Error: the first argument must use object destructuring pattern"`; exports[`should fail test-extend/fixture-rest-props.test.ts > test-extend/fixture-rest-props.test.ts 1`] = `"Error: Rest parameters are not supported"`;