Skip to content

Proper configuration when using Vite 5 + Vitest 1.x #52

@thedanchez

Description

@thedanchez

Full disclosure, I don't know if this issue belongs here or if it belongs in Vite/Vitest. Please let me know if it should move to one of those other places.

Does anybody have an example vite.config.ts that configures Vitest 1.x properly while using Vite 5? I keep getting the following error which I believe is affecting my tests that are now breaking for a simple Todo app:

stderr | file:/.../node_modules/.pnpm/solid-js@1.8.7/node_modules/solid-js/dist/dev.js:1919:13
You appear to have multiple instances of Solid. This can lead to unexpected behavior.

My current vite.config.ts is the following:

/// <reference types="vitest" />
/// <reference types="vite/client" />

import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';

export default defineConfig({
  plugins: [
    solidPlugin(),
  ],
  server: {
    port: 3000,
  },
  build: {
    target: 'esnext',
  },
  resolve: {
    conditions: ['development', 'browser'],
  },
  test: {
    globals: true,
    environment: 'jsdom',
    setupFiles: ['node_modules/@testing-library/jest-dom/vitest.js'],
    // otherwise, solid would be loaded twice:
    testTransformMode: {
      web: ["/\.[jt]sx?$/"],
    },
    deps: {
      optimizer: {
        web: { enabled: true }, // to replace deps: { registerNodeLoader: true },
      }
    },
    isolate: false,
    pool: "threads",
    poolOptions: {
      threads: {
        maxThreads: 2,
        minThreads: 1,
      }
    },
  },
});

My package.json is the following:

{
  "name": "vite-template-solid",
  "version": "0.0.0",
  "description": "",
  "type": "module",
  "scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview",
    "test": "vitest"
  },
  "license": "MIT",
  "devDependencies": {
    "@solidjs/testing-library": "^0.8.5",
    "@testing-library/jest-dom": "^6.1.5",
    "@types/jsdom": "^21.1.6",
    "@types/testing-library__jest-dom": "^6.0.0",
    "jsdom": "^23.0.1",
    "solid-devtools": "^0.29.2",
    "typescript": "^5.3.3",
    "vite": "^5.0.10",
    "vite-plugin-solid": "^2.8.0",
    "vitest": "^1.1.0"
  },
  "dependencies": {
    "solid-js": "^1.8.7"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions