Skip to content

[Bug]: Setting up Vitest does not account for configs that do not use defineConfig #33409

@yannbf

Description

@yannbf

Describe the bug

While testing, I noticed that if a Vitest config file looks like this, Storybook initializes correctly with testing features:

import { mergeConfig, defineConfig, coverageConfigDefaults } from 'vitest/config'
import viteConfig from './vite.config'

export default mergeConfig(
  viteConfig,
  defineConfig({
    test: {
      name: 'node',
      environment: 'happy-dom',
    },
  })
)

But when it does not use defineConfig (or a function call) and rather uses just an object:

import { mergeConfig, coverageConfigDefaults } from 'vitest/config'
import viteConfig from './vite.config'

export default mergeConfig(
  viteConfig,
  {
    test: {
      name: 'node',
      environment: 'happy-dom',
    },
  }
)

Then the file will be deemed with a not supported format.

The bug occurs in this specific method:
https://github.com/storybookjs/storybook/blob/next/code/core/src/cli/AddonVitestService.ts#L370

Which is called as part of this method:
https://github.com/storybookjs/storybook/blob/next/code/core/src/cli/AddonVitestService.ts#L331

I tried forcing the function to just return true and the latter logic which modifies the file works as intended, so it's just a matter of fixing the detection.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions