Skip to content

[Bug]: vitest fails on geting the config dir in Windows #34407

@SalahAdDin

Description

@SalahAdDin

Describe the bug

When we try to run the tests, it breaks with the following issue:

dirname: G:\Projects\sites\central-mosque-bogota\frontend G:\Projects\sites\central-mosque-bogota\frontend G:\Projects\sites\central-mosque-bogota\frontend\.storybook
│
▲  No story files found for the specified pattern: src\**\*.mdx
dirname: G:\Projects\sites\central-mosque-bogota\frontend G:\Projects\sites\central-mosque-bogota\frontend G:\Projects\sites\central-mosque-bogota\frontend\.storybook
dirname: G:\Projects\sites\central-mosque-bogota\frontend G:\Projects\sites\central-mosque-bogota\frontend G:\Projects\sites\central-mosque-bogota\frontend\.storybook

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
AggregateError: Failed to initialize projects. There were errors during projects setup. See below for more details.
    at resolveProjects (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:11147:27)
    at Vitest._setServer (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:13128:20)
    at BasicMinimalPluginContext.handler (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:14127:5)
    at _createServer (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vite@7.3.1_@types+node@25.5_d593e592f2c5ffb07d977b636d83184a/node_modules/vite/dist/node/chunks/config.js:25603:86)
    at createViteServer (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:8820:17)
    at createVitest (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:14161:18)
    at prepareVitest (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:14528:14)
    at startVitest (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:14471:14)
    at start (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cac.DRKYQDPl.js:2328:15) {
  [errors]: [
    TypeError: The URL must be of scheme file
        at fileURLToPath (node:internal/url:1608:11)
        at file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/@storybook+addon-vitest@10._5bf1baf61ad87163f31bfb8f4422c6f7/node_modules/@storybook/addon-vitest/dist/vitest-plugin/index.js:2526:43
        at Array.map (<anonymous>)
        at BasicMinimalPluginContext.config (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/@storybook+addon-vitest@10._5bf1baf61ad87163f31bfb8f4422c6f7/node_modules/@storybook/addon-vitest/dist/vitest-plugin/index.js:2526:25)
        at runConfigHook (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vite@7.3.1_@types+node@25.5_d593e592f2c5ffb07d977b636d83184a/node_modules/vite/dist/node/chunks/config.js:35936:15)
        at resolveConfig (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vite@7.3.1_@types+node@25.5_d593e592f2c5ffb07d977b636d83184a/node_modules/vite/dist/node/chunks/config.js:35438:13)
        at _createServer (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vite@7.3.1_@types+node@25.5_d593e592f2c5ffb07d977b636d83184a/node_modules/vite/dist/node/chunks/config.js:25362:67)
        at createViteServer (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:8820:17)
        at initializeProject (file:///G:/Projects/sites/central-mosque-bogota/frontend/node_modules/.pnpm/vitest@4.1.2_@types+node@25_b9542e0439b0b4b9512483fb4c3e3fec/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:11033:2)
        at async Promise.allSettled (index 1) {
      code: 'ERR_INVALID_URL_SCHEME'
    }
  ]
}

We have the following test configuration:

import { storybookTest } from "@storybook/addon-vitest/vitest-plugin";
import { playwright } from "@vitest/browser-playwright";
import { getViteConfig } from "astro/config";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { coverageConfigDefaults } from "vitest/config";

const dirname =
  typeof __dirname !== "undefined"
    ? __dirname
    : path.dirname(fileURLToPath(import.meta.url));

export default getViteConfig({
  build: {
    rollupOptions: {
      output: {
        banner:
          "/* ﷽ - In the name of Allah, the Most Gracious, the Most Merciful */",
      },
    },
  },
  test: {
    globals: true,
    css: true,
    clearMocks: true,
    restoreMocks: true,
    passWithNoTests: true,
    coverage: {
      exclude: [...coverageConfigDefaults.exclude],
      provider: "v8",
      reporter: ["html", "verbose"],
      thresholds: {
        branches: 90,
        functions: 95,
        lines: 80,
        statements: 80,
      },
    },
    projects: [
      {
        extends: true,
        test: {
          name: "unit",
          include: ["src/**/*.{test,spec}.{astro,js,jsx,ts,tsx}"],
          exclude: ["tests"],
          environment: "node",
          setupFiles: ["./src/vitest.setup.ts"],
        },
      },
      {
        extends: true,
        plugins: [
          storybookTest({
            configDir: path.join(dirname, ".storybook"),
            storybookScript: "pnpm storybook --no-open",
          }),
        ],
        test: {
          name: "storybook",
          browser: {
            enabled: true,
            headless: true,
            provider: playwright({}),
            instances: [
              {
                browser: "chromium",
              },
            ],
          },
        },
      },
    ],
  },
});

As you see in the logs, __dirname is defined, as well as the config directory, but vitest fails to run cause in this addon fails, and it seems to happen on Windows.

Reproduction link

https://github.com/SalahAdDin/central-mosque-bogota/tree/main/frontend

Reproduction steps

  1. Set up the project.
  2. Configure the tests with Vitest.
  3. Install Storybook.
  4. Configure it.
  5. Install the Vitest addon.
  6. Add addon configuration to the tests.
  7. Run the tests.

System

│
│  
│  Storybook Environment Info:
│

│  System:
│  OS: Windows 11 10.0.26200
│  CPU: (32) x64 Intel(R) Core(TM) i9-14900HX
│  Binaries:
│  Node: 24.13.1 -
│  C:\Users\alagu\AppData\Local\fnm_multishells\69064_1774906487606\node.EXE
│  npm: 11.8.0 -
│  C:\Users\alagu\AppData\Local\fnm_multishells\69064_1774906487606\npm.CMD
│  pnpm: 10.33.0 -
│  C:\Users\alagu\AppData\Local\fnm_multishells\69064_1774906487606\pnpm.CMD <-----
│  active
│  Browsers:
│  Edge: Chromium (140.0.3485.54)
│  npmPackages:
│  @storybook/addon-a11y: 10.3.3 => 10.3.3
│  @storybook/addon-designs: 11.1.3 => 11.1.3
│  @storybook/addon-docs: 10.3.3 => 10.3.3
│  @storybook/addon-themes: 10.3.3 => 10.3.3
│  @storybook/addon-vitest: 10.3.3 => 10.3.3
│  @storybook/builder-vite: 10.3.3 => 10.3.3
│  eslint-plugin-storybook: 10.3.3 => 10.3.3
│  storybook: 10.3.3 => 10.3.3
│  storybook-addon-rtl: 3.0.1 => 3.0.1
│  storybook-addon-tag-badges: 3.1.0 => 3.1.0

Additional context

We are using Storybook in an Astro project.

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