solidjs / solidjs/solid-vite-plugin

@solidjs/testing-library resolves @solidjs/web to the server build (isServer true) in jsdom tests under a multi-project vitest setup

Đang mở
#369 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
TypeScript
Star
520
Fork
70
Merge trung bình
23 giờ 35 phút
Pull request đã merge (30 ngày)
39

Mô tả

Environment

  • @solidjs/vite-plugin 3.0.0-next.44
  • vitest 5.0.1, multi-project (projects), pool: threads, isolate: false
  • solid-js / @solidjs/web 2.0.0-rc.9
  • @solidjs/testing-library 1.0.0-beta.3

Reproduction

A vitest config with two projects, one jsdom ("client") and one node ("server"):

test: {
  projects: [
    { test: { name: "client", environment: "jsdom", include: ["src/**/*.test.tsx"] } },
    { test: { name: "server", environment: "node", include: ["src/server/**/*.test.ts"] } },
  ],
}

In a test file, import { isServer } from "@solidjs/web" is false (correct browser build). But inside @solidjs/testing-library's render, @solidjs/web is the server build (isServer === true), so render/hydrate behave incorrectly.

Root cause

In the client/jsdom test posture the plugin injects browser into resolve.conditions (fixing inlined modules) but leaves @solidjs/web and @solidjs/testing-library externalized — and explicitly externalizes solid-js via test.server.deps.external: [/solid-js/]. Externalized modules are executed natively by Node, whose resolution conditions are ['node', 'import', 'default'] (no browser). So @solidjs/testing-library's own import { render, hydrate } from "@solidjs/web" resolves the node export (dist/server.js).

The plugin already handles the inverse case for the node/server posture by inlining /solid-js/ + /@solidjs[+/]web/, but the client posture gets no equivalent treatment.

Workaround

Inline the runtime packages so their imports resolve through Vite's browser condition:

test: {
  server: {
    deps: {
      inline: ["solid-js", "@solidjs/web", "@solidjs/testing-library"],
    },
  },
}

(deps.inline takes precedence over deps.external.)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với việc xử lý dependency của plugin cho biến thể node/server và so sánh với đường dẫn client/jsdom được mô tả trong issue. Tái hiện thiết lập multi-project của Vitest, sau đó xác minh rằng render và hydrate resolve browser build mà không cần workaround.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
node.js, typescript, vite
Lĩnh vực
build-system, testing-qa
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
68/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.