Skip to content

Workaround for vitest v3 projects #65

@adriencaccia

Description

@adriencaccia

Issue

When using Vitest with the projects configuration, the CodSpeed plugin's custom runner is not applied to project-level configurations. This prevents benchmarks from running correctly in the CodSpeed environment.

The root cause is that the projects syntax does not extend the runner configuration from the root vitest.config.ts to individual project configurations.

Workaround

Root Configuration

In your root vitest.config.ts, modify the plugin configuration to disable the global setup:

import codspeedPlugin from "@codspeed/vitest-plugin";
import { defineConfig } from "vitest/config";

export default defineConfig({
  plugins: [
    {
      ...codspeedPlugin(),
      config() {
        // @ts-expect-error
        const normalConfig = codspeedPlugin().config?.();
        normalConfig.test.globalSetup = undefined;
        return normalConfig;
      },
    },
  ],
  test: {
    projects: ["packages/*"],
  },
});

Package-Level Configuration

In each package that defines benchmarks, add a vitest.config.ts:

import codspeedPlugin from "@codspeed/vitest-plugin";
import { defineConfig } from "vitest/config";

export default defineConfig({
  plugins: [codspeedPlugin()],
});

This ensures the CodSpeed runner is properly configured at the package level where benchmarks are defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions