-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper configuration when using Vite 5 + Vitest 1.x #52
Comments
I made it work with the following dependencies (vite-plugin-solid v.2.8.1 breaks watch mode):
And these settings:
File
File src/vite-env.d.ts:
|
Thanks for sharing that @floratmin! Unfortunately it did not work for me 😭 -- However, I managed to kick the tires a bit and this is what I ended doing recently that got things working: // vite.config.ts
/// <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,
},
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./setupTests.ts'],
testTransformMode: { web: ["/\.[jt]sx?$/"] },
server: {
deps: {
inline: [/solid-js/], // this was what did the trick!
}
}
},
build: {
target: 'esnext',
},
resolve: {
conditions: ['development', 'browser'],
},
}); |
I'm currently fixing the vite-plugin so you should be able to get by without extra configuration in the upcoming version (except for globals, if you use them). |
I've been trying to get past vitest 0.33 for 5 months but get the "multiple instances of Solid" error on 0.34 through 1.2. I've tried exactly replicating these configs along with every other suggestion on the internet but still get this error. If anyone has any ideas please let me know. This is my package.json: {
"type": "module",
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"test": "vitest",
"lint": "eslint src tests --ext .ts,.tsx",
"prettier": "npx prettier src tests --check",
"format": "npm run prettier:fix && npm run lint:fix"
},
"devDependencies": {
"@solidjs/testing-library": "^0.8.5",
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/user-event": "^14.5.2",
"@types/editorjs__header": "^2.6.3",
"@types/google.maps": "^3.54.10",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-solid": "^0.13.1",
"eslint-plugin-tsdoc": "^0.2.17",
"jsdom": "^24.0.0",
"prettier": "^3.2.2",
"typescript": "^5.3.3",
"vite": "^5.0.11",
"vite-plugin-solid": "^2.9.0",
"vitest": "1.2.1"
},
"dependencies": {
"@anshulsanghi/googlemaps-vitest-mocks": "^1.0.1",
"@googlemaps/js-api-loader": "^1.16.2",
"@googlemaps/markerclusterer": "^2.5.2",
"@solid-primitives/script-loader": "^2.1.0",
"@solidjs/router": "^0.10.9",
"@toast-ui/calendar": "^2.1.3",
"@vitest/coverage-v8": "1.2.1",
"bootstrap": "^5.3.2",
"dayjs": "^1.11.10",
"flatpickr": "^4.6.13",
"js-cookie": "^3.0.5",
"moment": "^2.30.1",
"moment-timezone": "^0.5.44",
"npm": "^10.3.0",
"openapi-fetch": "^0.8.2",
"openapi-typescript": "^7.0.0-next.5",
"solid-bootstrap": "^1.0.19",
"solid-icons": "^1.1.0",
"solid-js": "^1.8.11",
"solid-styled-components": "^0.28.5",
"solid-transition-group": "^0.2.3"
}
} and first few lines of a typical vitest output, there's dozens of these warnings and most of the tests fail as a result:
|
This issue is with the vite plugin, not with testing library. Anyways, can you show me your vite(st) configuration? |
My current configuration is: /// <reference types="vitest" />
/// <reference types="vite/client" />
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";
export default defineConfig({
plugins: [solidPlugin()],
server: {
host: true,
port: 3000,
// necessary for loading node_modules in dev container
fs: { allow: ["../../node_modules", "."] },
},
test: {
environment: "jsdom",
globals: true,
transformMode: {
web: [/\.[jt]sx?$/],
},
setupFiles: "./setupVitest.ts",
coverage: {
include: ["src/"],
all: true,
lines: 81.4,
functions: 81.4,
branches: 89,
statements: 81.4,
},
},
resolve: {
conditions: ["development", "browser"],
},
}); I've also tried the configs listed here, as well as the options listed here and here. import "@testing-library/jest-dom/vitest";
import { vi } from "vitest";
process.on("unhandledRejection", (reason) => {
throw reason;
});
const IntersectionObserverMock = vi.fn(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
takeRecords: vi.fn(),
unobserve: vi.fn(),
}));
vi.stubGlobal("IntersectionObserver", IntersectionObserverMock); and I've also tried with just the first line of |
With the newest plugin, you no longer need to manually load jest-dom. Also, transformMode is deprecated. |
I created a minimal reproduction: https://stackblitz.com/edit/vitest-dev-vitest-xs9lkq?file=vite.config.ts. It seems when I remove the |
Can you try to add solid-transition-group to |
Updated, that didn't work. |
Thanks, I'll have a closer look this weekend. |
@atk did you get a chance to look into this? |
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:My current
vite.config.ts
is the following:My
package.json
is the following:The text was updated successfully, but these errors were encountered: