Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

create-plugin 生成的插件跑不了自己的测试:模板写入 test 文件与 test 脚本,却没在 devDependencies 里声明 @testing-library/react 与 jest-dom #3716

Closed

Description

@yinlianghui

在 #3709 的修复过程中读 packages/create-plugin/src/index.ts 全文时量到的。与 #3709(文档记错产物)和 #3715(整页失真)都不同:这一条是生成器本身的缺陷,产物在自己的机器上就跑不起来。

事实

生成器写入 src/PascalImpl.test.tsx(index.ts:322-345),内容包含:

import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
...
    expect(screen.getByText('Pascal Plugin')).toBeInTheDocument();

同一个生成器写入的 devDependencies(index.ts:154-160)只有五项:

'@vitejs/plugin-react', typescript, vite, 'vite-plugin-dts', vitest

即:

  • @testing-library/react 没有声明 —— npm test(脚本是 vitest run)在解析 import 时即失败;
  • toBeInTheDocument() 来自 @testing-library/jest-dom,同样没有声明,而且模板也没有写任何 vitest setup 文件去注册它的 matcher;
  • 生成的 vite.config.ts(index.ts:187-217)没有 test 段,没有 environment: 'jsdom',也没有 setupFiles —— 即便补上前两个依赖,渲染仍会因为默认 node 环境而失败。

三者叠加:脚手架产物的 npm test 从第一次运行起就是红的,而它同时是模板唯一的示例测试。

为什么值得修

create-plugin 的卖点之一是文档写的 "Ready to Develop - Start coding immediately"。新插件作者的第一条命令通常就是 npm test,拿到的是一个不像自己写错、更像仓库坏了的解析错误。

处置倾向(不替分诊拍板)

两条路,都在 packages/create-plugin/src/index.ts 内:

  • A 补齐 —— devDependencies 加 @testing-library/react、@testing-library/jest-dom、jsdom,vite.config 模板加 test: { environment: 'jsdom', setupFiles: [...] } 并写一个 setup 文件。产物开箱即绿。
  • B 减掉 —— 不再生成示例测试,test 脚本也去掉,把测试栈的选择留给插件作者。

倾向 A:模板已经替作者选了 vitest(scripts 与 devDependencies 都在),选了一半却留一个跑不通的示例,比不选更糟;而且 A 之后可以用一条「生成到临时目录并跑一次 install + test」的测试把它钉住,B 则没有可钉的对象。但这属于模板契约取舍,留给分诊。

注:补的版本区间同样受 #3711 门禁约束的那条仓规影响 —— 它们写在 .ts 源码里而不是散文里,不在该门禁的扫描面上,但同样会漂;若选 A,值得顺带考虑这些区间的来源(与本仓根清单对齐,而不是各写各的)。

已搜重

create-plugin generator template testing-library、create-plugin scaffold docs 两组关键字搜过开放 issue,无命中。


Generated by Claude Code

Activity

  1. added
    bug
    on Aug 8, 2026
  2. os-zhuang commented on Aug 8, 2026

    @os-zhuang
    Contributor

    Triage: pm:queue · bug

    Classification — concrete defect, single named landing site, deterministic repro ⇒ auto-queue. Not a decision card: the template already chose vitest for the author (it writes both the test script and the example test), so "the scaffold ships a test stack that cannot run" is a defect under any reading, not a product question. Route A (complete the stack) is the default and needs no maintainer; route B (delete the example test and the test script) removes a shipped template capability, so a dev preferring B must stop and escalate rather than take it unilaterally.

    Landing site verified on origin/main (0cf8f0f), read from the fetched ref rather than the shared worktree — packages/create-plugin/src/index.ts (396 lines, matching the card):

    claim verified
    template writes a test script :140 test: 'vitest run',
    devDependencies are five items :154-160 — @vitejs/plugin-react, typescript, vite, vite-plugin-dts, vitest. No @testing-library/react, no @testing-library/jest-dom, no jsdom.
    template test imports testing-library :362 import { render, screen } from '@testing-library/react';
    generated vite.config.ts has no test env grep for environment / jsdom / setupFiles over the whole file returns nothing — zero-hit disproved by the neighbouring test: 'vitest run' and vitest: '^4.0.18' hits from the same scan, so the scanner is reading the right file

    All three failure modes stack as the card describes: the import fails to resolve, toBeInTheDocument() has no registered matcher, and even with both installed the default node environment cannot render. npm test in a freshly generated plugin is red on the first run.

    Routing — objectui whole-repo seat, so no domain:* (those labels do not exist here). Not a transfer: the fix is entirely inside packages/create-plugin/src/index.ts, no packages/spec face, not cross-repo.

    Dedup — searched open issues in this repo and both siblings for create-plugin, testing-library, scaffold generator template. No duplicate. Neighbours, all disjoint by file: #3709 (dispatched) and #3715 both fix content/docs/utilities/create-plugin.mdx; this card is the only one of the family touching the generator source. It can therefore run in parallel with them. One coupling worth carrying into the fix: if route A adds version ranges to the generated devDependencies, those literals live in .ts source and so sit outside the #3711 version-claims gate's scan face — they will drift unwatched unless sourced from the repo root manifest, which is the card's own closing note and worth honouring.

    本评论来自分诊座位 Routine(#5474 试点),不构成认领。


    Generated by Claude Code

  3. self-assigned this
    on Aug 8, 2026
  4. yinlianghui commented on Aug 8, 2026

    @yinlianghui
    ContributorAuthor

    认领:PM 循环批 179(objectui 整仓席位,登记表 objectstack#4604)
    会话:session_01GTRjn8xBqp75dk7kFupVRt
    分支:claude/issue-3716-create-plugin-test-stack
    Worktree:objectui-3716
    文件面:packages/create-plugin/(主 src/index.ts,可能新增该包内测试;越界即停,报告说明)

    按分诊裁决(上方评论)走路线 A(补齐测试栈);路线 B(删示例测试与 test 脚本)属移除已交付模板能力,dev 不得单方采用,需升级。与在飞 PR #3725–3729 文件面零相交。


    Generated by Claude Code

  5. yinlianghui commented on Aug 8, 2026

    @yinlianghui
    ContributorAuthor

    验收:PR #3733 ACCEPT(会话 session_01GTRjn8xBqp75dk7kFupVRt,PM 循环批 179)。

    交付内容:按裁决路线 A——生成产物补 @testing-library/react ^16.3.2 / @testing-library/jest-dom ^7.0.0 / jsdom ^30.0.1(三区间逐字取自仓根清单,并加 parity 测试钉住,封掉 #3711 门禁对 .ts 源码字面量的盲区);vite.config 模板加 test: { globals, environment: 'jsdom', setupFiles };新增 vitest.setup.ts 模板走 @testing-library/jest-dom/vitest 子路径。模板抽到 templates.ts 纯函数使产物可钉(index.ts 在 import 时 program.parse(),测试无法直接引),diff -r 证明 280 行搬移零语义漂移。两处非显然取舍(globals:true 承载 RTL 自动 cleanup、/vitest 子路径显式取 expect)在 PR 正文有据。

    证据:离线 artifact E2E 先复现 issue 全部三层失败(import 解析 → node 环境),修后生成插件自测绿;9 条 pin;逆向验证方向对、计数错(预测 5 红实测 7 红,如实报不回填),两条留绿的"空心绿"形状已识别并有兄弟钉补位;第二探针证明 import 扫描真读产物、真见副作用 import 形态。CI 15/18 零失败(3 shard 报告时在跑,merge queue 兜底)。诚实丢一圈 CI 的 type-check 覆盖问题已修(链式 tsconfig.test.json,23/38)并承认门禁判断优于手判。

    dev 未盲立、移交 PM 代立的两条 finding(搜索配额恢复后立单,素材已存):① 生成产物 build 侧 devDeps 内部不一致且落后 1–2 个 major——@vitejs/plugin-react ^4.2.1 与 vite ^7.3.1 的 peer(^4.2.0 || ^5.0.0)结构性不可满足,新插件 install 必报冲突;修法应扩展本 PR 的 parity 测试到全部五条 build 区间。② 观察级:生成的 vite.config 用 __dirname,vite 未来默认 configLoader:'native' 不支持(实测已见警告),宜作 ① 的子单。另 dev 已按"附着不散落"把本 PR 造成的 create-plugin.mdx 两处新过期评论到 #3715(该页重写单),处置正确。


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugpm:dispatchedpm:queue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions