Skip to content

test.override not affecting fixtures used by auto fixtures #9810

@AriPerkkio

Description

@AriPerkkio

Describe the bug

There's no way to override fixtures that are used by auto fixtures. Code below keeps throwing Config missing. Note that this condition also requires setupFile to be there.

import { test as baseTest, describe } from 'vitest';

const test = baseTest
  .extend('config', (): undefined | {port: number, host: string} => undefined)
  .extend('server', { auto: true }, ({ config }) => {
    console.log({config})

    if (!config) {
      throw new Error('Missing config');
    }

    return `http://${config.host}:${config.port}`;
  });

describe('production environment', () => {
  test.override('config', { port: 8080, host: 'api.example.com' });

  test('uses production config', () => {});
});
import { beforeEach } from 'vitest';

beforeEach(({ task }) => {
    console.log(task.id)
});

Repro uses new builder pattern, but same issue happens with old pattern too.

Reproduction

https://stackblitz.com/~/edit/vitest-dev-vitest-ildnktb3?file=basic.test.ts&initialPath=/__vitest__/

System Info

Stackblitz, `vitest@4.1.0-beta.5`

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: contextp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions