@linkdesk/plugin-docs 0.1.30 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -254,6 +254,25 @@ Step one: your `.linkdesk-plugin` asset shows up on the GitHub Release. Step two
|
|
|
254
254
|
|
|
255
255
|
---
|
|
256
256
|
|
|
257
|
+
## Tests in a plugin repo
|
|
258
|
+
|
|
259
|
+
Nothing to set up — but "should I test this?" deserves a straight answer.
|
|
260
|
+
|
|
261
|
+
- **The toolchain is preinstalled.** `vitest` / `jsdom` / `@testing-library/react` are already in `devDependencies` — write `src/__tests__/<same-name>.test.ts` and run `npm run test`.
|
|
262
|
+
- **The shared test ground comes from the SDK.** The minimal `window.linkdesk` mock lives in `@linkdesk/plugin-sdk/vitest-setup`, and your `vitest.setup.ts` is a **one-line pointer** to it. ⛔ **Do not paste a second copy into your repo** — a copied mock silently drifts from the shared one.
|
|
263
|
+
- **Pure logic is what pays off.** A unit under `src/**/*.ts` that touches neither React nor `window.linkdesk` should get a test. Views and interactions are worth testing **when it pays off** — nothing measures that today.
|
|
264
|
+
- **Plugin-specific stubs stay in your own test files.** Does your code call something the shared mock does not cover (say `window.linkdesk.serial`)? Stub it with `vi.fn()` in the test that needs it — do not expect the shared mock to grow a branch for your plugin.
|
|
265
|
+
- **Declarative plugins** (pure JSON / themes / language packs) have **no testable units** — their gate is `npm run verify` (structure + declarations). **"It has no tests" is not a defect there.**
|
|
266
|
+
- **Older projects can migrate whenever they like.** Replacing the full mock body with the one-line pointer plus one `npm install` is the whole move (upside: mock upgrades then ride along with the SDK).
|
|
267
|
+
|
|
268
|
+
**How to know you did it right**
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
npm run test # vitest run — an empty suite passes on purpose (passWithNoTests)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
257
276
|
## Pitfalls Beginners Hit Most
|
|
258
277
|
|
|
259
278
|
| Symptom | Root cause | Where to look |
|
|
@@ -281,4 +300,5 @@ Step one: your `.linkdesk-plugin` asset shows up on the GitHub Release. Step two
|
|
|
281
300
|
| A whole **replacement settings UI** | [10-building-a-settings-plugin](10-building-a-settings-plugin.md) |
|
|
282
301
|
| Build **themes/icons** | [11-authoring-themes](11-authoring-themes.md) |
|
|
283
302
|
| **Where files should go**; authoritative README/CHANGELOG criteria | [09-plugin-directory-layout](09-plugin-directory-layout.md) |
|
|
303
|
+
| Decide **whether / how to test my plugin** | [§ Tests in a plugin repo](#tests-in-a-plugin-repo) |
|
|
284
304
|
| The full documentation index | [00-readme §Documentation Index](00-readme.md#documentation-index) |
|
package/docs/zh/13-/346/217/222/344/273/266/345/274/200/345/217/221/346/214/207/345/215/227.md
CHANGED
|
@@ -254,6 +254,25 @@ env:
|
|
|
254
254
|
|
|
255
255
|
---
|
|
256
256
|
|
|
257
|
+
## 插件仓里的测试怎么写
|
|
258
|
+
|
|
259
|
+
不用配任何东西——但「这段该不该测」值得一个直给的回答。
|
|
260
|
+
|
|
261
|
+
- **工具链已预装**:`vitest` / `jsdom` / `@testing-library/react` 都在 `devDependencies` 里,写 `src/__tests__/<同名>.test.ts`,然后 `npm run test`。
|
|
262
|
+
- **共享测试地基由 SDK 提供**:`window.linkdesk` 的最小 mock 住在 `@linkdesk/plugin-sdk/vitest-setup`,你仓里的 `vitest.setup.ts` 是指向它的**一行指针**。⛔ **不要在自己仓里再抄一份**——抄来的那份会与共享版**无声漂移**。
|
|
263
|
+
- **纯逻辑最值得测**:`src/**/*.ts` 里既不碰 React、也不碰 `window.linkdesk` 的单元,应该配上测试。视图与交互**划得来时再测**——今天没有任何东西在量它。
|
|
264
|
+
- **插件专属桩住本仓**:你的代码调了共享 mock 没覆盖的东西(比如 `window.linkdesk.serial`)?在需要它的那个测试文件里用 `vi.fn()` 补上——别指望共享 mock 为你的插件长一条分支。
|
|
265
|
+
- **声明式插件**(纯 JSON/主题/语言包)**没有可测单元**——它的门禁是 `npm run verify`(结构与声明)。**「没有测试」在那里不是缺陷。**
|
|
266
|
+
- **老仓什么时候迁都行**:把整份 mock 换成一枚一行指针 + 一次 `npm install`,就是全部动作(好处:mock 升级从此跟着 SDK 走)。
|
|
267
|
+
|
|
268
|
+
**怎么知道做对了**
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
npm run test # vitest run——空测试集**故意**判过(passWithNoTests)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
257
276
|
## 新手最常踩的坑
|
|
258
277
|
|
|
259
278
|
| 症状 | 病根 | 去哪看 |
|
|
@@ -281,4 +300,5 @@ env:
|
|
|
281
300
|
| 整套**替代设置 UI** | [10-如何造一个设置插件](10-如何造一个设置插件.md) |
|
|
282
301
|
| 做**主题/图标** | [11-主题制作](11-主题制作.md) |
|
|
283
302
|
| 文件**该放哪**、README/CHANGELOG 权威判据 | [09-插件目录规范](09-插件目录规范.md) |
|
|
303
|
+
| 决定**要不要/怎么写测试** | [§ 插件仓里的测试怎么写](#插件仓里的测试怎么写) |
|
|
284
304
|
| 全部文档索引 | [00-README §文档索引](00-README.md#文档索引) |
|